socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.12k stars 86 forks source link

Dynamic concurrency limiter / adaptive semaphore #277

Closed joeldrapper closed 7 months ago

joeldrapper commented 1 year ago

๐Ÿ‘‹ Just opening an issue here after our discussion on Mastodon about creating a dynamic concurrency limiter or "adaptive semaphore" based on available resources.

The idea is it would keep spawning fibres until it detects saturation of available resources.

joeldrapper commented 1 year ago

I wonder if it might also make sense to have some target max-real-time per task so that it doesn't oversaturate other resources. For example, if you're making concurrent HTTP requests and there is enough CPU and memory to saturate the internet connection, I believe you could eventually run into HTTP timeouts.

joeldrapper commented 1 year ago

@ioquatix we discussed potentially having the event loop schedule only one task per iteration so as the event loop slows, fewer tasks are scheduled.

Can you point me in the right direction to build something like this? I donโ€™t quite understand where that would hook in. It looks like the event loop isn't even in this library and comes from io-event instead.

ioquatix commented 7 months ago

I have a working PoC: https://github.com/socketry/async/pull/309

I'm planning on merging and releasing this soon.