Ejemplo n.º 1
0
 def _t():
     client = Client()
     for i in range(_ONE):
         try:
             client.execute(str(i))
         except:
             print 'error'
Ejemplo n.º 2
0
 def _t():
     client = Client()
     for i in range(_ONE):
         try:
             client.execute(str(i))
         except:
             print 'error'
Ejemplo n.º 3
0
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 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()
Ejemplo n.º 5
0
class TestClient():

    def __init__(self, config=None):
        self.client = Client(frontend=config.FRONTEND)

    def fetch(self, addr):
        return json.loads(self.client.execute(addr))
Ejemplo n.º 6
0
def phose():
    client = Client()
    p = run_cluster()
    time.sleep(5.)
    try:
        _phose(client)
    finally:
        p.terminate()
Ejemplo n.º 7
0
 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.
    """
Ejemplo n.º 9
0
import random
import sys
import time

from powerhose.client import Client
from powerhose.job import Job
from powerhose.util import set_logger


set_logger(True)
client = Client()

print 'Running 100 echo'

start = time.time()

for i in range(2000):
    data = str(random.randint(1, 1000))
    job = Job(data)
    res = client.execute(job)
    assert res == data
    sys.stdout.write('.')
    sys.stdout.flush()

print 'Done in %.2f' % (time.time() - start)
import pdb; pdb.set_trace()
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))
Ejemplo n.º 11
0
import random
import sys
import time

from powerhose.client import Client
from powerhose.job import Job
from powerhose.util import set_logger

set_logger(True)
client = Client()

print 'Running 100 echo'

start = time.time()

for i in range(2000):
    data = str(random.randint(1, 1000))
    job = Job(data)
    res = client.execute(job)
    assert res == data
    sys.stdout.write('.')
    sys.stdout.flush()

print 'Done in %.2f' % (time.time() - start)
import pdb
pdb.set_trace()
Ejemplo n.º 12
0
#!/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.
from powerhose import get_cluster
from powerhose.client import Client


cluster = get_cluster('echo_worker.echo', background=True)
cluster.start()

client = Client()

for i in range(10):
    print client.execute(str(i))

cluster.stop()