public
Description: A simple, asynchronous, single-threaded memcached client written in java.
Homepage: http://code.google.com/p/spymemcached/
Clone URL: git://github.com/dustin/java-memcached-client.git
Allow the input, op read and op write queues to be individually specified.

By default, the read queue is 10% larger than the input queue.

With a sufficiently large op read queue, it's possible to never
internally overflow, but correct values are likely
application-specific.
dustin (author)
Wed May 14 09:28:35 -0700 2008
commit  3d806bac909790a0fee4c655a5d005ecd30d464a
tree    1a962e56e4b4c20821286a2280e919aa1e648e0f
parent  9de48599d5a18cb5d59779e7c28713b517285aa4
...
41
42
43
44
45
 
 
46
47
48
...
41
42
43
 
 
44
45
46
47
48
0
@@ -41,8 +41,8 @@ public class BinaryConnectionFactory extends DefaultConnectionFactory {
0
   public MemcachedNode createMemcachedNode(SocketAddress sa,
0
       SocketChannel c, int bufSize) {
0
     return new BinaryMemcachedNodeImpl(sa, c, bufSize,
0
-      createOperationQueue(),
0
-      createOperationQueue(),
0
+      createReadOperationQueue(),
0
+      createWriteOperationQueue(),
0
       createOperationQueue());
0
   }
0
 
...
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
40
41
42
...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -37,6 +37,19 @@ public interface ConnectionFactory {
0
   BlockingQueue<Operation> createOperationQueue();
0
 
0
   /**
0
+   * Create a BlockingQueue for the operations currently expecting to read
0
+   * responses from memcached.
0
+   */
0
+  BlockingQueue<Operation> createReadOperationQueue();
0
+
0
+  /**
0
+   * Create a BlockingQueue for the operations currently expecting to write
0
+   * requests to memcached.
0
+   */
0
+  BlockingQueue<Operation> createWriteOperationQueue();
0
+
0
+
0
+  /**
0
    * Create a NodeLocator instance for the given list of nodes.
0
    */
0
   NodeLocator createLocator(List<MemcachedNode> nodes);
...
18
19
20
21
 
 
 
22
23
24
...
76
77
78
79
80
 
 
81
82
83
...
97
98
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
101
102
...
18
19
20
 
21
22
23
24
25
26
...
78
79
80
 
 
81
82
83
84
85
...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
0
@@ -18,7 +18,9 @@ import net.spy.memcached.protocol.ascii.AsciiOperationFactory;
0
  *
0
  * <p>
0
  * This implementation creates connections where each server worker queue is
0
- * implemented using an ArrayBlockingQueue.
0
+ * implemented using an ArrayBlockingQueue.  The read queue is automatically
0
+ * configured to be 10% larger than the specified op queue.  The write queue
0
+ * is and input queues are the same size.
0
  * </p>
0
  */
0
 public class DefaultConnectionFactory extends SpyObject
0
@@ -76,8 +78,8 @@ public class DefaultConnectionFactory extends SpyObject
0
   public MemcachedNode createMemcachedNode(SocketAddress sa,
0
       SocketChannel c, int bufSize) {
0
     return new AsciiMemcachedNodeImpl(sa, c, bufSize,
0
-        createOperationQueue(),
0
-        createOperationQueue(),
0
+        createReadOperationQueue(),
0
+        createWriteOperationQueue(),
0
         createOperationQueue());
0
   }
0
 
0
@@ -97,6 +99,21 @@ public class DefaultConnectionFactory extends SpyObject
0
   }
0
 
0
   /* (non-Javadoc)
0
+   * @see net.spy.memcached.ConnectionFactory#createReadOperationQueue()
0
+   */
0
+  public BlockingQueue<Operation> createReadOperationQueue() {
0
+    return new ArrayBlockingQueue<Operation>(
0
+      (int) (getOpQueueLen() * 1.1));
0
+  }
0
+
0
+  /* (non-Javadoc)
0
+   * @see net.spy.memcached.ConnectionFactory#createWriteOperationQueue()
0
+   */
0
+  public BlockingQueue<Operation> createWriteOperationQueue() {
0
+    return createOperationQueue();
0
+  }
0
+
0
+  /* (non-Javadoc)
0
    * @see net.spy.memcached.ConnectionFactory#createLocator(java.util.List)
0
    */
0
   public NodeLocator createLocator(List<MemcachedNode> nodes) {
...
20
21
22
 
 
 
 
 
 
 
23
...
20
21
22
23
24
25
26
27
28
29
30
0
@@ -20,4 +20,11 @@ public class ConnectionFactoryTest extends TestCase {
0
   public void testBinaryAnIntAnotherIntAndAHashAlgorithmCons() {
0
     new BinaryConnectionFactory(5, 5, HashAlgorithm.FNV1_64_HASH);
0
   }
0
+
0
+  public void testQueueSizes() {
0
+    ConnectionFactory cf=new DefaultConnectionFactory(100, 1024);
0
+    assertEquals(100, cf.createOperationQueue().remainingCapacity());
0
+    assertEquals(100, cf.createWriteOperationQueue().remainingCapacity());
0
+    assertEquals(110, cf.createReadOperationQueue().remainingCapacity());
0
+  }
0
 }

Comments