처리 서버를 테스트하는 python 스크립트가 있습니다. 업로드 된 파일은 처리가 완료되었음을 알리기 위해 업로드가 완료되면 이름이 바뀝니다. 무거운 하중을 테스트하기 위해 스크립트를 다중 스레드로 만들었지 만 서버에서 업로드 디렉토리를 볼 때 한 번에 하나의 파일 만 제공됩니다. 그래서 기본적으로 나는 무작위로 선택된 입력 파일 잘 형식화 된 출력 이름 다음 그러나 많은 스레드가 테스트 설정 파일에 지정된 시작 사이의 매핑과 대기열을 채우기업로드 후 ssh를 통해 여러 파일의 이름 변경
def worker(queue):
while queue.qsize():
try:
infile, filename = queue.get()
except Queue.Empty:
return
size = os.path.getsize(infile)
copyStart = time.time()
print '{}: {} started'.format(time.asctime(), filename)
os.system('ssh servername "cat > {0} && mv {0} {1}" < {2}'.format(filename, filename.replace('upl', 'jpg'), infile))
print '{}: {} took {} secs for {} bytes'.format(time.asctime(), filename, time.time() - copyStart, size)
q = Queue.Queue()
for media_type, num in config.get("media").items():
media_dir = media_dir_format.format(media_type)
print '\nLoading media from ' + media_dir
itemId = startId
for i in range(num):
infile = media_dir + random.choice([x for x in os.listdir(media_dir) if x[-3:].lower() == 'jpg'])
filename = output_format.format(itemId, media_type[:-1])
q.put((infile, filename))
itemId += 1
threads = []
for i in range(config.get("threads")):
t = threading.Thread(target=worker, args=(q,))
t.start()
threads.append(t)
다음은 관련 코드입니다. 문제는 os.system
호출은 스크립트 출력에서 볼 수있는 바와 같이 업로드 만, 잇달아 발생, 비슷한 시간에 실행되는 경우에도 :
Fri Jul 11 17:06:44 2014: /bla/foo/b1.upl started
Fri Jul 11 17:06:44 2014: /blah/foo/b2.upl started
Fri Jul 11 17:06:44 2014: /blah/foo/b3.upl started
Fri Jul 11 17:07:03 2014: /blah/foo/b1.upl took 19.0852029324 secs for 8947009 bytes
Fri Jul 11 17:07:03 2014: /blah/foo/b4.upl started
Fri Jul 11 17:07:21 2014: /blah/foo/b3.upl took 36.8071010113 secs for 8348547 bytes
Fri Jul 11 17:07:21 2014: /blah/foo/b5.upl started
Fri Jul 11 17:07:40 2014: /blah/foo/b2.upl took 55.855271101 secs for 8348547 bytes
그것의 조금이다 그러나 당신은 그 연속을 볼 수 있습니다 업로드 시간이 오래 걸립니다. 문제가없는 즉시 여러 쉘에 ssh를 넣을 수 있고 약간의 검색을 통해 여러 스레드에서 os.system
을 사용하는 사람들의 사례를 많이 보았 기 때문에 이것이 병목 현상이있는 곳인 ssh
문제라고 믿기 어렵습니다.
당신은 느린 업 링크 속도를 설명 할 수있다. 3 개의 파일이 모두 병렬로 시작됩니다. 이유가 무엇이든 빨리 완료되지만 즉시 다른 업로드를 시작하여 대역폭을 소비합니다. 단 3 파일로 다시 시도하고 다른 숫자가 개선되는지 확인하십시오. – tdelaney
나는 업로드되는 파일이 3 개인 경우 비슷한 경험을했습니다. – Michoel