You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/03/14 19:11:18 UTC

[bookkeeper] branch master updated: Replaced synchronized with volatile read in BookieStatus

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new e600852  Replaced synchronized with volatile read in BookieStatus
e600852 is described below

commit e60085286f48c73ec779e45c84b4a76b2dc2da38
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Wed Mar 14 12:11:11 2018 -0700

    Replaced synchronized with volatile read in BookieStatus
    
    `BookieStatus.isInReadOnlyMode()` is being called from IO threads at each write request.
    
    Having `synchronized` method is a major source of contention between all these threads and caps the throughput and increases the latency.
    
    Replacing here with a `volatile` variable read. This will have the same exact behavior as today while removing the contention point.
    
    I think we could eventually even do a "dirty" read of that variable to further reduce the overhead of the volatile read.
    
    Author: Matteo Merli <mm...@apache.org>
    
    Reviewers: Ivan Kelly <iv...@apache.org>, Enrico Olivelli <eo...@gmail.com>, Sijie Guo <si...@apache.org>
    
    This closes #1259 from merlimat/bookie-status-contention
---
 .../src/main/java/org/apache/bookkeeper/bookie/BookieStatus.java  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStatus.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStatus.java
index cb28639..7c702da 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStatus.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStatus.java
@@ -52,7 +52,7 @@ public class BookieStatus {
 
     private int layoutVersion;
     private long lastUpdateTime;
-    private BookieMode bookieMode;
+    private volatile BookieMode bookieMode;
 
 
     BookieStatus() {
@@ -61,11 +61,11 @@ public class BookieStatus {
         this.lastUpdateTime = INVALID_UPDATE_TIME;
     }
 
-    private synchronized BookieMode getBookieMode() {
+    private BookieMode getBookieMode() {
         return bookieMode;
     }
 
-    public synchronized boolean isInWritable() {
+    public boolean isInWritable() {
         return bookieMode.equals(BookieMode.READ_WRITE);
     }
 
@@ -78,7 +78,7 @@ public class BookieStatus {
         return false;
     }
 
-    synchronized boolean isInReadOnlyMode() {
+    boolean isInReadOnlyMode() {
         return bookieMode.equals(BookieMode.READ_ONLY);
     }
 

-- 
To stop receiving notification emails like this one, please contact
sijie@apache.org.