added two more queues
This commit is contained in:
+37
-56
@@ -10,8 +10,6 @@ from progressbar import *
|
||||
from collections import defaultdict
|
||||
from optparse import OptionParser
|
||||
|
||||
from multiprocessing.managers import BaseManager
|
||||
|
||||
import numpy as np
|
||||
|
||||
import interp.bootstrap
|
||||
@@ -19,50 +17,11 @@ import interp.bootstrap
|
||||
import logging
|
||||
log = logging.getLogger("interp")
|
||||
|
||||
class QueueManager(BaseManager): pass
|
||||
QueueManager.register('get_inqueue' )
|
||||
QueueManager.register('get_outqueue')
|
||||
|
||||
def run_queries(count, order = 3, extra_points = 8, verbose = False):
|
||||
r = []
|
||||
submit_start = time.time()
|
||||
for i in xrange(count):
|
||||
X = np.random.random((1,3))[0]
|
||||
inq.put((i,order,extra_points,X))
|
||||
submit_end = time.time()
|
||||
|
||||
receive_start = time.time()
|
||||
|
||||
widgets = ['Progress: ', Percentage(), ' ', Bar(), ' ', ETA()]
|
||||
pbar = ProgressBar(widgets = widgets, maxval = count)
|
||||
if verbose:
|
||||
pbar.start()
|
||||
for i in xrange(count):
|
||||
r.append(outq.get())
|
||||
if verbose:
|
||||
pbar.update(i+1)
|
||||
receive_end = time.time()
|
||||
if verbose:
|
||||
pbar.finish()
|
||||
|
||||
return (r, submit_end - submit_start, receive_end - receive_start)
|
||||
|
||||
def clean_up(inq, expected_participants, shutdown = False):
|
||||
"""
|
||||
I replace the normal first argument to the inq with None, and then do some
|
||||
code branching based on the second paramter, which is shutdown
|
||||
"""
|
||||
for i in xrange(expected_participants):
|
||||
inq.put([None, shutdown, None, None])
|
||||
|
||||
from interp.cluster import QueueManager, get_qs
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = OptionParser(usage = "usage: %s [options] <server> <expected participants> <interp count>")
|
||||
|
||||
parser.add_option("-v", "--verbose",
|
||||
action="store_true", dest="verbose", default=False,
|
||||
help="verbose flag (display progress bar: %default)")
|
||||
|
||||
parser.add_option("-l", "--last-time",
|
||||
action="store_true", dest="last", default=False,
|
||||
help="when finished, send shutdown signal to <expected participants> nodes (default: %default)")
|
||||
@@ -94,20 +53,46 @@ if __name__ == '__main__':
|
||||
m = QueueManager(address=(server, options.port), authkey='asdf')
|
||||
m.connect()
|
||||
|
||||
inq = m.get_inqueue()
|
||||
outq = m.get_outqueue()
|
||||
tasksq, resultsq, masterq, slavesq = get_qs(m)
|
||||
|
||||
# wait for all participants to be loaded up
|
||||
print "wait on all participants"
|
||||
for i in xrange(expected_participants):
|
||||
worker = outq.get()
|
||||
if options.verbose:
|
||||
print "%d of %d : %s" % (i, expected_participants, worker)
|
||||
worker = masterq.get()
|
||||
print "%d of %d : %s is ready" % (i, expected_participants - 1, worker)
|
||||
|
||||
# run codes
|
||||
results, submit, receive = run_queries(count, order = options.order, extra_points = options.extra, verbose = options.verbose)
|
||||
print "everyone ready!"
|
||||
|
||||
results = []
|
||||
|
||||
submit_start = time.time()
|
||||
for i in xrange(count):
|
||||
X = np.random.random((1,3))[0]
|
||||
tasksq.put((i, options.order, options.extra, X))
|
||||
submit_end = time.time()
|
||||
|
||||
for i in xrange(expected_participants):
|
||||
print "sending %d th start message" % i
|
||||
slavesq.put("start")
|
||||
|
||||
receive_start = time.time()
|
||||
widgets = ['Progress: ', Percentage(), ' ', Bar(), ' ', ETA()]
|
||||
pbar = ProgressBar(widgets = widgets, maxval = count)
|
||||
pbar.start()
|
||||
for i in xrange(count):
|
||||
results.append(resultsq.get())
|
||||
pbar.update(i+1)
|
||||
receive_end = time.time()
|
||||
pbar.finish()
|
||||
|
||||
submit = submit_end - submit_start
|
||||
receive = receive_end - receive_start
|
||||
|
||||
# shut down all participants
|
||||
clean_up(inq, expected_participants)
|
||||
for i in xrange(expected_participants):
|
||||
if options.last:
|
||||
slavesq.put("teardown")
|
||||
else:
|
||||
slavesq.put("prepare for more")
|
||||
|
||||
# post processing
|
||||
stats = {}
|
||||
@@ -116,8 +101,7 @@ if __name__ == '__main__':
|
||||
stats['count' ] = count
|
||||
stats['expected_participants'] = expected_participants
|
||||
|
||||
if options.verbose:
|
||||
print "%s" % stats
|
||||
print "%s" % stats
|
||||
log.error("stats: %s", stats)
|
||||
|
||||
tasks_accomplished_by = defaultdict(int)
|
||||
@@ -134,6 +118,3 @@ if __name__ == '__main__':
|
||||
'results' : npresults,
|
||||
}
|
||||
s.close()
|
||||
|
||||
if options.last:
|
||||
clean_up(inq, expected_participants, shutdown = True)
|
||||
|
||||
Reference in New Issue
Block a user