def _t(): client = Client() for i in range(_ONE): try: client.execute(str(i)) except: print 'error'
def phose(): client = Client() p = run_cluster() time.sleep(5.) try: _phose(client) finally: p.terminate()
def verify_broker(broker_endpoint=DEFAULT_FRONTEND, timeout=1.): """ Return True if there's a working broker bound at broker_endpoint """ from powerhose.client import Client client = Client(broker_endpoint) try: return client.ping(timeout) finally: client.close()
def __init__(self, config=None): self.client = Client(frontend=config.FRONTEND)
#!/usr/bin/env python """ Minimal test client for live testing. """ import json import time from powerhose.client import Client from powerhose.exc import TimeoutError from random import randrange client = Client(frontend='ipc:///tmp/geo_front', timeout=100, timeout_max_overflow=1, timeout_overflows=1) n = 1000 start = time.time() try: for num in xrange(n): ip = '%s.%s.%s.%s' % (randrange(0, 255), randrange( 0, 255), randrange(0, 255), randrange(0, 255)) raw = client.execute('GET %s' % ip) reply = json.loads(raw) if 'success' in reply and reply['success']['addr'] != ip: print "FAIL!\n%s\n%s" % (ip, json.dumps(reply)) secs = time.time() - start print "Time: %s\n RpS: %s\n" % (secs, n / secs) except ValueError as e: print "FAIL\n%s\n%s" % (str(e), raw) except TimeoutError as e: print """ A timeout occured trying to process the request. Please make sure that the broker and workers are running. """
from wsgiref.simple_server import make_server import json import time from powerhose.client import Client from powerhose.job import Job from powerhose.util import set_logger set_logger(True) client = Client() def application(environ, start_response): status = '200 OK' headers = [('Content-type', 'text/html')] start_response(status, headers) data = {} for key, value in environ.items(): if key.startswith('wsgi.') or key.startswith('gunicorn.'): continue data[key] = value job = Job(json.dumps(data)) start = time.time() try: return client.execute(job) finally: print('Time : %.4f\n' % (time.time() - start))