-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENHANCE: Create hashUpdateThreadPool to decrease IO thread overhead.
- Loading branch information
Showing
4 changed files
with
67 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.spy.memcached; | ||
|
||
|
||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
|
||
public class CacheListUpdateTask implements Callable<Boolean> { | ||
|
||
private final MemcachedConnection memcachedConnection; | ||
private final List<MemcachedNode> attachNodes; | ||
private final List<MemcachedNode> removeNodes; | ||
|
||
public CacheListUpdateTask(MemcachedConnection memcachedConnection, | ||
List<MemcachedNode> attachNodes, | ||
List<MemcachedNode> removeNodes) { | ||
|
||
this.memcachedConnection = memcachedConnection; | ||
this.attachNodes = attachNodes; | ||
this.removeNodes = removeNodes; | ||
} | ||
|
||
@Override | ||
public Boolean call() throws Exception { | ||
memcachedConnection.getLocator().update(attachNodes, removeNodes); | ||
|
||
// Remove the unavailable nodes. | ||
memcachedConnection.handleNodesToRemove(removeNodes); | ||
return true; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/net/spy/memcached/HashRingUpdateService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.spy.memcached; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class HashRingUpdateService { | ||
private final ExecutorService pool; | ||
|
||
public HashRingUpdateService() { | ||
pool = Executors.newSingleThreadExecutor(); | ||
} | ||
|
||
public Boolean updateHashes(CacheListUpdateTask task) { | ||
Boolean res = null; | ||
try { | ||
res = pool.submit(task).get(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return res; | ||
} | ||
|
||
public void shutdown() { | ||
pool.shutdown(); | ||
} | ||
} |
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
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