Make ThrottledIterator nonblocking#139988
Conversation
Today `ThrottledIterator` may block in `run()` while waiting for another thread to release the mutex on `iterator`, but this wait is unnecessary: if some thread is already executing `run()` then all other threads handling item completions can just release their permits and move on.
|
Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination) |
| refs.decRef(); | ||
| private void onItemRelease() { | ||
| try { | ||
| if (permits.getAndIncrement() == 0) { |
There was a problem hiding this comment.
This neatly removes the need for special recursion-detection: permits remains strictly positive until the very last line of run(), so the only way we can take this if() branch is if run() has finished its work.
|
|
||
| private void run() { | ||
| while (permits.tryAcquire()) { | ||
| do { |
There was a problem hiding this comment.
I wonder if we can assert only one thread here at a time? Might be too close to the permits though to really make sense. Ok to skip if you do not find it useful.
At least adding a comment to run() that it is run in one thread at a time only would help reading this.
There was a problem hiding this comment.
Yes 549062f asserts that permits.get() is positive within the loop, which makes sense in its own right but also implies mutual exclusion.
Today `ThrottledIterator` may block in `run()` while waiting for another thread to release the mutex on `iterator`, but this wait is unnecessary: if some thread is already executing `run()` then all other threads handling item completions can just release their permits and move on.
Today `ThrottledIterator` may block in `run()` while waiting for another thread to release the mutex on `iterator`, but this wait is unnecessary: if some thread is already executing `run()` then all other threads handling item completions can just release their permits and move on.
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in elastic#111933, but it only started failing recently. I suspect until the performance improvement in elastic#139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes elastic#143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in #111933, but it only started failing recently. I suspect until the performance improvement in #139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes #143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in elastic#111933, but it only started failing recently. I suspect until the performance improvement in elastic#139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes elastic#143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in elastic#111933, but it only started failing recently. I suspect until the performance improvement in elastic#139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes elastic#143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in #111933, but it only started failing recently. I suspect until the performance improvement in #139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes #143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in elastic#111933, but it only started failing recently. I suspect until the performance improvement in elastic#139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes elastic#143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in #111933, but it only started failing recently. I suspect until the performance improvement in #139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes #143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in #111933, but it only started failing recently. I suspect until the performance improvement in #139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes #143644
Silly test mistake: the throttle was supposed to limit the number of fragments in the queue, but was closing the throttling ref after submission rather than transmission so that the queue could grow without bound sometimes. It's been like this since the test was introduced in elastic#111933, but it only started failing recently. I suspect until the performance improvement in elastic#139988 landed it couldn't actually submit enough tasks at once to cause a failure. Closes elastic#143644
On reading this class again a few months after elastic#139988 it took some time to work this out. Adding a comment for the next person.
On reading this class again a few months after #139988 it took some time to work this out. Adding a comment for the next person.
On reading this class again a few months after elastic#139988 it took some time to work this out. Adding a comment for the next person.
Today
ThrottledIteratormay block inrun()while waiting for anotherthread to release the mutex on
iterator, but this wait is unnecessary:if some thread is already executing
run()then all other threadshandling item completions can just release their permits and move on.