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