Skip to content

Commit

Permalink
Add load testing scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
tooolbox committed May 26, 2020
1 parent 1fc3993 commit 3d0870c
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
8 changes: 8 additions & 0 deletions load/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Load Testing

These files can be run with [k6](https://github.com/loadimpact/k6). They're pretty rudimentary as far as load tests go but they did help to locate a deadlock, so they are being preserved for posterity.

Example command:
```
k6 run load/loadtest.js
```
70 changes: 70 additions & 0 deletions load/loadtest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import http from "k6/http";
import { check, sleep } from "k6";
import { Trend } from 'k6/metrics';

export let options = {
stages: [
// Ramp-up from 1 to 5 VUs in 10s
{
duration: "10s",
target: 50
},

// Stay at rest on 5 VUs for 5s
{
duration: "5s",
target: 50
},

// Ramp-down from 5 to 0 VUs for 5s
{
duration: "5s",
target: 0
},
// Ramp-down from 5 to 0 VUs for 5s
{
duration: "10s",
target: 1
}
]
};

let jobs = new Trend('jobs');
let activeJobs = new Trend('active_jobs');
let errorCount = new Trend('error_count');
let successCount = new Trend('success_count');

var count = 0;

function getSchedule(now) {
now.setSeconds(now.getSeconds() + 1);
return 'R5/' + now.toISOString() + '/PT5S';
}

export default function() {
let payload = JSON.stringify({
name: 'job' + (count++),
schedule: getSchedule(new Date()),
command: "bash -c 'date'"
});
let write = http.post("http://localhost:8000/api/v1/job/", payload);
check(write, {
"status is ok": (r) => r.status === 201
});
sleep(1);
let read = http.get("http://localhost:8000/api/v1/job/");
check(read, {
"status is ok": (r) => r.status === 200
});
sleep(1);
let stats = http.get("http://localhost:8000/api/v1/stats/");
check(stats, {
"status is ok": (r) => r.status === 200
});
let parsed = JSON.parse(stats.body);
jobs.add(parsed.Stats.jobs);
activeJobs.add(parsed.Stats.active_jobs);
errorCount.add(parsed.Stats.error_count);
successCount.add(parsed.Stats.success_count);
sleep(1);
}
70 changes: 70 additions & 0 deletions load/spiketest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import http from "k6/http";
import { check, sleep } from "k6";
import { Trend } from 'k6/metrics';

export let options = {
stages: [
// Ramp-up from 1 to 5 VUs in 10s
{
duration: "10s",
target: 5
},

// Stay at rest on 5 VUs for 5s
{
duration: "5s",
target: 200
},

// Ramp-down from 5 to 0 VUs for 5s
{
duration: "5s",
target: 5
},
// Ramp-down from 5 to 0 VUs for 5s
{
duration: "10s",
target: 1
}
]
};

let jobs = new Trend('jobs');
let activeJobs = new Trend('active_jobs');
let errorCount = new Trend('error_count');
let successCount = new Trend('success_count');

var count = 0;

function getSchedule(now) {
now.setSeconds(now.getSeconds() + 1);
return 'R5/' + now.toISOString() + '/PT5S';
}

export default function() {
let payload = JSON.stringify({
name: 'job' + (count++),
schedule: getSchedule(new Date()),
command: "bash -c 'date'"
});
let write = http.post("http://localhost:8000/api/v1/job/", payload);
check(write, {
"status is ok": (r) => r.status === 201
});
sleep(1);
let read = http.get("http://localhost:8000/api/v1/job/");
check(read, {
"status is ok": (r) => r.status === 200
});
sleep(1);
let stats = http.get("http://localhost:8000/api/v1/stats/");
check(stats, {
"status is ok": (r) => r.status === 200
});
let parsed = JSON.parse(stats.body);
jobs.add(parsed.Stats.jobs);
activeJobs.add(parsed.Stats.active_jobs);
errorCount.add(parsed.Stats.error_count);
successCount.add(parsed.Stats.success_count);
sleep(1);
}

0 comments on commit 3d0870c

Please sign in to comment.