From 19a1d274012dcf38b521966df6d059c3de27d5e0 Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Thu, 23 Dec 2021 10:54:12 +0200 Subject: [PATCH] [examples] Add NodeJS dummy server. --- examples/nodejs-dummy.js | 43 ++++++++++++++++++++++++++++++++++++++++ scripts/benchmark.z-run | 23 +++++++++++++++++---- 2 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 examples/nodejs-dummy.js diff --git a/examples/nodejs-dummy.js b/examples/nodejs-dummy.js new file mode 100644 index 0000000..e43341d --- /dev/null +++ b/examples/nodejs-dummy.js @@ -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); + diff --git a/scripts/benchmark.z-run b/scripts/benchmark.z-run index e269f8e..d1c0bc4 100644 --- a/scripts/benchmark.z-run +++ b/scripts/benchmark.z-run @@ -329,8 +329,6 @@ !! - - << benchmark / alternatives / haproxy-dummy exec -- \ sudo -u root -n -E -P -- \ @@ -349,8 +347,6 @@ !! - - << benchmark / alternatives / nginx-dummy exec -- \ 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 \ + "${@}" \ + # +!! + +