Xudong-Huang / may

rust stackful coroutine library
Apache License 2.0
1.96k stars 83 forks source link

What is the difference between I/O workers, workers, and pool capacity? #62

Closed hirrolot closed 5 years ago

hirrolot commented 5 years ago

I see three methods on the Config type: set_io_workers, set_workers, and set_pool_capacity.

What is the difference between them and what do they mean?

Xudong-Huang commented 5 years ago

we have too kind of threads that are running the scheduler of coroutines. one kind is for only IO APIs e.g. TCP/UDP stream one kind is for timer/sync primitives API e.g. Mutex, Sleep

so the APIs are used to set the thread number of the corresponding schedulers.

you can ref https://xudong-huang.github.io/stackful_coroutine_story.html#/ about the arch

set_pool_capacity is an optimization when you create/destroy coroutines. the underlying coroutine stack memory could be reused. so you don't have to alloc and free the stack whenever you create a coroutine. there is pool that manage the resources. When you set the pool size to 1000, the first 1000 coroutine will not alloc stack from sysmem, but reuse from the pool.

hirrolot commented 5 years ago

Thanks