We are implement memcached (memcached server run in GCE) throughout Socket API
But many problem occur .
1. We need to self implements memcached client because other java memcached client such as spymemcache , xmemcache .. using thread and other class that restriction by Google Appengine
Here is my implements http://pastebin.com/PfR9n69d
so we implement Jcache (jsr107cache) to compatible to google api
2. We hit first error is :
exception invalid stream header: ACED0000.
This error occur when we try to read object from memcached server .
It mix text and binary data , header and footer is txt while body is binary .
one appengine instance handle many request at same time , so it we read and write to memcache at same time , so data is dirty , so we need to synchronized methods such as get , put and delete
3. But now at same time one instance can call only get , put and delete . it locked by JVM
Website is too slow .
So at this time we need to create mutils Socket instance for one JVM .
we chose implement is by createCache
public Cache createCache(Map map) throws CacheException {
log.warning("cache instance count "+instacnes.size());
try {
if (instacnes.size()<20)
{
Memcached instacne = new Memcached(map);
instacnes.add(instacne);
return instacne;
}
else
{
int robin = counter++%20;
System.out.println(robin);
return instacnes.get(robin);
}
} catch (Exception e) {
log.warning("error while create cache instance "+e.getMessage());
throw new CacheException(e.getMessage());
}
}
4. Now , website is running fine . but when we turn on appstats .
why ?
here is big problem because 100+ remote_socket .Send and remote_socket.Receive will cost 1 to 2s
we use DataOutputStream writeBytes and DataInputStream readLine .
Because they read byte by byte . we need to implement batch read and write .
Change to outputstream .write (byte[])
out.write("get <key>".getBytes());
change to byte buff [] = new byte[1048576];
int byteReaded = recv.read(buff);
we use big buffer 1MB to store
