Motivation
An extension of #87 where other criteria than Least|Most-Recently-Used would be possible for polling order of idle resources (ie. created oldest).
The Priority Queue opens up more usages since a Comparator<PooledRef> can be used. For instance, one could prioritize youngest/oldest resources (in terms of creation time, independently of when it was last released) or by number of acquisitions. As long as the "priority" is not changing after insertion.
This implies:
- Adding accessors for the
PooledRef release timestamp (and creation timestamp): as "age" is a function of time and so is too dynamic for a priority => a timestamp is more absolute
- Possible performance loss: the
PriorityQueue interface relying on Comparator, implementations may be less efficient than simple baked-in fifo/lifo in Deque implementations
At the same time, it would better support maintaining order when polling-and-reinserting, which could help recover from some CAS failures.
Desired solution
An efficient Priority Queue implementation would be necessary, but the JDK only provides a binary-heap implementation that is not thread-safe (PriorityQueue) or a thread safe version that relies heavily on blocking/locks (PriorityBlockingQueue).
Considered alternatives
Implement one of the papers below.
Additional context
To our knowledge, no efficient lock-free implementation of Priority Queue exist in Java.
For reference, here are a few recent papers on concurrent priority queues:
- "A Practical, Scalable, Relaxed Priority Queue." or ZMSQ (T Zhou, M Michael, M Spear - 2019)
- "CBPQ: High Performance Lock-Free Priority Queue." (Braginsky A, Cohen N, Petrank E. - 2016)
- "The spraylist: A scalable relaxed priority queue." (Alistarh, Dan, et al. - 2015)
- "A skiplist-based concurrent priority queue with minimal memory contention." (Lindén, Jonatan, and Bengt Jonsson - 2013)
Motivation
An extension of #87 where other criteria than Least|Most-Recently-Used would be possible for polling order of idle resources (ie. created oldest).
The Priority Queue opens up more usages since a
Comparator<PooledRef>can be used. For instance, one could prioritize youngest/oldest resources (in terms of creation time, independently of when it was last released) or by number of acquisitions. As long as the "priority" is not changing after insertion.This implies:
PooledRefrelease timestamp (and creation timestamp): as "age" is a function of time and so is too dynamic for a priority => a timestamp is more absolutePriorityQueueinterface relying onComparator, implementations may be less efficient than simple baked-in fifo/lifo inDequeimplementationsAt the same time, it would better support maintaining order when polling-and-reinserting, which could help recover from some CAS failures.
Desired solution
An efficient Priority Queue implementation would be necessary, but the JDK only provides a binary-heap implementation that is not thread-safe (
PriorityQueue) or a thread safe version that relies heavily on blocking/locks (PriorityBlockingQueue).Considered alternatives
Implement one of the papers below.
Additional context
To our knowledge, no efficient lock-free implementation of Priority Queue exist in Java.
For reference, here are a few recent papers on concurrent priority queues: