user1559756
user1559756

Reputation: 21

libuv library in C :Change thread pool size

I am using libuv even loop library in my C application. I am also using the thread pool utility of libuv wherein i am calling uv_queue_work() to do some work in a thread provided by the thread pool. I have 2 questions in this regard.

  1. What is the default size of the thread pool in libuv and how can i find it out.
  2. How can i change the size of the thread pool. Please let me know if it can be done by code and how.

Upvotes: 2

Views: 732

Answers (2)

Jeach
Jeach

Reputation: 9052

libuv

Another important dependency is libuv, a C library that is used to abstract non-blocking I/O operations to a consistent interface across all supported platforms. It provides mechanisms to handle file system, DNS, network, child processes, pipes, signal handling, polling and streaming.

In event-driven programming, an application expresses interest in certain events and respond to them when they occur. The responsibility of gathering events from the operating system or monitoring other sources of events is handled by libuv, and the user can register callbacks to be invoked when an event occurs. The event-loop usually keeps running forever. In pseudocode:

while there are still events to process:
    e = get the next event
    if there is a callback associated with e:
        call the callback

It also includes a thread pool for offloading work for some things that can't be done asynchronously at the operating system level.

Source: https://nodejs.org/en/docs/meta/topics/dependencies/#libuv

Source: https://nikhilm.github.io/uvbook/basics.html

Thread pool work scheduling

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 1024).

Changed in version 1.30.0: the maximum UV_THREADPOOL_SIZE allowed was increased from 128 to 1024.

Changed in version 1.45.0: threads now have an 8 MB stack instead of the (sometimes too low) platform default.

Source: http://docs.libuv.org/en/v1.x/threadpool.html

Increase Node JS Performance With Libuv Thread Pool

The recommendation is to set the UV_THREADPOOL_SIZE to the number of logical cores your machine is running. In my case I will set the thread pool size to 12.

const OS = require('os')
process.env.UV_THREADPOOL_SIZE = OS.cpus().length

Source: https://dev.to/johnjardincodes/increase-node-js-performance-with-libuv-thread-pool-5h10

Upvotes: 0

Shravan40
Shravan40

Reputation: 9908

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).

Source : Thread Pool Work Scheduling

Upvotes: 2

Related Questions