MemcachedBench
/**
*Copyright(c)2008GregWhalin
*Allrightsreserved.
*
*Thislibraryisfreesoftware;youcanredistributeitand/or
*modifyitunderthetermsoftheBSDlicense
*
*Thislibraryisdistributedinthehopethatitwillbe
*useful,butWITHOUTANYWARRANTY;withouteventheimplied
*warrantyofMERCHANTABILITYorFITNESSFORAPARTICULAR
*PURPOSE.
*
*YoushouldhavereceivedacopyoftheBSDLicensealongwiththis
*library.
*
*@authorGregWhalin<[email protected]>
*/
packagecom.meetup.memcached.test;
importjava.util.Map;
importorg.apache.log4j.BasicConfigurator;
importorg.apache.log4j.Level;
importorg.apache.log4j.Logger;
importcom.yulong.memcached.MemcachedClient;
importcom.yulong.memcached.SockIOPool;
publicclassMemcachedBench{
//logger
privatestaticLoggerlog=
Logger.getLogger(MemcachedBench.class.getName());
publicstaticvoidmain(String[]args){
BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.OFF);
intruns=Integer.parseInt(args[0]);
intstart=Integer.parseInt(args[1]);
String[]serverlist={"192.168.1.50:1624"};
//initializethepoolformemcacheservers
SockIOPoolpool=SockIOPool.getInstance("test");
pool.setServers(serverlist);
pool.setInitConn(100);
pool.setMinConn(100);
pool.setMaxConn(500);
pool.setMaintSleep(20);
pool.setNagle(false);
pool.initialize();
//getclientinstance
MemcachedClientmc=newMemcachedClient("test");
mc.setCompressEnable(false);
StringkeyBase="testKey";
Stringobject="Thisisatestofanobjectblahblahes,serializationdoesnotseemtoslowthingsdownsomuch.Thegzipcompressionishorriblehorribleperformance,soweonlyuseitforverylargeobjects.Ihavenotdoneanyheavybenchmarkingrecently";
longbegin=System.currentTimeMillis();
for(inti=start;i<start+runs;i++){
mc.set(keyBase+i,object);
}
longend=System.currentTimeMillis();
longtime=end-begin;
System.out.println(runs+"sets:"+time+"ms");
begin=System.currentTimeMillis();
for(inti=start;i<start+runs;i++){
Stringstr=(String)mc.get(keyBase+i);
}
end=System.currentTimeMillis();
time=end-begin;
System.out.println(runs+"gets:"+time+"ms");
String[]keys=newString[runs];
intj=0;
for(inti=start;i<start+runs;i++){
keys[j]=keyBase+i;
j++;
}
begin=System.currentTimeMillis();
Mapvals=mc.getMulti(keys);
end=System.currentTimeMillis();
time=end-begin;
System.out.println(runs+"getMulti:"+time+"ms");
begin=System.currentTimeMillis();
for(inti=start;i<start+runs;i++){
mc.delete(keyBase+i);
}
end=System.currentTimeMillis();
time=end-begin;
System.out.println(runs+"deletes:"+time+"ms");
SockIOPool.getInstance("test").shutDown();
}
}