• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

#yyds干货盘点#windows下设置process.env.UV_THREADPOOL_SIZE无效

武飞扬头像
尼羲
帮助1

node在执行IO操作(读取文件)时会开启线程池(默认是4个),我们可以通过设置UV_THREADPOOL_SIZE增加线程池个数。

背景:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
const fs = require("fs");

process.env.UV_THREADPOOL_SIZE=64;

setInterval(() => {
    fs.readFile(`${__dirname}/index.html`,()=>{
        console.log("read success");
    })
}, 3000);
{
  "name": "threadpool",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start":"node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

在windows下运行node,发现process.env.UV_THREADPOOL_SIZE设置无效。

线程数量应该从12增加到76个,实际为16个,说明UV_THREADPOOL_SIZE设置无效

原因:

Linux系统下可以在js代码里直接设置,而windows系统下需要在执行node命令前设置线程池数量,将node启动改为如下图(注:=号左右不要有空格)

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhibegai
系列文章
更多 icon
同类精品
更多 icon
继续加载