tspace-spear 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -4
- package/dist/lib/core/decorators/context.d.ts +91 -0
- package/dist/lib/core/decorators/controller.d.ts +34 -0
- package/dist/lib/core/decorators/headers.d.ts +31 -0
- package/dist/lib/core/decorators/index.d.ts +9 -0
- package/dist/lib/core/decorators/methods.d.ts +82 -0
- package/dist/lib/core/decorators/middleware.d.ts +39 -0
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/statusCode.d.ts +26 -0
- package/dist/lib/core/decorators/swagger.d.ts +36 -0
- package/dist/lib/core/server/index.d.ts +302 -0
- package/dist/lib/core/server/index.js +343 -140
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/parser-factory.d.ts +32 -0
- package/dist/lib/core/server/parser-factory.js +269 -4
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/router.d.ts +109 -0
- package/dist/lib/core/server/router.js +12 -0
- package/dist/lib/core/server/router.js.map +1 -1
- package/dist/lib/core/types/index.d.ts +248 -0
- package/dist/lib/index.d.ts +11 -0
- package/package.json +24 -10
- package/dist/lib/core/server/radix-router.js +0 -65
- package/dist/lib/core/server/radix-router.js.map +0 -1
- package/dist/tests/benchmark.test.js +0 -145
- package/dist/tests/benchmark.test.js.map +0 -1
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const autocannon_1 = __importDefault(require("autocannon"));
|
|
7
|
-
const fastify_1 = __importDefault(require("fastify"));
|
|
8
|
-
const express_1 = __importDefault(require("express"));
|
|
9
|
-
const http_1 = __importDefault(require("http"));
|
|
10
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
11
|
-
const lib_1 = __importDefault(require("../lib"));
|
|
12
|
-
const MESSAGE = 'Hello world!';
|
|
13
|
-
const { argv } = (0, yargs_1.default)(process.argv.slice(2));
|
|
14
|
-
let duration = argv.d || argv.duration;
|
|
15
|
-
let connections = argv.c || argv.connections;
|
|
16
|
-
let pipelining = argv.p || argv.pipelining;
|
|
17
|
-
connections = connections == null ? 100 : Number(connections);
|
|
18
|
-
pipelining = pipelining == null ? 10 : Number(pipelining);
|
|
19
|
-
duration = duration == null ? 10 : Number(duration);
|
|
20
|
-
function runExpress() {
|
|
21
|
-
const port = 3000;
|
|
22
|
-
(0, express_1.default)()
|
|
23
|
-
.get('/', (req, res) => {
|
|
24
|
-
res.setHeader('Content-Type', 'text/plain');
|
|
25
|
-
return res.send(MESSAGE);
|
|
26
|
-
})
|
|
27
|
-
.listen(port, () => {
|
|
28
|
-
console.log(`Server 'Express' running at http://localhost:${port}`);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function runHttp() {
|
|
32
|
-
const port = 3001;
|
|
33
|
-
const server = http_1.default.createServer((req, res) => {
|
|
34
|
-
res.statusCode = 200;
|
|
35
|
-
res.setHeader('Content-Type', 'text/plain');
|
|
36
|
-
res.end(MESSAGE);
|
|
37
|
-
});
|
|
38
|
-
server.listen(port, () => {
|
|
39
|
-
console.log(`Server 'Http' running at http://localhost:${port}`);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function runFastify() {
|
|
43
|
-
const port = 3002;
|
|
44
|
-
(0, fastify_1.default)()
|
|
45
|
-
.get('/', (request, reply) => {
|
|
46
|
-
return reply
|
|
47
|
-
.header('Content-Type', 'text/plain')
|
|
48
|
-
.send(MESSAGE);
|
|
49
|
-
})
|
|
50
|
-
.listen({ port }, (err, address) => {
|
|
51
|
-
if (err)
|
|
52
|
-
throw err;
|
|
53
|
-
console.log(`server 'Fastify' running at : http://localhost:${port}`);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function runSpear() {
|
|
57
|
-
const port = 3003;
|
|
58
|
-
new lib_1.default()
|
|
59
|
-
.get('/', () => MESSAGE)
|
|
60
|
-
.listen(port, () => console.log(`server 'Spear' running at : http://localhost:${port}`));
|
|
61
|
-
}
|
|
62
|
-
const url = (port) => `http://localhost:${port}`;
|
|
63
|
-
const urls = [
|
|
64
|
-
{ name: 'express', url: url(3000) },
|
|
65
|
-
{ name: 'http', url: url(3001) },
|
|
66
|
-
{ name: 'fastify', url: url(3002) },
|
|
67
|
-
{ name: 'tspace-spear', url: url(3003) }
|
|
68
|
-
];
|
|
69
|
-
const sleep = (ms) => {
|
|
70
|
-
return new Promise(resolve => setTimeout(resolve, ms, null));
|
|
71
|
-
};
|
|
72
|
-
const runBenchmark = async () => {
|
|
73
|
-
const results = [];
|
|
74
|
-
const randomized = shuffle(urls);
|
|
75
|
-
await new Promise((resolve, reject) => {
|
|
76
|
-
(0, autocannon_1.default)({
|
|
77
|
-
url: randomized[0].url,
|
|
78
|
-
connections,
|
|
79
|
-
duration: 3
|
|
80
|
-
}, (err) => {
|
|
81
|
-
if (err)
|
|
82
|
-
return reject(err);
|
|
83
|
-
resolve(null);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
for (const { name, url } of randomized) {
|
|
87
|
-
const result = await new Promise((resolve, reject) => {
|
|
88
|
-
(0, autocannon_1.default)({
|
|
89
|
-
url,
|
|
90
|
-
connections,
|
|
91
|
-
duration,
|
|
92
|
-
pipelining
|
|
93
|
-
}, (err, result) => {
|
|
94
|
-
if (err)
|
|
95
|
-
return reject(err);
|
|
96
|
-
return resolve(result);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
const toMs = (v) => Number((v / 1000).toFixed(3));
|
|
100
|
-
const latency = result.latency;
|
|
101
|
-
results.push({
|
|
102
|
-
name,
|
|
103
|
-
url,
|
|
104
|
-
"req/sec": Number(result.requests.average.toFixed(0)),
|
|
105
|
-
"avg(ms)": toMs(latency.average),
|
|
106
|
-
"p50(ms)": toMs(latency.p50),
|
|
107
|
-
"p90(ms)": toMs(latency.p90),
|
|
108
|
-
"p97(ms)": toMs(latency.p97_5),
|
|
109
|
-
"p99(ms)": toMs(latency.p99),
|
|
110
|
-
"max(ms)": toMs(latency.max),
|
|
111
|
-
"stddev": Number(latency.stddev.toFixed(2)),
|
|
112
|
-
"requests": result.requests.total
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
// sort ตาม performance
|
|
116
|
-
results.sort((a, b) => Number(b["req/sec"]) - Number(a["req/sec"]));
|
|
117
|
-
console.log({
|
|
118
|
-
connections,
|
|
119
|
-
duration,
|
|
120
|
-
pipelining
|
|
121
|
-
});
|
|
122
|
-
console.table(results);
|
|
123
|
-
};
|
|
124
|
-
const shuffle = (arr) => {
|
|
125
|
-
const a = [...arr];
|
|
126
|
-
for (let i = a.length - 1; i > 0; i--) {
|
|
127
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
128
|
-
[a[i], a[j]] = [a[j], a[i]];
|
|
129
|
-
}
|
|
130
|
-
return a;
|
|
131
|
-
};
|
|
132
|
-
async function runApps() {
|
|
133
|
-
await Promise.all([
|
|
134
|
-
runSpear,
|
|
135
|
-
runFastify,
|
|
136
|
-
runExpress,
|
|
137
|
-
runHttp
|
|
138
|
-
].map(v => v()));
|
|
139
|
-
await sleep(5000);
|
|
140
|
-
console.log('benchmarking !!');
|
|
141
|
-
await runBenchmark();
|
|
142
|
-
console.log('benchmarking done !!');
|
|
143
|
-
}
|
|
144
|
-
runApps();
|
|
145
|
-
//# sourceMappingURL=benchmark.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"benchmark.test.js","sourceRoot":"","sources":["../../src/tests/benchmark.test.ts"],"names":[],"mappings":";;;;;AAAA,4DAAgD;AAChD,sDAA6B;AAC7B,sDAAoD;AACpD,gDAAuB;AACvB,kDAA0B;AAC1B,iDAA0B;AAE1B,MAAM,OAAO,GAAG,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