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
7.x: new router and middleware system #1561
Merged
+4,193
−3,386
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
99123d1
feat(server): new router and middleware system
hekike f9ed7ed
feat(plugins): add pre, use and route handlers latencies to metrics p…
f7cfba1
feat(server): emit after event when both request is flushed and last …
3616028
feat(plugins): add totalLatency to metrics plugin
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,33 @@ | ||
'use strict'; | ||
|
||
var restify = process.argv.includes('version=head') | ||
? require('../../lib') | ||
: require('restify'); | ||
|
||
var server = restify.createServer(); | ||
var path = '/'; | ||
var port = 3000; | ||
|
||
module.exports = { | ||
url: 'http://localhost:' + port + path | ||
}; | ||
|
||
function handler(req, res, next) { | ||
next(); | ||
} | ||
|
||
for (var i = 0; i < 10; i++) { | ||
server.pre(handler); | ||
} | ||
|
||
for (var j = 0; j < 10; j++) { | ||
server.use(handler); | ||
} | ||
|
||
server.get(path, function get(req, res) { | ||
res.send('hello world'); | ||
}); | ||
|
||
if (!module.parent) { | ||
server.listen(port); | ||
} |
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
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
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,132 @@ | ||
'use strict'; | ||
|
||
var restify = process.argv.includes('version=head') | ||
? require('../../lib') | ||
: require('restify'); | ||
|
||
var server = restify.createServer(); | ||
var path = '/whiskeys/scotch/islay/lagavulin/16-years/50'; | ||
var methods = ['post', 'put', 'get', 'del', 'patch']; | ||
var _ = require('lodash'); | ||
var port = 3000; | ||
|
||
// Disabling cache: it's not fair as it aims to the worst case, when | ||
// cache hit ratio is 0%. However, it's still better than the worst | ||
// as it doesn't require extra time to maintain the LRU cache. | ||
// There is no other way to simulate 100+ different endpoint | ||
// calls with the current benchmark suite. | ||
if (!process.argv.includes('version=head')) { | ||
server.router.cache = { | ||
get: function get() { | ||
return null; | ||
}, | ||
set: function get() { | ||
return null; | ||
}, | ||
dump: function get() { | ||
return []; | ||
} | ||
}; | ||
} | ||
|
||
module.exports = { | ||
url: 'http://localhost:' + port + path | ||
}; | ||
|
||
var routes = { | ||
beers: { | ||
ale: { | ||
'pale-ale': { | ||
'american-pale-ale': [], | ||
'indian-pale-ale': [] | ||
}, | ||
lambic: [], | ||
stout: { | ||
'american-porter': [], | ||
'imperial-stout': [], | ||
'irish-stout': [] | ||
} | ||
}, | ||
lager: { | ||
'german-lager': { | ||
marzen: [] | ||
}, | ||
pilsner: { | ||
'german-pilsner': [] | ||
} | ||
} | ||
}, | ||
|
||
whiskeys: { | ||
american: { | ||
bourbon: { | ||
kentchuky: { | ||
'jim-beam': ['jim-beam', 'bookers', 'old-crow'], | ||
'makers-mark': ['makers-mark'], | ||
'woodford-reserve': ['woodford-reserve'] | ||
}, | ||
tennessee: { | ||
'jack-daniels': ['jack-daniels'] | ||
} | ||
}, | ||
rye: { | ||
'beam-suntory': ['jim-beam-rye', 'knob-creek'] | ||
} | ||
}, | ||
irish: { | ||
'single-malt': { | ||
bushmills: ['bushmills'], | ||
connemare: ['connemare'] | ||
}, | ||
'single-pot': { | ||
redbreast: ['redbreast'], | ||
jameson: ['jameson-15-year'] | ||
} | ||
}, | ||
japanese: { | ||
nikka: ['coffeey-malt', 'blended', 'from-the-barrel'], | ||
hibiki: ['japanese-harmony'], | ||
yamazakura: ['blended'] | ||
}, | ||
scotch: { | ||
islay: { | ||
bruichladdich: ['25-years', 'islay-barley-2009'], | ||
octomore: ['7.2', 'islay-barley-8.3'], | ||
laphroaig: ['lore', '15-years', 'four-oak'], | ||
lagavulin: ['distillers-edition', '8-years', '16-years'] | ||
} | ||
} | ||
} | ||
}; | ||
|
||
function handler(req, res) { | ||
res.send('hello'); | ||
} | ||
|
||
function attachRoute(parent, routeConfig) { | ||
_.map(routeConfig, function map(route, routeKey) { | ||
var pathChunk = _.isString(routeKey) ? routeKey : route; | ||
var routePath = parent + '/' + pathChunk; | ||
|
||
methods.forEach(function forEach(method) { | ||
server[method](routePath, handler); | ||
}); | ||
|
||
if (_.isObject(route) || _.isArray(route)) { | ||
attachRoute(routePath, route); | ||
} | ||
if (_.isString(route)) { | ||
for (var i = 0; i <= 100; i++) { | ||
methods.forEach(function forEach(method) { | ||
server[method](routePath + '/' + i, handler); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
attachRoute('', routes); | ||
|
||
if (!module.parent) { | ||
server.listen(port); | ||
} |
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
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
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
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,19 @@ | ||
{ | ||
"name": "restify-benchmark", | ||
"homepage": "http://restifyjs.com", | ||
"description": "Restify benchmark", | ||
"version": "0.0.0", | ||
"private": true, | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10" | ||
}, | ||
"dependencies": { | ||
"restify": "*" | ||
}, | ||
"devDependencies": {}, | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node indec" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍺
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥃