我有一个程序需要通过网络进行大量查询,所以我正在做的是并行化工作。它实际上是 I/O 受限的,我只是在做:
for i in range(options.workers):
w = Worker(queue, output_queue, options.site)
w.setDaemon(True)
w.start()
for i, dataset_metadata in enumerate(datasets_metadata):
queue.put((i+1, dataset_metadata))
queue.join()
the options.workers
comes from the command line. Now I want to dynamically change the number of works.
First question: how to add workers after queue.join
?
Second question: how to evaluate the optimal number of workers at run time? I think I've to monitor the speed tasks/time, increase the number of workers until this ratio doesn't change.