def __getreply(self, sn, reader): """ Get the reply matched by serial number. @param sn: The request serial number. @type sn: str @param reader: A reader. @type reader: L{Reader} @return: The matched reply envelope. @rtype: L{Envelope} """ timer = Timer() timeout = float(self.timeout[1]) while True: timer.start() envelope = reader.search(sn, int(timeout)) if envelope: reader.ack() timer.stop() elapsed = timer.duration() if elapsed > timeout: raise RequestTimeout(sn, 1) else: timeout -= elapsed if envelope: if envelope.status == 'progress': self.__onprogress(envelope) else: return self.__onreply(envelope) else: raise RequestTimeout(sn, 1)
def perftest(uuid): N = 200 agent = Agent(uuid) dog = agent.Dog() t = Timer() t.start() print "measuring performance ..." for i in range(0, N): dog.bark("performance!") t.stop() print "total=%s, percall=%f (ms)" % (t, (t.duration() / N) * 1000) # sys.exit(0) # ASYNCHRONOUS dog = agent.Dog(async=1) t = Timer() t.start() print "measuring (async) performance ..." for i in range(0, N): dog.bark("performance!") t.stop() print "total=%s, percall=%f (ms)" % (t, (t.duration() / N) * 1000) sys.exit(0)
def test_performance(): N = 200 agent = Agent() dog = agent.Dog() t = Timer() t.start() print 'measuring performance ...' for i in range(0, N): dog.bark('performance!') t.stop() print 'total=%s, percall=%f (ms)' % (t, (t.duration()/N)*1000) #sys.exit(0) # ASYNCHRONOUS agent = Agent(wait=0) dog = agent.Dog() t = Timer() t.start() print 'measuring (async) performance ...' for i in range(0, N): dog.bark('performance!') t.stop() print 'total=%s, percall=%f (ms)' % (t, (t.duration()/N)*1000) sys.exit(0)
def test_performance(): N = 200 agent = Agent() dog = agent.Dog() t = Timer() t.start() print('measuring performance ...') for i in range(0, N): dog.bark('performance!') t.stop() print('total={}, percall={} (ms)'.format(t, (t.duration() / N) * 1000)) # sys.exit(0) # ASYNCHRONOUS agent = Agent(wait=0) dog = agent.Dog() t = Timer() t.start() print('measuring (async) performance ...') for i in range(0, N): dog.bark('performance!') t.stop() print('total={}, percall={} (ms)'.format(t, (t.duration() / N) * 1000)) sys.exit(0)
def test_memory(): N = 10000 with open(__file__) as fp: content = fp.read() agent = Agent(data=content) dog = agent.Dog() t = Timer() t.start() print 'testing memory ...' for n in range(0, N): dog.bark('hello!') print 'tested %d' % n t.stop() print 'total=%s, percall=%f (ms)' % (t, (t.duration()/N)*1000) sys.exit(0)
def test_memory(): N = 10000 with open(__file__) as fp: content = fp.read() agent = Agent(data=content) dog = agent.Dog() t = Timer() t.start() print('testing memory ...') for n in range(0, N): dog.bark('hello!') print('tested {}'.format(n)) t.stop() print('total={}, percall={} (ms)'.format(t, (t.duration() / N) * 1000)) sys.exit(0)
def test_duplex(pool, fn): N = 100 print 'START' t = Timer() t.start() reader = ReplyReader(pool, N) reader.start() for i in range(0,N): request = 'REQUEST-%d' % i pool.run(fn, request) reader.join() t.stop() for r in reader.reply: print r print 'total: %s, per-call: %f' % (t, t.duration()/N) print repr(pool)
def get_reply(self, sn, reader): """ Get the reply matched by serial number. :param sn: The request serial number. :type sn: str :param reader: A reader. :type reader: gofer.messaging.consumer.Reader :return: The matched reply document. :rtype: Document """ timer = Timer() timeout = float(self.wait) while not Thread.aborted(): timer.start() document = reader.search(sn, int(timeout)) timer.stop() elapsed = timer.duration() if elapsed > timeout: raise RequestTimeout(sn, self.wait) else: timeout -= elapsed if not document: raise RequestTimeout(sn, self.wait) # rejected if document.status == 'rejected': raise DocumentError( document.code, document.description, document.document, document.details) # accepted | started if document.status in ('accepted', 'started'): continue # progress reported if document.status == 'progress': self.on_progress(document) continue # reply return self.on_reply(document)
def get_reply(self, sn, reader): """ Get the reply matched by serial number. :param sn: The request serial number. :type sn: str :param reader: A reader. :type reader: gofer.messaging.consumer.Reader :return: The matched reply document. :rtype: Document """ timer = Timer() timeout = float(self.wait) while not Thread.aborted(): timer.start() document = reader.search(sn, int(timeout)) timer.stop() elapsed = timer.duration() if elapsed > timeout: raise RequestTimeout(sn, self.wait) else: timeout -= elapsed if not document: raise RequestTimeout(sn, self.wait) # rejected if document.status == 'rejected': raise DocumentError(document.code, document.description, document.document, document.details) # accepted | started if document.status in ('accepted', 'started'): continue # progress reported if document.status == 'progress': self.on_progress(document) continue # reply return self.on_reply(document)
def duration(self): t = Timer() t.started = 10.0 t.stopped = 100.0 self.assertEqual(t.duration(), 90.0)
def test_duration(self): t = Timer() t.started = 10.0 t.stopped = 100.0 self.assertEqual(t.duration(), 90.0)