我运行了几个python子进程来将数据迁移到S3。我注意到我的python子进程经常降到0%并且这个条件持续超过一分钟。这大大降低了迁移过程的性能。
子流程执行以下操作:
每个表的Spawn子进程。
for table in tables:
print "Spawn process to process {0} table".format(table)
process = multiprocessing.Process(name="Process " + table,
target=target_def,
args=(args, table))
process.daemon = True
process.start()
processes.append(process)
for process in processes:
process.join()
使用Limit和Offset从数据库查询数据。我使用PyMySQL库来查询数据。
将返回的数据转换为另一个结构。 construct_structure_def()
是一个将行转换为另一种格式的函数。
buffer_string = []
for i, row_file in enumerate(row_files):
if i == num_of_rows:
buffer_string.append( json.dumps(construct_structure_def(row_file)) )
else:
buffer_string.append( json.dumps(construct_structure_def(row_file)) + "\n" )
content = ''.join(buffer_string)
将转换后的数据写入文件并使用gzip进行压缩。
with gzip.open(file_path, 'wb') as outfile:
outfile.write(content)
return file_name
将文件上传到S3。
为了加快速度,我使用multiprocesses.Process
内置库为每个表创建子进程。
我在虚拟机中运行了我的脚本。以下是规格:
我在here的帖子中看到,其中一个主要可能性是由于内存I / O限制。所以我尝试运行一个子流程来测试该理论,但没有用。
知道为什么会这样吗?如果你们需要更多信息,请告诉我。
提前谢谢!
答案 0 :(得分:0)
你的虚拟机是一台Windows机器,我更像是一个Linux用户,所以如果有人支持我,我会喜欢它。
我认为daemon
是问题所在。
我已经阅读了daemon preocesses,特别是关于TSR。
TSR的第一行说:
关于计算机,终止和驻留程序(通常由初始主义TSR引用)是一种计算机程序,它使用DOS操作系统中的系统调用将计算机的控制权返回给操作系统,就好像该程序具有退出,但保持驻留在计算机内存中,以便可以通过硬件或软件中断重新激活它。
根据我的理解,让进程成为daemon
(或你的情况下为TSR
)使其处于休眠状态,直到系统调用将其唤醒,我不认为这是这里的情况(如果我错了,请纠正我。)