Skip to content

UV_THREADPOOL_SIZE undefined in Windows #1429

Closed

Description

@rhernandog
  • Node.js Version: 8.11.2
  • OS: Windows 7 64
  • Scope (install, code, runtime, meta, other?): startup
  • Module (and version) (if relevant): none

Hi,

I'm not completely sure if this should be here or on the libuv repo, so correct me if I'm in the wrong place asking the wrong question.

I was running some benchmarks with apache benchmark on an express server and I tried to modify the number of threads in the thread pool through my index.js file with no success:
process.env.UV_THREADPOOL_SIZE=1;

I ran it through the command line and it worked, then I wanted to check the amount of threads by doing a console.log(process.env.UV_THREADPOOL_SIZE) call. The thing is that I forgot to remove that line of code and when I restarted my laptop I got undefined from the console call.

So in fact when you start a fresh boot of the machine the UV_THREADPOOL_SIZE property is not set in the process.env object. Why is that?, Why the property is not added with it's default size (4 as I understand from the libuv docs) at startup?.

On Start Up

console.log(process.env.UV_THREADPOOL_SIZE); // -> undefined

Activity

  1. gireeshpunathil commented on Aug 14, 2018

    @gireeshpunathil
    Member
    #cat 1429.js
    process.env.UV_THREADPOOL_SIZE=1;
    console.log(process.env.UV_THREADPOOL_SIZE)
    #node 1429.js
    1
    #
    

    it does not happen to me. Just to be sure that we are on the same page: index.js is the only code you are having, or do you spawn other processes? I guess the settings in the index.js do not propagate to child processes, can you please check?

  2. rhernandog commented on Aug 14, 2018

    @rhernandog
    Author

    @gireeshpunathil Thanks for the answer.

    Yep just one file. Here's an extremely simplified set up to reproduce the issue:

    index.js

    console.log( process.env.UV_THREADPOOL_SIZE ); // -> undefined
    
    const express = require("express");
    
    // EXPRESS
    const app = express();
    
    app.get("/", (req, res) => {
      res.send("Hi didly ho!!!");
    });
    
    app.get("/fast", (req, res) => {
      res.send("FAST FAST FAST!!!!");
    });
    
    app.listen(3000, null, () => {
      console.log("express working on port 3000!!!");
    })

    This in a folder with just express 4.16.3 installed. Run node index and this is the result:
    node-threadpool-issue
    As I mentioned this happens on Windows 7 64b (I believe most windows OS as well, haven't tested in 8 or 10 yet).

    Also is worth mentioning that if I set the thread pool size via command line it is defined and set and after that I can change it through the index.js file or any other file. So doing this first:

    $ SET UV_THREADPOOL_SIZE=1
    

    Then running the index file gives this result:

    $ node index
    1
    express working on port 3000!!!
    
  3. gireeshpunathil commented on Aug 14, 2018

    @gireeshpunathil
    Member

    where are you doing:
    process.env.UV_THREADPOOL_SIZE=1; in index.js ? I don't see it in your code (previous comment)

    setting the value in the command line is the right behavior, and the right way to use it - so that different runs can use different values, if need be, without changing the source.

  4. rhernandog commented on Aug 14, 2018

    @rhernandog
    Author

    Yep, in that file is not there, it is just the most reduced code sample to reproduce that.

    A simple solution is to create an NPM script:

    SET UV_THREADPOOL_SIZE=1 && node index
    

    But I was trying to actually avoid that. At the end I was just curious about why process.env.UV_THREADPOOL_SIZE returns undefined in Windows OS' before setting the value via CLI and not on OSX, because in OSX you can set the number of threads through a file. I just want to know if it's by design or not, if it's because how the specific OS works, etc. Just looking for an answer of why 😄

  5. gireeshpunathil commented on Aug 14, 2018

    @gireeshpunathil
    Member
    #uname
    Darwin
    #node
    > console.log( process.env.UV_THREADPOOL_SIZE );
    undefined
    undefined
    > 
    

    I don't see anything special with macos. If UV_THREADPOOL_SIZE is not defined in the command line (export UV_THREADPOOL_SIZE ... ) or in the source (process.env.UV_THREADPOOL_SIZE ...) it is always going to be undefined.

    I fear there is a disconnect between us. Am I missing something from your explanation?

  6. rhernandog commented on Aug 14, 2018

    @rhernandog
    Author

    No you're getting everything right, It was just I wanted to know why is undefined in one OS and not in another, just that.

  7. gireeshpunathil commented on Aug 27, 2018

    @gireeshpunathil
    Member

    ok, let us resolve this confusion.

    1. Can you run:
      console.log( process.env.UV_THREADPOOL_SIZE ); in both win and mac to see if it differs?

    2. Can you run:

    process.env.UV_THREADPOOL_SIZE = 1;
    console.log( process.env.UV_THREADPOOL_SIZE ); 

    in both and see if it dffers?

    1. Can you run:

    $ export UV_THREADPOOL_SIZE=1
    and
    console.log( process.env.UV_THREADPOOL_SIZE );

    in UNIX and
    > set UV_THREADPOOL_SIZE=1
    and
    console.log( process.env.UV_THREADPOOL_SIZE );

    in windows and see if they differ?

    In all cases I would expect they don't.

  8. gireeshpunathil commented on Jun 10, 2019

    @gireeshpunathil
    Member
  9. gireeshpunathil commented on Jun 24, 2019

    @gireeshpunathil
    Member

    inactive, closing; pls reopen if the the issue is still relevant

  10. Polyhistor commented on Nov 21, 2020

    @Polyhistor

    @gireeshpunathil the issue exists on windows. I'm currently running on windows 10 and Node v12. I've logged process.env, it's got no UV_THREADPOOL_SIZE property on it...

    The exact same behaviour exists on Ubuntu 10 and Node V10

  11. lorand-horvath commented on Oct 13, 2022

    @lorand-horvath

    Having the exact same problem on Win 7 and Node 12.22.12. By default, process.env.UV_THREADPOOL_SIZE is undefined, unless I set it from CMD with set UV_THREADPOOL_SIZE=1, for example.

    The other very strange issue that I must mention is that setting process.env.UV_THREADPOOL_SIZE = 1; in the js file doesn't have any effect on the actual number of threads. It only does if I set it via the command line, BEFORE running node index.js
    A similar report can be found here: https://stackoverflow.com/questions/68691702/process-uv-threadpool-size-size-is-not-working-in-windows

  12. gireeshpunathil commented on Oct 17, 2022

    @gireeshpunathil
    Member

    re-opening, as there are at least 2 affected parties

    @nodejs/libuv - is there anything special with UV_THREADPOOL_SIZE on windows? I couldn't find anything either in the code or in docs; yet the reports say that the value is not honoured.

  13. saghul commented on Oct 17, 2022

    @saghul
    Member
  14. 5 remaining items

  15. preveen-stack commented on Jun 22, 2023

    @preveen-stack
    Contributor

    windows 7 is past end of life. Wondering if we should track this

  16. lorand-horvath commented on Jun 22, 2023

    @lorand-horvath

    windows 7 is past end of life. Wondering if we should track this

    This also happens in Windows 10, 11 etc. So yes, it needs to be fixed.

  17. rsonaniya commented on May 3, 2024

    @rsonaniya

    I have faced the same issue and one thing I tried, opened the cmd with administrator privilage then run the file via cmd by typing node filename.js

    and surprisingly that worked for me

  18. lorand-horvath commented on May 3, 2024

    @lorand-horvath

    I have faced the same issue and one thing I tried, opened the cmd with administrator privilage then run the file via cmd by typing node filename.js

    and surprisingly that worked for me

    No, it doesn't work in Windows with Node 18.20.2 (haven't tried Node versions 20, 21, 22).
    You have probably set an environment variable in CMD before running node filename.js and then just reused the same terminal instance, e.g.:

    SET UV_THREADPOOL_SIZE=3
    node filename.js
    

    The variable will be available within filename.js when you run it again, as long as you don't close the CMD instance.

  19. github-actions commented on Oct 31, 2024

    @github-actions

    It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
    If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
    Make sure to look at the README file for the most updated links.

  20. preveen-stack commented on Nov 15, 2024

    @preveen-stack
    Contributor

    Clarification added in doc in nodejs/node#55832

  21. moshezvi commented on Jan 14, 2025

    @moshezvi

    Can confirm: Still relevant on Windows 11 64, node v22.13.0. Commenting to keep open.

  22. avivkeller commented on Mar 31, 2025

    @avivkeller
    Member

    Clarification added in doc in nodejs/node#55832

    Closing as completed. Sorry for the delay.

  23. avivkeller commented on Mar 31, 2025

    @avivkeller
    Member

    Can confirm: Still relevant on Windows 11 64, node v22.13.0. Commenting to keep open.

    If you are experiencing a similar issue, which the documentation update did not address, please open a new issue

  24. harshal255 commented on May 17, 2025

    @harshal255

    I have faced the same issue and one thing I tried, opened the cmd with administrator privilage then run the file via cmd by typing node filename.js
    and surprisingly that worked for me

    No, it doesn't work in Windows with Node 18.20.2 (haven't tried Node versions 20, 21, 22). You have probably set an environment variable in CMD before running node filename.js and then just reused the same terminal instance, e.g.:

    SET UV_THREADPOOL_SIZE=3
    node filename.js
    

    The variable will be available within filename.js when you run it again, as long as you don't close the CMD instance.

    then Do you solve this problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions