Adam Miskiewicz
10/22/2020, 4:56 PMCoroutineScheduler
doesn’t expose any public APIs to get it’s current “state”, meaning that there’s no way to really get much insight into the state of the default dispatcher.
TL;DR — I want to figure out how to structure my application such that, when we’re saturating the CPU (and thus all the default dispatcher threads are super busy doing “stuff”), I can start to throw some back pressure and reject some requests, rather than continuing to accept hundreds/thousands of requests and causing the server to completely become unresponsive. And notably, I want to be able to cause this behavior with a mechanism that doesn’t require a ton of tuning per-service — I don’t want to do this strictly with a “request rate limit” or something like that. I’d like it to be much more adaptive, ideally.louiscad
10/22/2020, 7:02 PMAdam Miskiewicz
10/22/2020, 7:05 PMlouiscad
10/22/2020, 7:06 PMCoroutineDispatcher
wrapping Dispatchers.Default
and adding enter/exit listeners (with `try`/`finally`). With that, you could experiment with the API and its usage and report back on how it's going, so we can see if that could be a great addition or inspiration for first-party support into kotlinx.coroutinesAdam Miskiewicz
10/22/2020, 7:10 PMlouiscad
10/22/2020, 7:15 PM<http://Dispatchers.IO|Dispatchers.IO>
), or something else?Adam Miskiewicz
10/22/2020, 7:20 PMlouiscad
10/22/2020, 7:23 PMAdam Miskiewicz
10/22/2020, 7:23 PMlouiscad
10/22/2020, 7:23 PMAdam Miskiewicz
10/22/2020, 7:24 PMlouiscad
10/22/2020, 7:24 PMdelay(…)
, otherwise, it signals the work is slow, so other requests can be throttled or what needs to be done is done to avoid making the situation worse. After signaling this, the work is still allowed to run until the second timeout (mind the subtraction with first timeout if needed). If the second delay completes without being cancelled from that work completion, then it cancels the work (and also sends some signal to somewhere if needed?).Adam Miskiewicz
10/22/2020, 7:33 PMlouiscad
10/22/2020, 7:40 PMraceOf
is from my open source library #splitties, you can find it documented here: https://github.com/LouisCAD/Splitties/tree/main/modules/coroutines#racing-coroutineselizarov
10/23/2020, 7:37 AMJilles van Gurp
10/23/2020, 9:48 AMkenkyee
10/23/2020, 11:17 AMAdam Miskiewicz
10/23/2020, 4:29 PM