smbinterp/bin/master.py

66 lines
1.6 KiB
Python
Raw Normal View History

2011-03-02 23:01:46 -08:00
#!/usr/bin/env python
2011-03-02 23:38:47 -08:00
import sys
import os
2011-03-02 23:38:47 -08:00
import time
2011-03-02 23:01:46 -08:00
from multiprocessing.managers import BaseManager
import numpy as np
import interp.bootstrap
import logging
log = logging.getLogger("interp")
2011-03-02 23:01:46 -08:00
class QueueManager(BaseManager): pass
QueueManager.register('get_inqueue' )
QueueManager.register('get_outqueue')
def run_queries(count, order = 3, extra_points = 8):
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()
for i in xrange(count):
r.append(outq.get())
receive_end = time.time()
2011-03-02 23:01:46 -08:00
return (r, submit_end - submit_start, receive_end - receive_start)
2011-03-02 23:01:46 -08:00
if __name__ == '__main__':
server = 'localhost'
m = QueueManager(address=(server, 50000), authkey='asdf')
m.connect()
expected_participants, count = (int(i) for i in sys.argv[1:])
2011-03-02 23:38:47 -08:00
inq = m.get_inqueue()
outq = m.get_outqueue()
2011-03-02 23:01:46 -08:00
# wait for all participants to be loaded up
for i in xrange(expected_participants):
print outq.get()
# run codes
results, submit, receive = run_queries(count, order=3, extra_points = 64)
# shut down all participants
for i in xrange(expected_participants):
inq.put([None] * 4)
stats = {}
stats['submit' ] = float(submit)
stats['receive' ] = float(receive)
stats['count' ] = count
stats['expected_participants'] = expected_participants
print "submit time for %(count)s interps, %(expected_participants)d participants: %(submit)0.2f seconds, results time: %(receive)0.2f" % stats
log.error("stats: %s", stats)