def main(): options = get_options() # Seed RNG with a fixed value to give deterministic runs random.seed(0) graph = generate_graph(options.users) graph_keys = graph.nodes() random.shuffle(graph_keys) conn = { 'host': options.host, 'port': options.port, 'bucket': options.bucket, } if options.engine == 'twisted': for start in range(options.workers): AsyncGen(iterator=PersonIterator(graph, graph_keys, start, options.workers), conn=conn) # Then drive the event loop reactor.run() elif options.engine == 'threaded': threads = list() for start in range(options.workers): iterator = PersonIterator(graph, graph_keys, start, options.workers) t = Thread( target=produce_AB, args=(iterator, options.iterations, conn), ) threads.append(t) t.start() for t in threads: t.join() elif options.engine == 'multiprocessing': results = list() pool = Pool(processes=options.workers) for start in range(options.workers): r = pool.apply_async( func=produce_AB, args=( PersonIterator(graph, graph_keys, start, options.workers), options.iterations, conn, ) ) results.append(r) for r in results: r.get()
def generate_graph(self): random.seed(0) self.graph = generate_graph(self.test_config.load_settings.items) self.graph_keys = self.graph.nodes() random.shuffle(self.graph_keys)