Skip to content

Commit

Permalink
Dynamic Variables and Improved Benchmark files (#60)
Browse files Browse the repository at this point in the history
* Environment set and dynamic

* Removed local setting file added by mistake

* Benchmarks now working with dynamic environment variables make file pass in FACTOR and USE_MIDDLEWARE

* Removing messages I had added because the output looked cluttered
- Improving the output could be helpful
- Kept the order in the makefile

* clarify the number output meaning
  • Loading branch information
JacobMGEvans authored Feb 24, 2020
1 parent 24d0a4f commit 1940ec9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
36 changes: 18 additions & 18 deletions bench/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
all: middleware

middleware:
@./run 1 false
@./run 5 false
@./run 10 false
@./run 20 false
@./run 50 false
@./run 100 false
@./run 200 false
@./run 500 false
@./run 1000 false
@./run 1 true
@./run 5 true
@./run 10 true
@./run 20 true
@./run 50 true
@./run 100 true
@./run 200 true
@./run 500 true
@./run 1000 true
@sh ./run 1 false
@sh ./run 5 false
@sh ./run 10 false
@sh ./run 20 false
@sh ./run 50 false
@sh ./run 100 false
@sh ./run 200 false
@sh ./run 500 false
@sh ./run 1000 false
@sh ./run 1 true
@sh ./run 5 true
@sh ./run 10 true
@sh ./run 20 true
@sh ./run 50 true
@sh ./run 100 true
@sh ./run 200 true
@sh ./run 500 true
@sh ./run 1000 true

.PHONY: all middleware
9 changes: 5 additions & 4 deletions bench/run
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
#!/bin/env bash

set -e

set -o allexport; source "$(dirname $0)/../.env"; set +o allexport
export FACTOR=$1
export USE_MIDDLEWARE=$2

host="http://localhost:3333"
host="http://localhost:$PORT"

node "$(dirname $0)/server.js" &

Expand All @@ -27,4 +27,5 @@ wrk "$host/10/child/grandchild/%40" \
| grep 'Requests/sec' \
| awk '{ print " " $2 }'

kill $pid
kill $pid
exit
10 changes: 6 additions & 4 deletions bench/server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const Koa = require('koa');
const Router = require('../');
const env = require('@ladjs/env')({path:'../.env', includeProcessEnv: true,
assignToProcessEnv: true,});

const app = new Koa();
const router = new Router();

const ok = ctx => ctx.status = 200;
const n = parseInt(process.env.FACTOR || '10', 10);
const useMiddleware = process.env.USE_MIDDLEWARE === 'true';
const n = parseInt(env.FACTOR || '10', 10);
const useMiddleware = env.USE_MIDDLEWARE === 'true';

router.get('/_health', ok);

Expand Down Expand Up @@ -42,6 +44,6 @@ if (process.env.DEBUG) {

app.use(router.routes());

process.stdout.write(`mw: ${useMiddleware} factor: ${n}`);
process.stdout.write(`mw: ${useMiddleware} factor: ${n} requests/sec`);

app.listen(3333);
app.listen(env.PORT);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"urijs": "^1.19.2"
},
"devDependencies": {
"@ladjs/env": "^1.0.0",
"expect.js": "^0.3.1",
"jsdoc-to-markdown": "^5.0.3",
"koa": "^2.11.0",
Expand Down

0 comments on commit 1940ec9

Please sign in to comment.