Implement spawn_blocking [monoio] - TagMerge

Implement spawn_blocking [monoio]

ihciahAsked 5 months ago

Is your feature request related to a problem? Please describe. We need spawn_blocking like tokio, or the latency will be very big if users do heavy calculation.

Describe the solution you'd like Implement with an thread pool.

Describe alternatives you've considered Maybe users can do "spawn" by themselves since they can do across-thread communication.

Additional context Nop.

Source: link

SSeboAnswered 5 months ago

How about port the tokio implementation ?

ihciahAnswered 5 months ago

How about port the tokio implementation ?

I will consider that. But there's another way to provide spawn_blocking abaility by providing a pool and let user create it by themselves.

How do you think these two solution?

SSeboAnswered 5 months ago

I will consider that. But there's another way to provide spawn_blocking abaility by providing a pool and let user create it by themselves.

How do you think these two solution?

There are two common reasons for blocking:

  • Expensive CPU-bound computation. ( should use rayon )
  • synchronous IO
    • Limited synchronous IO . ( should use thread pool )
    • Unlimited synchronous IO. ( should spawn a dedicated thread )

Even though we provide a thread pool, we can not fit all needs. monoio is focusing on async, so it's a good idea to leave thread pool detail to user. monoio may give some advice.

But there is no de facto standard thread pool crate like rayon for CPU-bounded computation. Maybe tokio can not find one so just implemented one? async-std still not stabilize their spawn_blocking

Recent Issues

    Programming Languages