print libuv threadpool size in node js 8
Asked Answered
D

1

3

This link purely specifies that libuv provides a thread pool which can be used to run user code and get notified in the loop thread. Its default size is 4, but it can be changed at startup time by setting the UV_THREADPOOL_SIZE environment variable to any value. (the absolute maximum is 128).

So, in package.json, I set scripts field as below (NOTE: I am using Windows 7, Node JS 8.11.3, nodemon, express 4.16),

Code snippet from package.json

.
.
.
"scripts": {
    "start": "SET UV_THREADPOOL_SIZE = 120 && node index.js",
  },
.
.
.

Code for index.js

var express = require('express');
var app = express();

var server = app.listen(3000, function(){
    console.log('LIBUV Threads: ', process.env.UV_THREADPOOL_SIZE); // this returns 'undefined'
});

How can I be assured that thread pool size is set? I want to print it out here in index.js as above.

Dyl answered 27/5, 2018 at 13:36 Comment(0)
P
9

You shouldn't have spaces in your set command.

set UV_THREADPOOL_SIZE=120 && node index.js

Also you should start your Node.js program by invoking the start script:

npm start

Otherwise the environmental variable won't be set and you will continue to get undefined when accessing it in your code.

If you are using Nodemon, you can ensure your npm script is invoked by running the command with an extra argument:

nodemon --exec npm start
Pinguid answered 27/5, 2018 at 13:42 Comment(8)
Thanks for that rectification, but still I get undefined.Dyl
Can you please try the same command but using only 1 ampersand (&)?Pinguid
Yup! I did and result is unaffected. Also, I doubt whether process.env.UV_THREADPOOL_SIZE is the right way to print the libuv thread pool in node jsDyl
Do you start your server with npm start?Pinguid
I use nodemon, it automatically identifies the start script.Dyl
Did you try running just npm start? nodemon looks for index.js if it is run without arguments (if I remember correctly).Pinguid
Yeah! you are absolutely correct. It worked! can you update your answer with proper directions, so that I will accept it? also I will update my question with more detailsDyl
but how do we actually see if the config gets picked up, I am working on windows so some of the linux commands arent fetching my purpose.Traduce

© 2022 - 2024 — McMap. All rights reserved.