Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an OS independent way to set/get UV_THREADPOOL_SIZE #4401

Open
joy4eg opened this issue May 10, 2024 · 8 comments · May be fixed by #4415
Open

Provide an OS independent way to set/get UV_THREADPOOL_SIZE #4401

joy4eg opened this issue May 10, 2024 · 8 comments · May be fixed by #4415

Comments

@joy4eg
Copy link

joy4eg commented May 10, 2024

Currently, if you want to increase thread pool size, you need to write something like that:

static int xsetenv(const char *key, const char *value)
{
#ifdef _WIN32
	return (int)_putenv_s(key, value);
#else
	return setenv(key, value, 1);
#endif
}

void uv_set_thread_num(unsigned int n)
{
	char buf[0xFF];

	snprintf(buf, sizeof(buf), "%u", n);
	xsetenv("UV_THREADPOOL_SIZE", buf);
}

Which is not really convenient.
Instead, it would be really nice to have some low-level function that does this thing for you.
Something that you can call during early init procedure, like uv_replace_allocator().

@saghul
Copy link
Member

saghul commented May 10, 2024

Maybe uv_os_setenv ? https://docs.libuv.org/en/v1.x/misc.html#c.uv_os_setenv

@joy4eg
Copy link
Author

joy4eg commented May 10, 2024

Maybe uv_os_setenv ? https://docs.libuv.org/en/v1.x/misc.html#c.uv_os_setenv

Yeah, looks like I missed it :D

Anyway, having a native API would be still better rather than dealing with env.

@saghul
Copy link
Member

saghul commented May 10, 2024

A native API would not be very reliable really, because just setting the env var doesn't do anything if the threadpool has already been started anyway...

@joy4eg
Copy link
Author

joy4eg commented May 10, 2024

That's the point. uv_set_thread_num can return 0 if the thread pool is not running yet, and it was able to update the configuration.
If the thread pool is already running, we can return an error (<0).

@saghul
Copy link
Member

saghul commented May 10, 2024

SGTM. Ping @libuv/collaborators

@vtjnash
Copy link
Member

vtjnash commented May 10, 2024

SGRM. setenv is also thread-unsafe by design in posix, so it is good to have safe alternatives

@juanarbol
Copy link
Contributor

I can investigate on this one.

@saghul
Copy link
Member

saghul commented May 21, 2024

Go for it!

juanarbol added a commit to juanarbol/libuv that referenced this issue May 21, 2024
This call will set the threadpool size from libuv and set
`UV_THREADPOOL_SIZE` environment variable.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 21, 2024
This call will set the threadpool size from libuv and set
`UV_THREADPOOL_SIZE` environment variable.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
@juanarbol juanarbol linked a pull request May 21, 2024 that will close this issue
juanarbol added a commit to juanarbol/libuv that referenced this issue May 21, 2024
This call will set the threadpool size from libuv and set
`UV_THREADPOOL_SIZE` environment variable.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 21, 2024
This call will set the threadpool size from libuv and set
`UV_THREADPOOL_SIZE` environment variable.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 21, 2024
This call will set the threadpool size from libuv and set
`UV_THREADPOOL_SIZE` environment variable.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 21, 2024
This call will set the threadpool size from libuv and set
`UV_THREADPOOL_SIZE` environment variable.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 21, 2024
This call will set the threadpool size from libuv and set
`UV_THREADPOOL_SIZE` environment variable.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 23, 2024
This patch will allow to grow and set the thread pool size on
demand via libuv calls instead of just `UV_THREADPOOL_SIZE` but
`UV_THREADPOOL_SIZE` will remain as the initial value.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 23, 2024
This patch will allow to grow and set the thread pool size on
demand via libuv calls instead of just `UV_THREADPOOL_SIZE` but
`UV_THREADPOOL_SIZE` will remain as the initial value.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 23, 2024
This patch will allow to grow and set the thread pool size on
demand via libuv calls instead of just `UV_THREADPOOL_SIZE` but
`UV_THREADPOOL_SIZE` will remain as the initial value.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue May 23, 2024
This patch will allow to grow and set the thread pool size on
demand via libuv calls instead of just `UV_THREADPOOL_SIZE` but
`UV_THREADPOOL_SIZE` will remain as the initial value.

Fixes: libuv#4401
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants