Exemple #1
0
def parent_run():

    # Make sure we can connect
    conn = psycopg2.connect(conn_string)
    curs = conn.cursor()
    curs.execute(dummy_statement)
    curs.fetchall()
    curs.close()
    conn.close()

    # Spawn workers
    children = []
    result_queue = Queue()
    start_lock = Event()
    for i in xrange(0, n_workers):
        done_event = Event()
        child = Process(target=child_run,
                        args=(i, result_queue, start_lock, done_event))
        children.append(child)
        child.done_event = done_event

    for child in children:
        child.start()

    # and start them working
    start_lock.set()

    # wait a while for children to thrash the system
    # then ask them to finish
    time.sleep(10)
    start_lock.clear()

    # Wait until all children have reported in
    sys.stderr.write("Waiting for children to complete...")
    sys.stderr.flush()
    for child in children:
        child.done_event.wait()
    sys.stderr.write(" done\n")

    # Read the results
    results = []
    for i in range(0, len(children)):
        (worker_number, num_tx) = result_queue.get(False)
        results.append(num_tx)
    total_tx = sum(results)
    mean_tx = float(total_tx) / float(len(results))

    # and wait for children to exit
    for child in children:
        child.join()

    sys.stderr.write(
        "Done, executed %i statements with %i conns and %i workers\n" %
        (total_tx, n_conns, n_workers))
    sys.stderr.write("Mean tx per worker was %.2f\n" % mean_tx)
Exemple #2
0
def parent_run():

    # Make sure we can connect
    conn = psycopg2.connect(conn_string)
    curs = conn.cursor()
    curs.execute(dummy_statement)
    curs.fetchall()
    curs.close()
    conn.close()

    # Spawn workers
    children = []
    result_queue = Queue()
    start_lock = Event()
    for i in xrange(0, n_workers):
        done_event = Event()
        child = Process(target=child_run, args=(i,result_queue,start_lock,done_event))
        children.append(child)
        child.done_event = done_event

    for child in children:
        child.start()

    # and start them working
    start_lock.set()

    # wait a while for children to thrash the system
    # then ask them to finish
    time.sleep(10)
    start_lock.clear()

    # Wait until all children have reported in
    sys.stderr.write("Waiting for children to complete...")
    sys.stderr.flush()
    for child in children:
        child.done_event.wait()
    sys.stderr.write(" done\n")

    # Read the results
    results = []
    for i in range(0, len(children)):
        (worker_number, num_tx) = result_queue.get(False)
        results.append(num_tx)
    total_tx = sum(results)
    mean_tx = float(total_tx) / float(len(results))

    # and wait for children to exit
    for child in children:
        child.join()


    sys.stderr.write("Done, executed %i statements with %i conns and %i workers\n" % (total_tx, n_conns, n_workers))
    sys.stderr.write("Mean tx per worker was %.2f\n" % mean_tx)