コード例 #1
0
ファイル: manage.py プロジェクト: xmnlab/minilab
 def request_stream(self, request):
     m = request.urlargs['m']
     n = request.urlargs['n']
     if m*n > 8388608:
         # limit at 8 megabytes of total data
         raise HttpException(status=403)
     stream = ('Chunk %s\n%s\n\n' % (i+1, ''.join((
         choice(characters) for _ in range(m)))) for i in range(n))
     request.response.content = stream
     return request.response
コード例 #2
0
ファイル: manage.py プロジェクト: robgil/pulsar
def randompaths(request, num_paths=1, size=250, mu=0, sigma=1):
    '''Lists of random walks.'''
    r = []
    for p in range(num_paths):
        v = 0
        path = [v]
        r.append(path)
        for t in range(size):
            v += normalvariate(mu, sigma)
            path.append(v)
    return r
コード例 #3
0
ファイル: manage.py プロジェクト: JinsongBian/pulsar
def randompaths(request, num_paths=1, size=250, mu=0, sigma=1):
    '''Lists of random walks.'''
    r = []
    for p in range(num_paths):
        v = 0
        path = [v]
        r.append(path)
        for t in range(size):
            v += normalvariate(mu, sigma)
            path.append(v)
    return r
コード例 #4
0
 def request_stream(self, request):
     m = request.urlargs['m']
     n = request.urlargs['n']
     if m * n > 8388608:
         # limit at 8 megabytes of total data
         raise HttpException(status=403)
     stream = ('Chunk %s\n%s\n\n' % (i + 1, ''.join((choice(characters)
                                                     for _ in range(m))))
               for i in range(n))
     request.response.content = stream
     return request.response
コード例 #5
0
 def testTimeIt(self):
     msg = b''.join((b'a' for x in range(2**10)))
     response = self.pool.timeit(10, self.server.address, msg)
     yield response
     self.assertTrue(response.locked_time >= 0)
     self.assertTrue(response.total_time >= response.locked_time)
     self.assertEqual(response.num_failures, 0)
コード例 #6
0
ファイル: monitor.py プロジェクト: Ghost-script/dyno-chat
    def spawn_actors(self):
        '''Spawn new actors if needed. If the :class:`PoolMixin` is spawning
do nothing.'''
        to_spawn = self.cfg.workers - len(self.managed_actors)
        if self.cfg.workers and to_spawn > 0:
            for _ in range(to_spawn):
                self.spawn()
コード例 #7
0
ファイル: tests.py プロジェクト: xmnlab/minilab
 def testTimeIt(self):
     msg = b''.join((b'a' for x in range(2**10)))
     response = self.pool.timeit(10, self.server.address, msg)
     yield response
     self.assertTrue(response.locked_time >= 0)
     self.assertTrue(response.total_time >= response.locked_time)
     self.assertEqual(response.num_failures, 0)
コード例 #8
0
ファイル: monitor.py プロジェクト: japaks/pulsar
    def spawn_actors(self):
        '''Spawn new actors if needed. If the :class:`PoolMixin` is spawning
do nothing.'''
        to_spawn = self.cfg.workers - len(self.managed_actors)
        if self.cfg.workers and to_spawn > 0:
            for _ in range(to_spawn):
                self.spawn()
コード例 #9
0
 def spawn_actors(self, monitor):
     '''Spawn new actors if needed.
     '''
     to_spawn = monitor.cfg.workers - len(self.managed_actors)
     if monitor.cfg.workers and to_spawn > 0:
         for _ in range(to_spawn):
             monitor.spawn()
コード例 #10
0
    def timeit(self, func, times, *args, **kwargs):
        '''Usefull little utility for timing responses from server. The
usage is simple::

    >>> from pulsar.apps import rpc
    >>> p = rpc.JsonProxy('http://127.0.0.1:8060')
    >>> p.timeit('ping',10)
    0.56...
    '''
        func = getattr(self, func)
        return multi_async((func(*args, **kwargs) for t in range(times)))
コード例 #11
0
 def stop_actors(self, monitor):
     """Maintain the number of workers by spawning or killing as required
     """
     if monitor.cfg.workers:
         num_to_kill = len(self.managed_actors) - monitor.cfg.workers
         for i in range(num_to_kill, 0, -1):
             w, kage = 0, sys.maxsize
             for worker in itervalues(self.managed_actors):
                 age = worker.impl.age
                 if age < kage:
                     w, kage = w, age
             self.manage_actor(monitor, w, True)
コード例 #12
0
ファイル: monitor.py プロジェクト: Ghost-script/dyno-chat
 def stop_actors(self):
     """Maintain the number of workers by spawning or killing as required
     """
     if self.cfg.workers:
         num_to_kill = len(self.managed_actors) - self.cfg.workers
         for i in range(num_to_kill, 0, -1):
             w, kage = 0, sys.maxsize
             for worker in itervalues(self.managed_actors):
                 age = worker.impl.age
                 if age < kage:
                     w, kage = w, age
             self.manage_actor(w, True)
コード例 #13
0
 def testStreamed(self):
     stream = ('line {0}\n'.format(l + 1) for l in range(10))
     r = wsgi.WsgiResponse(content=stream)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.status, '200 OK')
     self.assertEqual(r.content, stream)
     self.assertTrue(r.is_streamed)
     data = []
     for l, a in enumerate(r):
         data.append(a)
         self.assertTrue(r.started)
         self.assertEqual(a, ('line {0}\n'.format(l + 1)).encode('utf-8'))
     self.assertEqual(len(data), 10)
コード例 #14
0
ファイル: wsgi.py プロジェクト: BazookaShao/pulsar
 def testStreamed(self):
     stream = ('line {0}\n'.format(l+1) for l in range(10))
     r = wsgi.WsgiResponse(content=stream)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.status, '200 OK')
     self.assertEqual(r.content, stream)
     self.assertTrue(r.is_streamed)
     data = []
     for l, a in enumerate(r):
         data.append(a)
         self.assertTrue(r.started)
         self.assertEqual(a, ('line {0}\n'.format(l+1)).encode('utf-8'))
     self.assertEqual(len(data), 10)
コード例 #15
0
 def _run_once(self, timeout=None):
     timeout = timeout or self.poll_timeout
     self._num_loops += 1
     #
     # Compute the desired timeout
     if self._callbacks:
         timeout = 0
     elif self._scheduled:
         timeout = min(max(0, self._scheduled[0].deadline - self.timer()),
                       timeout)
     # poll events
     self._poll(timeout)
     #
     # append scheduled callback
     now = self.timer()
     while self._scheduled and self._scheduled[0].deadline <= now:
         self._callbacks.append(heappop(self._scheduled))
     #
     # Run callbacks
     callbacks = self._callbacks
     todo = len(callbacks)
     for i in range(todo):
         exc_info = None
         callback = callbacks.popleft()
         try:
             value = callback()
         except socket.error as e:
             if raise_socket_error(e) and self.running:
                 exc_info = sys.exc_info()
             if self._raise_loop_error(e):
                 exc_info = sys.exc_info()
         except Exception:
             exc_info = sys.exc_info()
         else:
             if isgenerator(value):
                 self.task_factory(value, event_loop=self)
         if exc_info:
             Failure(exc_info).log(
                 msg='Unhadled exception in event loop callback.')
コード例 #16
0
ファイル: bench.py プロジェクト: BazookaShao/pulsar
 def _call(self):
     simple = lambda info, *args: info
     testMethod = self.testMethod
     testStartUp = getattr(self.test, 'startUp', lambda: None)
     testGetTime = getattr(self.test, 'getTime', lambda dt: dt)
     testGetInfo = getattr(self.test, 'getInfo', simple)
     testGetSummary = getattr(self.test, 'getSummary', simple)
     t = 0
     t2 = 0
     info = {}
     for r in range(self.number):
         testStartUp()
         start = default_timer()
         yield testMethod()
         delta = default_timer() - start
         dt = testGetTime(delta)
         testGetInfo(info, delta, dt)
         t += dt
         t2 += dt*dt
     self.updateSummary(info, self.number, t, t2)
     self.set_test_attribute('bench_info',
                             testGetSummary(info, self.number, t, t2))
コード例 #17
0
ファイル: bench.py プロジェクト: robgil/pulsar
 def _call(self):
     simple = lambda info, *args: info
     testMethod = self.testMethod
     testStartUp = getattr(self.test, 'startUp', lambda: None)
     testGetTime = getattr(self.test, 'getTime', lambda dt: dt)
     testGetInfo = getattr(self.test, 'getInfo', simple)
     testGetSummary = getattr(self.test, 'getSummary', simple)
     t = 0
     t2 = 0
     info = {'name': '%s.%s' % (self.test.__class__.__name__,
                                testMethod.__name__)}
     for r in range(self.number):
         testStartUp()
         start = default_timer()
         testMethod()
         delta = default_timer() - start
         dt = testGetTime(delta)
         testGetInfo(info, delta, dt)
         t += dt
         t2 += dt*dt
     self.updateSummary(info, self.number, t, t2)
     self.set_test_attribute('bench_info',
                             testGetSummary(info, self.number, t, t2))
