typelevel / keypool

A Keyed Pool Implementation for Scala
MIT License
34 stars 15 forks source link

Implement fairness #559

Closed rossabaker closed 1 month ago

rossabaker commented 3 months ago

commons-pool2 functionality

In commons-pool2, [fairness]( https://javadoc.io/doc/org.apache.commons/commons-pool2/latest/org/apache/commons/pool2/impl/BaseGenericObjectPool.html#getFairness()) determines whether requests are serviced in FIFO or LIFO order. The default is LIFO.

Current behavior

keypool only supports FIFO.

Analysis

This is a configuration for good reason. A nice visualization of the tradeoffs is in this queueing article.

The semaphore that lurks within Keypool effectively imposes FIFO ordering. Fixing this would effectively require Keypool reimplement some semaphore-like semantics.

Notably, in the feature comparison, keypool stands alone with its FIFO default.

Workarounds

None

rossabaker commented 3 months ago

One can also imagine a priority queue here, but that would require an enhanced borrow interface that accepted a priority as an argument.