-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid acquiring closeLock.readLock() on every add/read operation
In the `BookieClient`, we are always acquiring a readlock when grabbing a connection to use for sending a write/read request. The lock is the `closeLock` and it's only acquired in "write" mode when the `BookKeeper` instance is closed. The problem with the read-lock is that it introduces contention between the threads that are acquiring it (even if all of them in read mode). Multiple threads can be be in read mode in the critical section, though they have contention when they're entering/exiting the section. Additionally, the Java implementation of read/write lock is creating and destroying a lot of objects when that contention happens. My understanding of the code is that we don't need to acquire the read lock in that point. The reason is that, we are already acquiring the lock in the `lookupClient()` method, although only if the pool is null. Additionally, when `Bookkeeper.close()` is invoked all PCBC will be set to closed as well, so it will not be possibile to create a new connection. All the line changes in the patch are just removing the readLock acquire and try/finally, and reducing the indentation level. Author: Matteo Merli <mmerli@apache.org> Reviewers: Ivan Kelly <ivank@apache.org>, Enrico Olivelli <eolivelli@gmail.com>, Jia Zhai <None>, Sijie Guo <sijie@apache.org> This closes #1292 from merlimat/bookie-client-rw-lock and squashes the following commits: 2104a3a [Matteo Merli] Converted anonymous classes into lambdas cabad14 [Matteo Merli] Avoid acquiring closeLock.readLock() on every add/read operation
- Loading branch information
Showing
1 changed file
with
104 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters