gwhalin/Memcached-Java-Client — Issue #41: About the big data operation using memcached-java-client!!help me out!!
Author: rainmanzh
Created: 2012-03-05 15:04:11+00:00
State: open

We use memcached-java-client as one of our memcached client in our project.we found that when we operation big data some thing goes wrong:

[2012-03-05 22:58:29.872]-[ERROR] com.danga.MemCached.MemCachedClient ++++ exception thrown while writing bytes to server on get
[2012-03-05 22:58:29.874]-[ERROR] com.danga.MemCached.MemCachedClient An existing connection was forcibly closed by the remote host
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:69)
at sun.nio.ch.IOUtil.write(IOUtil.java:26)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
at com.schooner.MemCached.SchoonerSockIOPool$TCPSockIO.flush(SchoonerSockIOPool.java:1547)
at com.schooner.MemCached.BinaryClient.get(BinaryClient.java:1482)
at com.schooner.MemCached.BinaryClient.get(BinaryClient.java:738)
at com.schooner.MemCached.BinaryClient.get(BinaryClient.java:734)
at com.danga.MemCached.MemCachedClient.get(MemCachedClient.java:917)
at com.eshore.crm.memcache.client.SimpleTest$1.run(SimpleTest.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
null

Test code:
memcached server:
/usr/local/bin/memcached -d -m 4096m -u mem -vv -p 11212 -I 10m

client test:

import java.util.UUID;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;

public class SimpleTest {

// create a static client as most installs only need
// a single instance
protected static MemCachedClient mcc;

// set up connection pool once at class load
static {

// server list and weights
String[] servers = { "10.17.13.49:11212" };

Integer[] weights = { 3, 3, 2 };

// grab an instance of our connection pool
SockIOPool pool = SockIOPool.getInstance();

// set the servers and the weights
pool.setServers(servers);
pool.setWeights(weights);

// set some basic pool settings
// 5 initial, 5 min, and 250 max conns
// and set the max idle time for a conn
// to 6 hours
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(250);
pool.setMaxIdle(1000 * 60 * 60 * 6);

// set the sleep for the maint thread
// it will wake up every x seconds and
// maintain the pool size
pool.setMaintSleep(30);

// set some TCP settings
// disable nagle
// set the read timeout to 3 secs
// and don’t set a connect timeout
pool.setNagle(false);
pool.setSocketTO(3000);
pool.setSocketConnectTO(0);

pool.setBufferSize(30000000);

// initialize the connection pool
pool.initialize();

// lets set some compression on for the client
// compress anything larger than 64k
//mcc.setCompressEnable(true);
//mcc.setCompressThreshold(64 * 1024);
mcc = new MemCachedClient(true);
}

public static void main(String args[]){
int k=1;
String[] values= new String[8000];
int j = 0;
for (int i = 0; i < keys.length; i++) {
keys[j] = "3";
j++;
}
BlockingQueue startStopQueue = new LinkedBlockingQueue();
ThreadPoolExecutor taskExecutor = new ThreadPoolExecutor(10,
10, 10, TimeUnit.SECONDS,
startStopQueue);
taskExecutor.allowCoreThreadTimeOut(true);
final String[] vs=values;
final MemCachedClient mc = mcc;
while(k>0){
//mcc.delete("foo");
taskExecutor.submit(new Runnable(){

@Override
public void run() {
//mcc = new MemCachedClient(true);
String key = "foo"+UUID.randomUUID();
mcc.set(key, vs);
Object obj = mcc.get(key);
System.out.println(obj);
}

});
try {
TimeUnit.MICROSECONDS.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
k--;
}

taskExecutor.shutdown();
while(!taskExecutor.isTerminated()){
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.exit(1);
}
}
----------------
when I change the values size to 1000 the error won't happend.did something wrong with my code or config .please help me out !!