Memcached学习笔记 — 第四部分:Memcached Java 客户端-gwhalin(2)-性能测试


  


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


http://acooly.iteye.com/blog/1120758

Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


Memcached学习笔记 — 第四部分:Memcached Java 客户端-gwhalin(2)-性能测试


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


Memcached学习笔记 — 第四部分:Memcached Java 客户端-gwhalin(2)-性能测试


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


Memcached学习笔记 — 第四部分:Memcached Java 客户端-gwhalin(2)-性能测试


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


http://acooly.iteye.com/blog/1120758


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


http://acooly.iteye.com/blog/1120758


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


http://acooly.iteye.com/blog/1120758


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


http://acooly.iteye.com/blog/1120758


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 


http://acooly.iteye.com/blog/1120758

 

 


Memcached JJAVA Client 性能测试

 

 

测试方案

机器环境

我的小本本,thinkPad410,4G内,i5cpu虚拟4核(也就是假4核),64位windows7盗版操作系统,另外还开了很多其它服务和软件,测试前的内存显示已用2.3G,不过还是剩的很多。

 


软件环境

在本地WINDOWS7下安装了3个memcached服务,分别给了128M,64M,64M内存。测试代码待ECLIPSE下直接运行。如果有好的环境,下次在跑跑看。

测试方法

10线程,每个线程10000次调用,每次分别调用5个业务方法,并且KEY都不同
依次:add,set,get,gets,cas,delete

测试代码

因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。

 

Java代码   收藏代码
  1. public class MemcachedClientTest {  
  2.     /** 线程数 */  
  3.     static int THREAD_COUNT = 10;  
  4.     /** 每线程执行次数 */  
  5.     static int PER_THREAD_COUNT = 10000;  
  6.       
  7.       
  8.     static String KEY = "key";  
  9.     static String VALUE = "value";  
  10.     static String NEW_VALUE = "newValue";  
  11.       
  12.     /** 成功数 */  
  13.     int addSuccess;  
  14.     int setSuccess;  
  15.     int getSuccess;  
  16.     int getsSuccess;  
  17.     int casSuccess;  
  18.     int delSuccess;  
  19.       
  20.     /** 执行时间 */  
  21.     int addTotal;  
  22.     int setTotal;  
  23.     int getTotal;  
  24.     int getsTotal;  
  25.     int casTotal;  
  26.     int delTotal;  
  27.       
  28.     int total;  
  29.       
  30.     public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);  
  31.       
  32.     public static void main(String[] args) throws Exception{  
  33.         MemcachedClient memcachedClient = new MemcachedClientJava();  
  34.         MemcachedClientTest test = new MemcachedClientTest(memcachedClient);  
  35.         test.startTest();  
  36.     }  
  37.       
  38.       
  39.       
  40.       
  41.     private MemcachedClient memcachedClient;  
  42.     private MemcachedClientTest(MemcachedClient memcachedClient) {  
  43.         super();  
  44.         this.memcachedClient = memcachedClient;  
  45.     }  
  46.       
  47.     public void startTest() throws Exception{  
  48.           
  49.         CountDownLatch latch = new CountDownLatch(THREAD_COUNT);  
  50.         ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);  
  51.           
  52.         for (int i = 1; i <= THREAD_COUNT; i++) {  
  53.             executor.execute(new Task("Thread-"+i,latch));  
  54.         }  
  55.         latch.await();  
  56.         executor.shutdown();  
  57.           
  58.         //total = addTotal+setTotal+getTotal+getsTotal+casTotal;  
  59.         total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待  
  60.         logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);  
  61.           
  62.         logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  63.         logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  64.         logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");  
  65.         logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  66.         logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  67.         logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");  
  68.         logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));  
  69.           
  70.         logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");  
  71.         logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");  
  72.         logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");  
  73.         logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");  
  74.         logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");  
  75.         logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");  
  76.         logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));  
  77.           
  78.         memcachedClient.flushAll();  
  79.           
  80.     }  
  81.       
  82.     class Task implements Runnable{  
  83.           
  84.         private String name;  
  85.         CountDownLatch latch;  
  86.         public Task(String name,CountDownLatch latch) {  
  87.             super();  
  88.             this.name = name;  
  89.             this.latch = latch;  
  90.         }  
  91.   
  92.         public void run() {  
  93.             long start = System.currentTimeMillis();  
  94.               
  95.             for (int i = 0; i < PER_THREAD_COUNT; i++) {  
  96.                 String key = name+KEY+i;  
  97.                 long singleStart = System.currentTimeMillis();  
  98.                 if(memcachedClient.add(key, VALUE)){  
  99.                     addSuccess++;  
  100.                 }  
  101.                 addTotal += System.currentTimeMillis() - singleStart;  
  102.                   
  103.                 singleStart = System.currentTimeMillis();  
  104.                 if(memcachedClient.set(key, NEW_VALUE)){  
  105.                     setSuccess++;  
  106.                 }  
  107.                 setTotal += System.currentTimeMillis() - singleStart;  
  108.                   
  109.                 singleStart = System.currentTimeMillis();  
  110.                 if(memcachedClient.get(key) != null){  
  111.                     getSuccess++;  
  112.                 }  
  113.                 getTotal += System.currentTimeMillis() - singleStart;  
  114.                   
  115.                 singleStart = System.currentTimeMillis();  
  116.                 CacheItem item = memcachedClient.gets(key);  
  117.                 if(item.getValue() != null){  
  118.                     getsSuccess++;  
  119.                 }  
  120.                 getsTotal += System.currentTimeMillis() - singleStart;  
  121.                   
  122.                 singleStart = System.currentTimeMillis();  
  123.                 if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){  
  124.                     casSuccess++;  
  125.                 }  
  126.                 casTotal += System.currentTimeMillis() - singleStart;  
  127.                   
  128.                 singleStart = System.currentTimeMillis();  
  129.                 if(memcachedClient.delete(key)){  
  130.                     delSuccess++;  
  131.                 }  
  132.                 delTotal += System.currentTimeMillis() - singleStart;                 
  133.                 try {  
  134.                     Thread.sleep(1);  
  135.                 } catch (Exception e) {  
  136.                     // TODO: handle exception  
  137.                 }  
  138.             }  
  139.   
  140.             long time = System.currentTimeMillis() - start;  
  141.             total += time;  
  142.             logger.debug(name + " - time:" + time);  
  143.             latch.countDown();  
  144.         }  
  145.     }  
  146. }  

 

测试结果

20325  - Test thread: 10; total times: 75481s;count/thread: 60000
20325  - add success : 98137; success rate: 98.13699%
20326  - set success : 98192; success rate: 98.192%
20326  - get success : 98216; success rate: 982159.94%
20326  - gets success : 98237; success rate: 98.237%
20326  - cas success : 98675; success rate: 98.675%
20327  - del success : 98915; success rate: 98.915%
20327  - Average time: 0.12580167
20327  - add TPS: 18639.32898415657; time: 5365ms
20327  - set TPS: 8730.574471800244; time: 11454ms
20327  - get TPS: 7048.2097547223; time: 14188ms
20327  - gets TPS: 7649.938800489596; time: 13072ms
20327  - cas TPS: 7330.303474563847; time: 13642ms
20327  - del TPS: 6236.357966947303; time: 16035ms
20327  - Average TPS: 6624.183569375075

成功率都在98%以上,在我的小本本上还不错,平均TPS:6624。

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值