New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scheduling capabilities to EnhancedQueueExecutor
#111
Conversation
Thanks @dmlloyd I'll be watching this 👍 |
You can take look at hashed timing wheel to track scheduled tasks efficiently eg https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/HashedWheelTimer.java |
I did think of this implementation, and pondered some potential modifications of it. At the moment I am considering precise timing to be more important than throughput, but that's just my initial assumption; we'll have to see what kind of usage pattern there is. It could potentially be made configurable. |
Out of curiosity, what are your goals for this implementation? Which trade-offs we're making against other implementations, and use-cases that are/aren't in scope. |
The primary motivation is to avoid having to maintain a separate scheduled thread pool executor for Quarkus. My initial design points are:
|
f4dfcf1
to
67d330a
Compare
I think I'm also going to explore a simple array-backed double-ended queue with random-access insert and remove (the latter to support cancellation, potentially). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great from the Mutiny perspective 👍
Of course, GitHub Actions is having problems now. Well, I'll come back to this later once CI completes. |
This is an initial prototype with the following features:
EnhancedQueueExecutor
to implementScheduledExecutorService
directlyThe scheduled work queue is a simple sorted[UPDATE: Just using aArrayList
(I expect this to perform substantially better than e.g.TreeSet
up to a certain size... but I don't know what size that might be)TreeSet
for now, until a more optimal array-based structure can be thoroughly vetted]Task
structure to capture the calling context and also to avoid creating more wrapper objects than strictly necessaryUses thread monitor[UPDATE: Now usingwait
/notify
which may only have millisecond resolution on some JDKsReentrantLock
for the main queue; for theFuture
itself it doesn't matter as much]Delayed
interface with any other implementationsTasks with same execution time compare to[UPDATE: Each task now has a uniquifying sequence number]0
Manually tested some basic cases[UPDATE: There are unit tests now]I want to pursue (at a minimum) the following before finalizing the PR:
ArrayList
to e.g.TreeSet
(or something better that is still no worse thanO(log n)
for insertions andO(log n)
for head removals) once it reaches a certain sizeArrayList
to a logical fraction of the "certain size" so that it resizes exactly zero, one, or two times before switching to an alternative data structureReentrantLock
/Condition
for the work queue so that tasks can wait with higher resolution than millisecond