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

Expose cpuCount #108

Closed
wants to merge 1 commit into from
Closed

Expose cpuCount #108

wants to merge 1 commit into from

Conversation

slorber
Copy link

@slorber slorber commented Jan 27, 2025

This lib computes physical CPUs for pool default values, but this computed value is not exposed.

Exposing it gives the possibility for the user to create more advanced algorithms to define the appropriate number of threads.

I'm not sure what name to use for the export, just wanted to open the discussion that I'd like to access that value.

Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's the use case here. I think users should rather check their host environment and pass the minThreads and maxThreads options to Tinypool. They can use any custom logic they want to compute values for those options.

@slorber
Copy link
Author

slorber commented Feb 7, 2025

Agree, this was before I knew about os.availableParallelism() and how you use it in Vitest:

https://github.com/vitest-dev/vitest/blob/b997355be71220c098563b1a60056eb57f4d4d90/packages/vitest/src/node/pools/threads.ts#L46-L71

  const numCpus
    = typeof nodeos.availableParallelism === 'function'
      ? nodeos.availableParallelism()
      : nodeos.cpus().length

I wanted it to be exposed because I didn't know availableParallelism(). Now I wonder what prevents you to use this API instead of this logic: https://github.com/tinylibs/tinypool/blob/main/src/physicalCpuCount.ts

I guess it requires a breaking change, bumping the Node version.

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 this pull request may close these issues.

2 participants