예제 #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
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
    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
 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
    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
 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
 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
 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()