Ank*_*oni 2 javascript node.js libuv ecmascript-6
此链接纯粹指定libuv提供一个线程池,可用于运行用户代码并在循环线程中获得通知。它的默认大小为 4,但可以在启动时通过将UV_THREADPOOL_SIZE环境变量设置为任何值来更改它。(绝对最大值为 128)。
因此,在 中package.json,我将scripts字段设置如下(注意:我使用的是 Windows 7、Node JS 8.11.3、nodemon、express 4.16),
代码片段来自 package.json
.
.
.
"scripts": {
"start": "SET UV_THREADPOOL_SIZE = 120 && node index.js",
},
.
.
.
Run Code Online (Sandbox Code Playgroud)
代码 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'
});
Run Code Online (Sandbox Code Playgroud)
我如何确保设置了线程池大小?我想在index.js上面打印出来。
你的set命令中不应该有空格。
set UV_THREADPOOL_SIZE=120 && node index.js
Run Code Online (Sandbox Code Playgroud)
您还应该通过调用start脚本来启动 Node.js 程序:
npm start
Run Code Online (Sandbox Code Playgroud)
否则环境变量将不会被设置,你将undefined在代码中访问它时继续获取。
如果您使用的是 Nodemon,您可以通过运行带有额外参数的命令来确保您的 npm 脚本被调用:
nodemon --exec npm start
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4993 次 |
| 最近记录: |