-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use limited parallelism to prevent thread starvation
`Dispatchers.IO` has a default thread limit of 64. This can lead to thread starvation resulting in deadlocks, if more than 64 coroutines doing blocking calls are running in parallel. Exceeding this limit can also negatively impact performance if no blocking calls are involved. To fix this, use `limitedParallelism` [1] to limit the amount of coroutines running at the same time, and to make use of the elasticity feature of `Dispatchers.IO` [2]. This commit applies a conservative limit of 20 to places where `Dispatchers.IO` is used and many parallel coroutines are started. This value can later be adjusted if it has negative impact on performance. [1]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/limited-parallelism.html [2]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html Signed-off-by: Martin Nonnenmacher <[email protected]>
- Loading branch information
1 parent
1d0805f
commit 23c9bb0
Showing
6 changed files
with
9 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters