admin管理员组文章数量:1305361
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.
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.
1 Answer
Reset to default 9You shouldn't have spaces in your set
mand.
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 mand with an extra argument:
nodemon --exec npm start
本文标签: javascriptprint libuv threadpool size in node js 8Stack Overflow
版权声明:本文标题:javascript - print libuv threadpool size in node js 8 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741800803a2398210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论