Repository navigation
Conversation
snaury
left a comment
There was a problem hiding this comment.
LGTM, but I'm not part of YDB at the moment.
| // close() can run after the count is reserved but before this offer. | ||
| // In that case clear() cannot see the new entry, so clean it here. | ||
| if (stopped && waitingAcquires.remove(acquire)) { | ||
| waitingAcqueireCount.decrementAndGet(); |
There was a problem hiding this comment.
Maybe fix a typo? waitingAcqueireCount -> waitingAcquireAcount.
There was a problem hiding this comment.
Thanks for catching this! Fixed.
| } | ||
|
|
||
| waitingAcquires.offer(acquire); // ConcurrentLinkedQueue always return true | ||
| acquire.whenComplete((ignored, th) -> removeWaitingAcquire(acquire)); |
There was a problem hiding this comment.
To be honest I'm a little worried that this call happens in all cases, both when the call is cancelled and when successful. In the case of success, since the future is removed immediately before completion, this operation is always O(n) on the number of awaiters, with potentially very expensive worst-case walk over the concurrent list, since the future is guaranteed to not be in the list. The total complexity grows quadratically, and completing 1000 awaiters will take on the order of 1 million operations. Historically things like that were enough to cause clients problems in production, even with modest spikes in concurrent requests.
Ideally this should be amortized somehow. At the minimum awaiters which are already dequeued shouldn't incur this cost at all when completing. Would be best if this cost is never quadratic, because a spike in concurrent requests with many such requests cancelled at roughly the same time is also very much possible to cause problems. I'm not sure how to solve the latter with standard java ConcurrentLinkedDeque though.
Changes
WaitingQueueTest.canceledWaitingTestto assert the intentional behavior change: a cancelled waiter now frees its waiting slot immediately, rather than remaining counted until the next session release.Metrics
ydb.table.session.acquire_timeandydb.query.session.acquire_timehistograms, recorded in seconds for completed acquire attempts.ydb.table.session.acquire_failuresandydb.query.session.acquire_failurescounters. Theydb.table.session.reasonandydb.query.session.reasonattributes use the bounded valuestimeout,cancelled,rejected, andother.0.4.0.Tests
Performance note
Removing a cancelled waiter from
ConcurrentLinkedDequeis linear in the queue length.Fixes #794