Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 | ||
|
||
.PHONY: all middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
export FACTOR=$1 | ||
export USE_MIDDLEWARE=$2 | ||
export PORT=3333 | ||
|
||
host="http://localhost:$PORT" | ||
|
||
node "$(dirname $0)/server.js" & | ||
|
||
pid=$! | ||
|
||
curl \ | ||
--retry-connrefused \ | ||
--retry 5 \ | ||
--retry-delay 0 \ | ||
-s \ | ||
"$host/_health" \ | ||
> /dev/null | ||
|
||
# siege -c 50 -t 8 "$host/10/child/grandchild/%40" | ||
wrk "$host/10/child/grandchild/%40" \ | ||
-d 3 \ | ||
-c 50 \ | ||
-t 8 \ | ||
| grep 'Requests/sec' \ | ||
| awk '{ print " " $2 }' | ||
|
||
kill $pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const Koa = require('koa'); | ||
const Router = require('../'); | ||
|
||
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'; | ||
|
||
router.get('/_health', ok); | ||
|
||
for (let i = n; i > 0; i--) { | ||
if (useMiddleware) router.use((ctx, next) => next()); | ||
router.get(`/${i}/one`, ok); | ||
router.get(`/${i}/one/two`, ok); | ||
router.get(`/${i}/one/two/:three`, ok); | ||
router.get(`/${i}/one/two/:three/:four?`, ok); | ||
router.get(`/${i}/one/two/:three/:four?/five`, ok); | ||
router.get(`/${i}/one/two/:three/:four?/five/six`, ok); | ||
} | ||
|
||
const grandchild = new Router(); | ||
|
||
if (useMiddleware) grandchild.use((ctx, next) => next()); | ||
grandchild.get('/', ok); | ||
grandchild.get('/:id', ok); | ||
grandchild.get('/:id/seven', ok); | ||
grandchild.get('/:id/seven(/eight)?', ok); | ||
|
||
for (let i = n; i > 0; i--) { | ||
let child = new Router(); | ||
if (useMiddleware) child.use((ctx, next) => next()); | ||
child.get(`/:${''.padStart(i, 'a')}`, ok); | ||
child.nest('/grandchild', grandchild); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jbielick
Author
Collaborator
|
||
router.nest(`/${i}/child`, child); | ||
} | ||
|
||
if (process.env.DEBUG) { | ||
console.log(require('../lib/utils').inspect(router)); | ||
} | ||
|
||
app.use(router.routes()); | ||
|
||
process.stdout.write(`mw: ${useMiddleware} factor: ${n}`); | ||
|
||
app.listen(process.env.PORT); |
@jbielick Hey, do you remember how you were using
child.nest()
when writing this? I can't find the relevant API and would love to know this was meant to work!