Join Slack
Powered by
But I could just offload the CPU bound work to a b...
# ktor
m
Marc Knaup
10/01/2018, 9:45 PM
But I could just offload the CPU bound work to a background thread and prevent the OTHER coroutines from being blocked, couldn't I?
e
elizarov
10/02/2018, 6:27 AM
Other coroutines will not be blocked. They (usually) run on a thread pool
m
Marc Knaup
10/02/2018, 8:50 AM
I don't know for sure about ktor though. Isn't that internal to ktor? If it uses a thread pool, does it use it's own one? What's the thread limit?
e
elizarov
10/02/2018, 8:52 AM
It is configurable. # of CPU cores by default, so it is designed for CPU-bound tasks.
m
Marc Knaup
10/02/2018, 8:56 AM
So if I have 4 cores and just 4 requests are CPU bound and take a while, no further requests can be handled even if they are very lightweight?
e
elizarov
10/02/2018, 9:21 AM
You are not supposed
to block
those threads. If all your code is async, you can handle tens of thousands of concurrent requests
elizarov
10/02/2018, 9:22 AM
If you have code that blocks thread, then you should consider moving
that particular code
to a dedicated thread-pool using
withContext(myPool) { ... }
2
Views
Open in Slack
Previous
Next