일부 큰 데이터에 대한 데이터 처리 작업이 있습니다. 나는 다음과 같은 형태 파이썬을 사용하여 EC2에서 스크립트 실행 라인으로 데이터 라인을 통해파일을 한 줄 씩 쓸 때 RAM이 부족합니다. [Python]
with open(LARGE_FILE, 'r') as f:
with open(OUTPUT_FILE, 'w') as out:
for line in f:
results = some_computation(line)
out.write(json.dumps(results))
out.write('\n')
I 루프 라인으로 다른 파일 라인에 결과를 작성합니다.
몇 시간 동안 실행 한 후 서버에 로그인 할 수 없습니다. 계속하려면 인스턴스를 다시 시작해야합니다.
$ ssh [email protected]$IP_ADDRESS
ssh_exchange_identification: read: Connection reset by peer
서버의 RAM이 부족한 것 같습니다. 파일에 쓸 때 RAM이 천천히 움직입니다. 나는 한 줄씩 읽고 쓸 때 왜 메모리가 문제가되는지 확신 할 수 없다.
충분한 하드 드라이브 공간이 있습니다.
나는이 문제에 가장 가까운 생각 : Does the Python "open" function save its content in memory or in a temp file?
'some_computation()'함수는 어떻게됩니까? – MaxU
내기가 json.dumps에 있습니다. 가능한 복제본 : [http://stackoverflow.com/questions/24239613/memoryerror-using-json-dumps] (파이썬 json.dumps 메모리 부족으로 피하는 방법을 찾고) – Markus
그래서'json.dump some_computation (line), out)'대신'results = some_computation (line); out.write (json.dumps (results))' – MaxU