本文整理汇总了Python中eventlet.GreenPile.next方法的典型用法代码示例。如果您正苦于以下问题:Python GreenPile.next方法的具体用法?Python GreenPile.next怎么用?Python GreenPile.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eventlet.GreenPile
的用法示例。
在下文中一共展示了GreenPile.next方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Benchmarker
# 需要导入模块: from eventlet import GreenPile [as 别名]
# 或者: from eventlet.GreenPile import next [as 别名]
class Benchmarker():
def __init__(self, rate, auth, total_ops=None, data_size=1024*1024, container='nacho', base='item-', queue_size=None):
self.rate = rate
self.dist = NegExp(self.rate)
self.data_size = data_size
self.ops = 0
self.errors = 0
self.container = container
self.base = base
self.outstanding = 0
self.total_ops = total_ops
self.running = False
if queue_size:
self.pile = GreenPile(queue_size)
else:
self.pile = GreenPile()
self._done = Event()
# self.client = Connection(authurl='http://localhost:8080/auth/v1.0', user='test:tester', key='testing')
self.storage_url, self.token = get_auth(auth, 'test:tester', 'testing')
self.data = "x" * data_size
LOG.info("Object-size=%s" % (len(self.data)))
LOG.info("Object-base=%s" % base)
if total_ops:
LOG.info("This benchmark will take aprox %.0f seconds" % (total_ops / rate))
def __iter__(self):
return self.pile
def next(): self.pile.next()
def _work(self, op):
running_ops = self.outstanding
self.outstanding += 1
t1 = time()
try:
# client = Connection(authurl='http://192.168.16.12:8080/auth/v1.0', user='test:tester', key='testing')
# client.put_object(self.container,'%s-%s' % (self.base, op), self.data)
get_object(self.storage_url, token=self.token, container=self.container, name='%s-%s' % (self.base, op))
t2 = time()
elapsed = (t2-t1) * 1000
self.outstanding -= 1
LOG.info("Operation #%d took %.2f ms (%.2f MB/s, %d ops outstanding on arrival)" % (op, elapsed, (self.data_size / (1024.*1024)) / (t2 - t1) , running_ops))
entry = { "Operation": op,
"Arrival-time": t1,
"Completion-time": t2,
"Elapsed": elapsed,
"Outstanding-on-arrival": running_ops,
"Outstanding-on-completion": self.outstanding }
print '%d, %f, %f, %.2f, %d, %d' % (op, t1, t2, elapsed, running_ops, self.outstanding)
return entry
except KeyboardInterrupt:
self.outstanding -= 1
self.running = False
return None
except Exception:
self.errors += 1
raise
def _run(self):
print '# date-time = %s' % datetime.now()
print '# object-size = %s' % self.data_size
print '# rate = %s' % self.rate
print "Operation, Arrival-time, Completion-time, Elapsed, Outstanding-on-arrival, Outstanding-on-completion"
self.running = True
while self.running:
sleep(self.dist.next())
if self.running:
self.ops += 1
self.pile.spawn(self._work, self.ops)
# stop looping if we have an operations limit
if self.running and self.total_ops:
self.running = self.ops < self.total_ops
self._done.send()
def start(self):
spawn_n(self._run)
def wait(self):
# wait for pending jobs
#while self.outstanding > 0: sleep(.1)
self._done.wait()
self.pile.pool.waitall()
def stop(self):
self.running = False
self.wait()