njs
njs copied to clipboard
request localServer datasize between 131k and 165k , response time > 40ms
When request datasize between 131k and 165k , response time > 40ms else response time < 2ms
OS: linux mint 20.3 (Una) unused container nginx version: nginx/1.23.0 njs version: nginx-module-njs_1.23.0+0.7.5-1_focal_amd64
nginx.conf
js_import xxx/http.js
location /njs {
add_header content-type text/plain;
js_content http.hello;
}
http.js
function http(r) {
r.return(200, "Hello world!");
}
export default {hello: http};
request script:
const fetch=require('node-fetch');
const body="1".repeat(132*1000); //postdata
async function request(){
console.time("time")
let res=await fetch("http://127.0.0.1/njs", {
"headers": {
"content-type": "text/plain; charset=utf-8"
},
"body": body,
"method": "POST"
})
console.log('response:',(await res.text()));
console.timeEnd("time")
}
async function main(){
for (let i=0;i<10;i++){
await request();
}
}
main();
Today, I tested with the container again and found that this problem only occurs when the request is made on the local network!