Skip to content

Commit

Permalink
support step load mode in locust ui
Browse files Browse the repository at this point in the history
  • Loading branch information
delulu committed Nov 4, 2019
1 parent bc703bd commit 7a4f6b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
16 changes: 14 additions & 2 deletions locust/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{% if is_distributed %}
<div class="top_box box_slaves" id="box_slaves">
<div class="label">SLAVES</div>
<div class="value" id="slaveCount">0</div>
<div class="value" id="slaveCount">{{slave_count}}</div>
</div>
{% endif %}
<div class="top_box box_rps box_running" id="box_rps">
Expand All @@ -57,10 +57,16 @@
<div class="padder">
<h2>Start new Locust swarm</h2>
<form action="./swarm" method="POST" id="swarm_form">
<label for="locust_count">Number of users to simulate</label>
<label for="locust_count">Number of total users to simulate</label>
<input type="text" name="locust_count" id="locust_count" class="val" /><br>
<label for="hatch_rate">Hatch rate <span style="color:#8a8a8a;">(users spawned/second)</span></label>
<input type="text" name="hatch_rate" id="hatch_rate" class="val" /><br>
{% if is_step_load %}
<label for="step_locust_count">Number of users to increase by step</label>
<input type="text" name="step_locust_count" id="step_locust_count" class="val" /><br>
<label for="step_duration">Step duration <span style="color:#8a8a8a;">(300s, 20m, 3h, 1h30m, etc.)</span></label>
<input type="text" name="step_duration" id="step_duration" class="val" /><br>
{% endif %}
<button type="submit">Start swarming</button>
</form>
<div style="clear:right;"></div>
Expand All @@ -78,6 +84,12 @@ <h2>Change the locust count</h2>
<input type="text" name="locust_count" id="new_locust_count" class="val" /><br>
<label for="hatch_rate">Hatch rate <span style="color:#8a8a8a;">(users spawned/second)</span></label>
<input type="text" name="hatch_rate" id="new_hatch_rate" class="val" /><br>
{% if is_step_load %}
<label for="step_locust_count">Number of users to increase by step</label>
<input type="text" name="step_locust_count" id="step_locust_count" class="val" /><br>
<label for="step_duration">Step duration <span style="color:#8a8a8a;">(300s, 20m, 3h, 1h30m, etc.)</span></label>
<input type="text" name="step_duration" id="step_duration" class="val" /><br>
{% endif %}
<button type="submit">Start swarming</button>
</form>
<div style="clear:right;"></div>
Expand Down
21 changes: 16 additions & 5 deletions locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .stats import distribution_csv, failures_csv, median_from_dict, requests_csv, sort_stats
from .util.cache import memoize
from .util.rounding import proper_round
from .util.time import parse_timespan

logger = logging.getLogger(__name__)

Expand All @@ -40,32 +41,42 @@
@app.route('/')
def index():
is_distributed = isinstance(runners.locust_runner, MasterLocustRunner)
slave_count = 0
if is_distributed:
slave_count = runners.locust_runner.slave_count
else:
slave_count = 0


if runners.locust_runner.host:
host = runners.locust_runner.host
elif len(runners.locust_runner.locust_classes) > 0:
host = runners.locust_runner.locust_classes[0].host
else:
host = None

is_step_load = runners.locust_runner.step_load

return render_template("index.html",
state=runners.locust_runner.state,
is_distributed=is_distributed,
user_count=runners.locust_runner.user_count,
version=version,
host=host
host=host,
slave_count=slave_count,
is_step_load=is_step_load
)

@app.route('/swarm', methods=["POST"])
def swarm():
assert request.method == "POST"

is_step_load = runners.locust_runner.step_load
locust_count = int(request.form["locust_count"])
hatch_rate = float(request.form["hatch_rate"])

if is_step_load:
step_locust_count = int(request.form["step_locust_count"])
step_duration = parse_timespan(str(request.form["step_duration"]))
runners.locust_runner.start_stepload(locust_count, hatch_rate, step_locust_count, step_duration)
return jsonify({'success': True, 'message': 'Swarming started in Step Load Mode'})

runners.locust_runner.start_hatching(locust_count, hatch_rate)
return jsonify({'success': True, 'message': 'Swarming started'})

Expand Down

0 comments on commit 7a4f6b2

Please sign in to comment.