コード例 #18
0
    def timeit(self, times, *args, **kwargs):
        '''Send ``times`` requests asynchronously and evaluate the time
        taken to obtain all responses. In the standard implementation
        this method will open ``times`` :class:`Connection` with the
        remote server.
        Usage::

            client = Client(...)
            multi = client.timeit(100, ...)
            response = yield multi
            multi.total_time

        :return: a :class:`MultiDeferred` which results in the list of results
          for the individual requests. Its :attr:`MultiDeferred.total_time`
          attribute indicates the number of seconds taken (once the deferred
          has been called back).
        '''
        results = []
        for _ in range(times):
            r = self.request(*args, **kwargs)
            if hasattr(r, 'on_finished'):
                r = r.on_finished
            results.append(r)
        return multi_async(results)
コード例 #19
0
ファイル: clients.py プロジェクト: elimisteve/pulsar
    def timeit(self, times, *args, **kwargs):
        '''Send ``times`` requests asynchronously and evaluate the time
        taken to obtain all responses. In the standard implementation
        this method will open ``times`` :class:`Connection` with the
        remote server.
        Usage::

            client = Client(...)
            multi = client.timeit(100, ...)
            response = yield multi
            multi.total_time

        :return: a :class:`MultiDeferred` which results in the list of results
          for the individual requests. Its :attr:`MultiDeferred.total_time`
          attribute indicates the number of seconds taken (once the deferred
          has been called back).
        '''
        results = []
        for _ in range(times):
            r = self.request(*args, **kwargs)
            if hasattr(r, 'on_finished'):
                r = r.on_finished
            results.append(r)
        return multi_async(results)
コード例 #20
0
ファイル: manage.py プロジェクト: JinsongBian/pulsar
 def getsize(self, request):
     size = request.urlargs["size"]
     data = {"size": size, "data": "".join(("d" for n in range(size)))}
     return self.info_data_response(request, **data)
コード例 #21
0
 def on_message(self, websocket, msg):
     websocket.write(json.dumps([(i, random()) for i in range(100)]))
コード例 #22
0
 def getsize(self, request):
     size = request.urlargs['size']
     data = {'size': size, 'data': ''.join(('d' for n in range(size)))}
     return self.info_data_response(request, **data)
コード例 #23
0
ファイル: tests.py プロジェクト: JinsongBian/pulsar
 def test_large(self):
     '''Echo a 3MB message'''
     msg = b''.join((b'a' for x in range(2**13)))
     result = yield self.client(msg)
     self.assertEqual(result, msg)
コード例 #24
0
 def test_getbench(self):
     c = self.client
     yield MultiDeferred((c.get(self.uri) for _ in range(1))).lock()
コード例 #25
0
ファイル: futures.py プロジェクト: axisofentropy/pulsar
 def __call__(self, func, *args, **kwargs):
     self.start = self._loop.time()
     data = (func(*args, **kwargs) for t in range(self.times))
     self.result = multi_async(data, loop=self._loop)
     return chain_future(self.result, callback=self._done)
コード例 #26
0
ファイル: futures.py プロジェクト: robgil/pulsar
 def __call__(self, func, *args, **kwargs):
     self.start = self._loop.time()
     data = (func(*args, **kwargs) for t in range(self.times))
     self.result = multi_async(data, loop=self._loop)
     return chain_future(self.result, callback=self._done)
コード例 #27
0
ファイル: manage.py プロジェクト: xmnlab/minilab
 def getsize(self, request):
     size = request.urlargs['size']
     data = {'size': size,
             'data': ''.join(('d' for n in range(size)))}
     return self.info_data_response(request, **data)
コード例 #28
0
ファイル: tests.py プロジェクト: rennat/pulsar
 def test_large(self):
     """Echo a 3MB message"""
     msg = b"".join((b"a" for x in range(2 ** 13)))
     result = yield self.client(msg)
     self.assertEqual(result, msg)
コード例 #29
0
def random_string(characters=None, len=20):
    characters or default_characters
    return ''.join((choice(characters) for s in range(len)))
コード例 #30
0
ファイル: manage.py プロジェクト: BazookaShao/pulsar
 def on_message(self, websocket, msg):
     websocket.write(json.dumps([(i, random()) for i in range(100)]))
コード例 #31
0
 def test_large(self):
     '''Echo a 3MB message'''
     msg = b''.join((b'a' for x in range(2**13)))
     result = yield self.client(msg)
     self.assertEqual(result, msg)
コード例 #32
0
ファイル: tests.py プロジェクト: BazookaShao/pulsar
 def test_getbench(self):
     c = self.client
     yield MultiDeferred((c.get(self.uri) for _ in range(1))).lock()