[examples] Add NodeJS dummy server.

This commit is contained in:
Ciprian Dorin Craciun 2021-12-23 10:54:12 +02:00
parent 400fc81c5c
commit 19a1d27401
2 changed files with 62 additions and 4 deletions

43
examples/nodejs-dummy.js Normal file
View file

@ -0,0 +1,43 @@
const process = require ("process");
const http = require ("http");
const _dummyBodyString = "hello world!\n";
const _dummyBodySize = _dummyBodyString.length;
const _dummyBodyBuffer = Buffer.alloc (_dummyBodySize, _dummyBodyString, "utf-8");
const _dummyHeaders = [
"Content-Length", _dummyBodySize.toString (),
"Content-Type", "text/plain; charset=utf-8",
"Content-Encoding", "identity",
"Cache-Control", "no-store, max-age=0",
];
function _handler (_request, _response) {
_response.sendDate = false;
_response.writeHead (200, "OK", _dummyHeaders);
_response.end (_dummyBodyBuffer);
};
const _server = http.createServer ({}, _handler);
var _endpoint_ip = "127.0.0.1";
var _endpoint_port = 8080;
switch (process.argv.length) {
case 2 :
break;
case 3 :
_endpoint_port = parseInt (process.argv[2]);
break;
case 4 :
_endpoint_ip = process.argv[2];
_endpoint_port = parseInt (process.argv[3]);
break;
default :
throw Error ("[a102837d]");
}
_server.listen (_endpoint_port, _endpoint_ip, 65536);

View file

@ -329,8 +329,6 @@
!! !!
<< benchmark / alternatives / haproxy-dummy << benchmark / alternatives / haproxy-dummy
exec -- \ exec -- \
sudo -u root -n -E -P -- \ sudo -u root -n -E -P -- \
@ -349,8 +347,6 @@
!! !!
<< benchmark / alternatives / nginx-dummy << benchmark / alternatives / nginx-dummy
exec -- \ exec -- \
sudo -u root -n -E -P -- \ sudo -u root -n -E -P -- \
@ -370,6 +366,25 @@
!! !!
<< benchmark / alternatives / nodejs-dummy
exec -- \
sudo -u root -n -E -P -- \
taskset -c 0,1 \
nice -n -19 -- \
ionice -c 2 -n 0 -- \
chrt -r 10 \
prlimit -n262144 -- \
sudo -u "${USER}" -n -E -P -- \
env -i -- \
./.bin/node16 \
-- \
./examples/nodejs-dummy.js \
127.9.185.194 8080 \
"${@}" \
#
!!