nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.47k stars 280 forks source link

Some UV_THREADPOOL_SIZE count does not affect zlib.gzip method performance #4290

Closed jeongsik-woo closed 3 months ago

jeongsik-woo commented 10 months ago

Details

When I run zlib.gzip, I expect the gzip to be handled by threads in a UV_THREADPOOL with the number of threads set by UV_THREADPOOL_SIZE.

So, I thought that increasing the UV_THREADPOOL_SIZE would naturally result in more threads running concurrently, which would improve performance, but this was not the case.

I experimented with UV_THREADPOOL_SIZE values of 4, 8, 16 and 32. The modification from 4 to 8 resulted in a nearly 2x performance increase, while the modification from 8 to 16 resulted in almost no performance difference. I thought that setting UV_THREADPOOL_SIZE to 16 would make the job faster by having 16 UV_THREADs running at the same time to do 32 gzips, but it didn't.

Do you have any idea why?

test results is below.

UV_THREADPOOL_SIZE 32
3531

UV_THREADPOOL_SIZE 16
3615

UV_THREADPOOL_SIZE 8
3634

UV_THREADPOOL_SIZE 4
5185

Node.js version

v18.17.0

Example code

const zlib = require('zlib');
const jsonData = require('./large-file.json'); // large size file. 28MB byte.

console.log('UV_THREADPOOL_SIZE', process.env.UV_THREADPOOL_SIZE);

const stringData = JSON.stringify(jsonData);

const length = 32;
const result = [];
const begin = new Date();
let end = null;
for (let i = 1; i <= length; i++) {
  zlib.gzip(stringData, {level: 9}, () => {
    result.push(1);
    if (result.length === length) {
      end = new Date();
    }
  });
}

setTimeout(() => {
    console.log(end.getTime() - begin.getTime());

}, 1000 * 120);

Operating system

Darwin 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:22 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T6000 arm64

Scope

runtime

Module and version

Not applicable.

jeongsik-woo commented 10 months ago

large size file exmple: https://github.com/json-iterator/test-data/blob/master/large-file.json

preveen-stack commented 10 months ago

cc @nodejs/libuv

github-actions[bot] commented 4 months ago

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.

github-actions[bot] commented 3 months ago

It seems there has been no activity on this issue for a while, and it is being closed. 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.