developit / greenlet

🦎 Move an async function into its own thread.
https://npm.im/greenlet
4.67k stars 100 forks source link

Create N workers (N := CPU cores) #21

Closed kurtextrem closed 6 years ago

kurtextrem commented 6 years ago

Wouldn't it be beneficial to create N workers, where N is the amount of CPU cores the system has, instead of only one?

developit commented 6 years ago

As an option maybe! Or another function that wraps Greenlet

bishwenduk029 commented 6 years ago

Hi there, I wanted to work on this issue and was just wondering that, is the requirement like there would be N workers created for N different tasks, and for N + 1 task in a round robin fashion allocate to one of the previous N's which have finished. So at a time only N workers.

Or like N workers for one task? If you could help me out with understanding context may be I can try to implement.

kurtextrem commented 6 years ago

@bishwenduk029 I leave that to @developit, however I think it's the first case as I think the most common use case is one task = one worker instead of computing something over N workers.

developit commented 6 years ago

Definitely N workers for one task, with round-robin routing. Personally I'd love to see a pool size parameter (either as a cap or initially allocated, perhaps as an option).

developit commented 6 years ago

Here's a pooling solution: https://gist.github.com/developit/65a2212731f6b00a8aaa55d70c594f5c