测试代码
const http = require("http");
const fs = require("fs");
const path = require("path");
const port = 3000;
function sleep(ms) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, ms);
});
}
http
.createServer(async function(request, response) {
await sleep(200);
response.end("Hello, world!");
})
.listen(port);
console.log(`listen http://localhost:${port}/`);
Node v10.15.3
> siege -c 100 -t 10s http://127.0.0.1:3000/
Transactions: 4193 hits
Availability: 100.00 %
Elapsed time: 9.83 secs
Data transferred: 0.05 MB
Response time: 0.23 secs
Transaction rate: 426.55 trans/sec
Throughput: 0.01 MB/sec
Concurrency: 98.04
Successful transactions: 4200
Failed transactions: 0
Longest transaction: 0.26
Shortest transaction: 0.20
Node v12.0.0
> siege -c 100 -t 10s http://127.0.0.1:3000/
Transactions: 3809 hits
Availability: 100.00 %
Elapsed time: 9.10 secs
Data transferred: 0.05 MB
Response time: 0.23 secs
Transaction rate: 418.57 trans/sec
Throughput: 0.01 MB/sec
Concurrency: 96.55
Successful transactions: 3809
Failed transactions: 0
Longest transaction: 0.26
Shortest transaction: 0.20