/
router-heavy.js
132 lines (120 loc) · 3.53 KB
/
router-heavy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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);
}