Memcached Java client lock contention improvement

Jiazi Yu yujiazi at gmail.com
Tue Aug 21 06:51:42 UTC 2007


Skipped content of type multipart/alternative-------------- next part --------------
--- memcache_java/src/com/danga/MemCached/MemCachedClient.java	2007-08-07 17:09:17.000000000 +0800
+++ popo6/devel/server/Common/src/com/danga/MemCached/MemCachedClient.java	2007-08-07 16:51:24.000000000 +0800
@@ -199,11 +199,15 @@
 	// which pool to use
 	private String poolName;
 
+	// pool instance
+	private SockIOPool poolInstance = null;
+	
 	// optional passed in classloader
 	private ClassLoader classLoader;
 
 	// optional error handler
 	private ErrorHandler errorHandler;
+	
 
 	/**
 	 * Creates a new instance of MemCachedClient.
@@ -249,6 +253,7 @@
 		this.compressThreshold  = COMPRESS_THRESH;
 		this.defaultEncoding    = "UTF-8";
 		this.poolName           = "default";
+		this.poolInstance       = SockIOPool.getInstance(this.poolName);
 	}
 
 	/** 
@@ -278,6 +283,7 @@
 	 */
 	public void setPoolName( String poolName ) {
 		this.poolName = poolName;
+		this.poolInstance = SockIOPool.getInstance(poolName);
 	}
 
 	/** 
@@ -405,7 +411,7 @@
 		}
 
 		// get SockIO obj from hash or from key
-		SockIOPool.SockIO sock = SockIOPool.getInstance( poolName ).getSock( key, hashCode );
+		SockIOPool.SockIO sock = poolInstance.getSock( key, hashCode );
 
 		// return false if unable to get SockIO obj
 		if ( sock == null )
@@ -656,7 +662,7 @@
 		}
 
 		// get SockIO obj
-		SockIOPool.SockIO sock = SockIOPool.getInstance( poolName ).getSock( key, hashCode );
+		SockIOPool.SockIO sock = poolInstance.getSock( key, hashCode );
 		
 		if ( sock == null )
 			return false;
@@ -1076,7 +1082,7 @@
 		}
 
 		// get SockIO obj for given cache key
-		SockIOPool.SockIO sock = SockIOPool.getInstance( poolName ).getSock(key, hashCode);
+		SockIOPool.SockIO sock = poolInstance.getSock(key, hashCode);
 
 		if ( sock == null )
 			return -1;
@@ -1208,7 +1214,7 @@
 		}
 
 		// get SockIO obj using cache key
-		SockIOPool.SockIO sock = SockIOPool.getInstance( poolName ).getSock( key, hashCode );
+		SockIOPool.SockIO sock = poolInstance.getSock( key, hashCode );
 	    
 	    if ( sock == null )
 			return null;
@@ -1393,7 +1399,7 @@
 			}
 
 			// get SockIO obj from cache key
-			SockIOPool.SockIO sock = SockIOPool.getInstance( poolName ).getSock( key, hash );
+			SockIOPool.SockIO sock = poolInstance.getSock( key, hash );
 
 			if ( sock == null )
 				continue;
@@ -1462,8 +1468,7 @@
 		for ( Iterator<String> i = cmdMap.keySet().iterator(); i.hasNext(); ) {
 
 			String host = i.next();
-			SockIOPool.SockIO sock =
-				SockIOPool.getInstance( poolName ).getConnection( host );
+			SockIOPool.SockIO sock = poolInstance.getConnection( host );
 
 			try {
 				// get a selector
@@ -1839,7 +1844,7 @@
 	public boolean flushAll( String[] servers ) {
 
 		// get SockIOPool instance
-		SockIOPool pool = SockIOPool.getInstance( poolName );
+		SockIOPool pool = poolInstance;
 
 		// return false if unable to get SockIO obj
 		if ( pool == null ) {
@@ -2028,7 +2033,7 @@
 		}
 
 		// get SockIOPool instance
-		SockIOPool pool = SockIOPool.getInstance( poolName );
+		SockIOPool pool = poolInstance;
 
 		// return false if unable to get SockIO obj
 		if ( pool == null ) {


More information about the memcached mailing list