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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
-
-
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
-
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
-
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
-
- int total;
-
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
-
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
-
-
-
-
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
-
- public void startTest() throws Exception{
-
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
-
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
-
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
-
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
-
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
-
- memcachedClient.flushAll();
-
- }
-
- class Task implements Runnable{
-
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
-
- public void run() {
- long start = System.currentTimeMillis();
-
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
-
-
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
-
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
-
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
-
- int total;
-
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
-
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
-
-
-
-
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
-
- public void startTest() throws Exception{
-
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
-
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
-
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
-
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
-
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
-
- memcachedClient.flushAll();
-
- }
-
- class Task implements Runnable{
-
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
-
- public void run() {
- long start = System.currentTimeMillis();
-
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
-
-
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
-
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
-
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
-
- int total;
-
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
-
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
-
-
-
-
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
-
- public void startTest() throws Exception{
-
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
-
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
-
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
-
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
-
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
-
- memcachedClient.flushAll();
-
- }
-
- class Task implements Runnable{
-
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
-
- public void run() {
- long start = System.currentTimeMillis();
-
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
-
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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
测试代码
因为是测试代码些的很乱很随意了,见谅。以下测试代码依赖前面介绍的“我的代码”。
- public class MemcachedClientTest {
- /** 线程数 */
- static int THREAD_COUNT = 10;
- /** 每线程执行次数 */
- static int PER_THREAD_COUNT = 10000;
- static String KEY = "key";
- static String VALUE = "value";
- static String NEW_VALUE = "newValue";
- /** 成功数 */
- int addSuccess;
- int setSuccess;
- int getSuccess;
- int getsSuccess;
- int casSuccess;
- int delSuccess;
- /** 执行时间 */
- int addTotal;
- int setTotal;
- int getTotal;
- int getsTotal;
- int casTotal;
- int delTotal;
- int total;
- public static final Logger logger = LoggerFactory.getLogger(MemcachedClientTest.class);
- public static void main(String[] args) throws Exception{
- MemcachedClient memcachedClient = new MemcachedClientJava();
- MemcachedClientTest test = new MemcachedClientTest(memcachedClient);
- test.startTest();
- }
- private MemcachedClient memcachedClient;
- private MemcachedClientTest(MemcachedClient memcachedClient) {
- super();
- this.memcachedClient = memcachedClient;
- }
- public void startTest() throws Exception{
- CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
- ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
- for (int i = 1; i <= THREAD_COUNT; i++) {
- executor.execute(new Task("Thread-"+i,latch));
- }
- latch.await();
- executor.shutdown();
- //total = addTotal+setTotal+getTotal+getsTotal+casTotal;
- total -= THREAD_COUNT * PER_THREAD_COUNT; //减去线程等待
- logger.info("Test thread: " + THREAD_COUNT + "; total times: " + total + "ms" + ";count/thread: "+PER_THREAD_COUNT * 6);
- logger.info("add success : " + addSuccess + "; success rate: " + (addSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("set success : " + setSuccess + "; success rate: " + (setSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("get success : " + getSuccess + "; success rate: " + (getSuccess * 1.0f / THREAD_COUNT) * 100 + "%");
- logger.info("gets success : " + getsSuccess + "; success rate: " + (getsSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("cas success : " + casSuccess + "; success rate: " + (casSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("del success : " + delSuccess + "; success rate: " + (delSuccess * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT)) * 100 + "%");
- logger.info("Average time: " + (total * 1.0f / (THREAD_COUNT * PER_THREAD_COUNT * 6)));
- logger.info("add TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (addTotal * 1.0 / 1000) + "; time: " + addTotal + "ms");
- logger.info("set TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (setTotal * 1.0 / 1000) + "; time: " + setTotal + "ms");
- logger.info("get TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getTotal * 1.0 / 1000) + "; time: " + getTotal + "ms");
- logger.info("gets TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (getsTotal * 1.0 / 1000) + "; time: " + getsTotal + "ms");
- logger.info("cas TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (casTotal * 1.0 / 1000) + "; time: " + casTotal + "ms");
- logger.info("del TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 1.0) / (delTotal * 1.0 / 1000) + "; time: " + delTotal + "ms");
- logger.info("Average TPS: " + (THREAD_COUNT * PER_THREAD_COUNT * 5 * 1.0) / (total * 1.0 / 1000));
- memcachedClient.flushAll();
- }
- class Task implements Runnable{
- private String name;
- CountDownLatch latch;
- public Task(String name,CountDownLatch latch) {
- super();
- this.name = name;
- this.latch = latch;
- }
- public void run() {
- long start = System.currentTimeMillis();
- for (int i = 0; i < PER_THREAD_COUNT; i++) {
- String key = name+KEY+i;
- long singleStart = System.currentTimeMillis();
- if(memcachedClient.add(key, VALUE)){
- addSuccess++;
- }
- addTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.set(key, NEW_VALUE)){
- setSuccess++;
- }
- setTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.get(key) != null){
- getSuccess++;
- }
- getTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- CacheItem item = memcachedClient.gets(key);
- if(item.getValue() != null){
- getsSuccess++;
- }
- getsTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.cas(key, NEW_VALUE, item.getUnique())){
- casSuccess++;
- }
- casTotal += System.currentTimeMillis() - singleStart;
- singleStart = System.currentTimeMillis();
- if(memcachedClient.delete(key)){
- delSuccess++;
- }
- delTotal += System.currentTimeMillis() - singleStart;
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- long time = System.currentTimeMillis() - start;
- total += time;
- logger.debug(name + " - time:" + time);
- latch.countDown();
- }
- }
- }
测试结果
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。