mirror of
https://github.com/valitydev/yandex-tank.git
synced 2024-11-08 03:08:56 +00:00
publish steps in instance_plan
This commit is contained in:
parent
fc7646aa64
commit
89da37aa05
@ -9,6 +9,7 @@ import logging
|
||||
class LoadPlanBuilder(object):
|
||||
|
||||
def __init__(self):
|
||||
self.generators = []
|
||||
self.steps = []
|
||||
self.instances = 0
|
||||
self.duration = 0
|
||||
@ -19,31 +20,34 @@ class LoadPlanBuilder(object):
|
||||
if count < 0:
|
||||
raise StepperConfigurationError(
|
||||
"Can not stop instances in instances_schedule.")
|
||||
self.steps.append(repeat(int(self.duration), count))
|
||||
self.generators.append(repeat(int(self.duration), count))
|
||||
self.instances += count
|
||||
return self
|
||||
|
||||
def wait(self, duration):
|
||||
self.log.debug("Wait for %sms from %sms" % (duration, self.duration))
|
||||
self.duration += duration
|
||||
self.steps.append((self.instances, duration / 1000.0))
|
||||
return self
|
||||
|
||||
def ramp(self, count, duration):
|
||||
self.log.debug("Ramp %s instances in %sms from %sms" % (count, duration, self.duration))
|
||||
self.log.debug("Ramp %s instances in %sms from %sms" %
|
||||
(count, duration, self.duration))
|
||||
if count < 0:
|
||||
raise StepperConfigurationError(
|
||||
"Can not stop instances in instances_schedule.")
|
||||
interval = float(duration) / count
|
||||
start_time = self.duration
|
||||
self.steps.append(int(start_time + i * interval)
|
||||
for i in xrange(0, count))
|
||||
self.generators.append(int(start_time + i * interval)
|
||||
for i in xrange(0, count))
|
||||
self.steps += [(self.instances + i, interval / 1000.0) for i in xrange(0, count)]
|
||||
self.instances += count
|
||||
self.duration += duration
|
||||
return self
|
||||
|
||||
def const(self, instances, duration):
|
||||
self.start(instances - self.instances)
|
||||
self.duration += duration
|
||||
return self
|
||||
|
||||
def wait(self, duration):
|
||||
self.log.debug("Wait for %sms from %sms" % (duration, self.duration))
|
||||
self.duration += duration
|
||||
self.wait(duration)
|
||||
return self
|
||||
|
||||
def line(self, initial_instances, final_instances, duration):
|
||||
@ -116,7 +120,8 @@ class LoadPlanBuilder(object):
|
||||
'(\d+),\s*(\d+),\s*(\d+),\s*([0-9.]+[dhms]?)+\)')
|
||||
s_res = template.search(params)
|
||||
if s_res:
|
||||
initial_instances, final_instances, step_size, step_duration = s_res.groups()
|
||||
initial_instances, final_instances, step_size, step_duration = s_res.groups(
|
||||
)
|
||||
self.stairway(int(initial_instances), int(final_instances), int(
|
||||
step_size), parse_duration(step_duration))
|
||||
else:
|
||||
@ -146,8 +151,8 @@ class LoadPlanBuilder(object):
|
||||
return self
|
||||
|
||||
def create(self):
|
||||
self.steps.append(cycle([0]))
|
||||
return chain(*self.steps)
|
||||
self.generators.append(cycle([0]))
|
||||
return chain(*self.generators)
|
||||
|
||||
|
||||
def create(instances_schedule):
|
||||
@ -176,9 +181,12 @@ def create(instances_schedule):
|
||||
|
||||
>>> take(10, create(['step(2, 10, 2, 3s)']))
|
||||
[0, 0, 3000, 3000, 6000, 6000, 9000, 9000, 0, 0]
|
||||
|
||||
>>> take(12, LoadPlanBuilder().const(3, 1000).line(5, 10, 5000).steps)
|
||||
[(3, 1.0), (5, 1.0), (6, 1.0), (7, 1.0), (8, 1.0), (9, 1.0)]
|
||||
'''
|
||||
lpb = LoadPlanBuilder().add_all_steps(instances_schedule)
|
||||
info.status.publish('duration', 0)
|
||||
info.status.publish('steps', [])
|
||||
info.status.publish('steps', lpb.steps)
|
||||
info.status.publish('instances', lpb.instances)
|
||||
return lpb.create()
|
||||
|
Loading…
Reference in New Issue
Block a user