Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflector load-testing application #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/load/index.vwf.config.yaml
@@ -0,0 +1,7 @@
---
info:
title: "Load Testing Application"
model:
nodriver:
view:
vwf/view/load-test:
228 changes: 228 additions & 0 deletions test/load/index.vwf.html
@@ -0,0 +1,228 @@
<!DOCTYPE html>

<html><head>

<meta charset="utf-8">

<title>Load Test</title>

<style>

body {
background: white;
font: 10px sans-serif;
}

.bar rect {
fill: steelblue;
shape-rendering: crispEdges;
}

.bar text {
fill: #fff;
}

.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}

.label {
font: 14px sans-serif;
}

</style>

</head><body>

<script>

require( [ "http://d3js.org/d3.v3.js", "https://rawgit.com/tmcw/simple-statistics/master/src/simple_statistics.js" ], function() {

var driver = vwf.views.filter( function( view ) {
while ( view.view ) { view = view.view }
return view.module.id === "vwf/view/load-test";
} )[ 0 ];

var data = driver && driver.state.results; // [ { ping: timestamp, pong: timestamp }, { ... } ]
var lastItem;

setInterval( function() {

if ( data && data[ data.length - 1 ] !== lastItem ) {

var latencies = data.map( function( item ) {
return item.pong - item.ping;
} );

var stats = {
n: latencies.length,
min: ss.min( latencies ),
max: ss.max( latencies ),
avg: ss.mean( latencies ),
stddev: ss.standard_deviation( latencies ),
};

var params = {
size: driver.state.size,
interval: driver.state.interval,
duration: driver.state.duration,
clients: Object.keys( driver.state.clients ).length,
pending: driver.state.pending,
rate: ( data.length - 1 + driver.state.others ) / ( data[ data.length - 1 ].pong - data[0].pong ) * 1000,
};

graph( latencies, stats, params );

lastItem = data[ data.length - 1 ];
}

}, 1000 );

function graph( values, stats, params ) {

d3.selectAll("svg").remove();

// A formatter for counts.
var formatCount = d3.format(",.0f");

var margin = {top: 10, right: 30, bottom: 30, left: 30},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;

var x = d3.scale.linear()
.domain([0, 100])
.range([0, width]);

// Generate a histogram using twenty uniformly-spaced bins.
var data = d3.layout.histogram()
.bins(x.ticks(20))
(values);

var y = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d.y; })])
.range([height, 0]);

var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");

var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom + 75)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

var bar = svg.selectAll(".bar")
.data(data)
.enter().append("g")
.attr("class", "bar")
.attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; });

bar.append("rect")
.attr("x", 1)
.attr("width", x(data[0].dx) - 1)
.attr("height", function(d) { return height - y(d.y); });

bar.append("text")
.attr("dy", ".75em")
.attr("y", 6)
.attr("x", x(data[0].dx) / 2)
.attr("text-anchor", "middle")
.text(function(d) { return formatCount(d.y); });

svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);

var legend = svg.append("g")
.selectAll("text")
.data([stats])
.enter();

legend.append("text")
.attr("class","label")
.attr("x",0)
.attr("y",500)
.text(function(d,i) { return "n: " + d.n });

legend.append("text")
.attr("class","label")
.attr("x",1*width/10)
.attr("y",500)
.text(function(d,i) { return "min: " + d.min });

legend.append("text")
.attr("class","label")
.attr("x",2*width/10)
.attr("y",500)
.text(function(d,i) { return "max: " + d.max });

legend.append("text")
.attr("class","label")
.attr("x",3*width/10)
.attr("y",500)
.text(function(d,i) { return "avg: " + d.avg.toPrecision(4) });

legend.append("text")
.attr("class","label")
.attr("x",4*width/10)
.attr("y",500)
.text(function(d,i) { return "stddev: " + d.stddev.toPrecision(4) });

legend.append("text")
.attr("class","label")
.attr("text-anchor","end")
.attr("x",width)
.attr("y",500)
.text("ms");

var legend = svg.append("g");

legend.append("text")
.attr("class","label")
.attr("x",0)
.attr("y",525)
.text("size: " + params.size + "B");

legend.append("text")
.attr("class","label")
.attr("x",1*width/10)
.attr("y",525)
.text("intrvl: " + params.interval*1000 + "ms");

legend.append("text")
.attr("class","label")
.attr("x",2*width/10)
.attr("y",525)
.text("clients: " + params.clients);

legend.append("text")
.attr("class","label")
.attr("x",3*width/10)
.attr("y",525)
.text("dur: " + params.duration + "s");

var legend = svg.append("g");

legend.append("text")
.attr("class","label")
.attr("x",0)
.attr("y",550)
.text("rate: " + params.rate.toPrecision(4) + "/s");

legend.append("text")
.attr("class","label")
.attr("x",1*width/10)
.attr("y",550)
.text("unack: " + params.pending);

}

} );

</script>

</body></html>
26 changes: 26 additions & 0 deletions test/load/index.vwf.yaml
@@ -0,0 +1,26 @@
# Copyright 2015 United States Government, as represented by the Secretary of Defense, Under
# Secretary of Defense (Personnel & Readiness).
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

## Load testing application.

---
properties:
enabled: false
duration: 10
size: 1
interval: 1
methods:
ping:
parameters:
- time
- payload