Open birkmose opened 2 years ago
The pool used to be unfair, and that had problems too: https://github.com/smol-rs/async-channel/issues/6
Unfairness definitely comes with its own problems. The point I was making, was that for some setups/workloads optimizing for throughput is preferred. I think it makes a lot of sense to have the default setting for the pool as fair, but I feel it would still make sense to give consumers of the pool, the option to configure it for unfairness if it suits their needs? (I.e make that option public, documented, and not hidden).
Is your feature request related to a problem? Please describe. Currently,
PoolOptions::__fair
is hidden in the docs, and according to the comments in the code:However, using sqlx on configurations without work-stealing - the first-come-first-serve order can be detrimental to throughput. In my use case (sqlx on
actix-web
), I observed a large increase in throughput (3x) during heavy load with a large number of concurrent clients, whenfair
is set tofalse
.Describe the solution you'd like For some workloads
fair = true
, is actually better if throughput is more important than fairness. It would be nice if thefair
option could be made part of the public API.Additional context I tried to create an example that illustrates this issue - the example is a bit "extreme/worst-case scenario", but it illustrated my point (I hope). The idea is basically to have two single-threaded tokio runtimes, doing a large number of concurrent requests on each runtime. One runtime is extremely CPU-bound (to illustrate a non-uniform workload), and the other runtime is purely I/O bound.
With
fair=true
we can observe how the runtime that has an extremely CPU-bound workload, will starve the purely I/O-bound runtime:With
fair=false
we observe a large increase in throughput (in real-life scenarios the difference is of course a lot less, but I did observe a 3x increase in throughput for my workload):The example code: