`

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。

 

 

 

 

 

  • 大小: 73.6 KB
分享到:
评论

相关推荐

    Memcached学习笔记 — 第四部分:Memcached Java 客户端-gwhalin(1)-介绍及使用

    本篇学习笔记将重点介绍如何在Java环境中使用gwhalin提供的Memcached客户端进行开发。gwhalin的Memcached Java客户端是一个轻量级、高性能的库,使得Java开发者可以轻松地与Memcached服务器进行交互。 ### 一、...

    java_memcached-release_2.5.1.jar Memcache java jar 包

    Java Memcached是一个流行的Java客户端库,用于与Memcached缓存系统进行交互。Memcached是一种分布式内存对象缓存系统,常用于减轻数据库负载,提高Web应用的性能。在本例中,我们关注的是`java_memcached-release_...

    java-memcached-2.6.6.jar

    java-memcached-2.6.6.jar

    java_memcached-release_2.6.3.rar 客户端所有包

    2. **Java Memcached客户端**:Java Memcached客户端库允许Java开发者与Memcached服务器通信。此版本`2.6.3`提供了对Memcached协议的支持,包括添加、获取、删除和更新缓存中的键值对。 3. **依赖库解析**: - `...

    memcached-1.2.1-win32.zip 和 java_memcached-release_1.6.zip

    2. **引入Java客户端库**:将`java_memcached-release_1.6.zip` 解压后,将库文件(JAR)添加到Java项目的类路径中。 3. **编写Java代码**: - 引入必要的依赖:`import net.spy.memcached.MemcachedClient;` - ...

    Memcached最新版Jar包

    Memcached最新版Jar包: spymemcached-2.11.6.jar spymemcached-2.11.6-javadoc.jar spymemcached-2.11.6-sources.jar https://github.com/dustin/java-memcached-client

    memcached安装及java应用使用memcached

    虽然描述部分是空的,但我们可以推测文章可能涵盖了安装memcached的基本步骤,以及Java开发者如何集成并利用memcached来提升应用性能。 **标签解析:** 1. **源码**:可能意味着文章会涉及memcached的源代码安装或...

    memcached linux安装说明+ java客户端调用例子

    **memcached** 是一款高性能、分布式内存对象缓存系统,常用于减轻数据库负载,提高Web应用性能。在Linux系统上安装和配置memcached,并通过Java客户端进行调用是常见的操作流程,下面将详细介绍这一过程。 ### 一...

    java_memcached-release_2.5.1

    服务集成平台5.6的性能测试进入尾声,这期的优化也算告一段落。这次主要的优化工作还是在三个方面:应用服务器(Apache,JBoss)配置,业务流程,Cache Client包...

    memcached的三种java客户端jar

    2.spymemcached,支持异步,单线程的memcached客户端,用到了java1.5版本的concurrent和nio,存取速度会高于前者,但是稳定性不好,测试中常 报timeOut等相关异常。 3.xmemcached,XMemcached也使用得比较广泛,而且...

    Memcached-Java-Client-release_2.6.1.zip

    2. **Memcached Java客户端库** - Memcached-Java-Client是Java开发者与Memcached进行交互的主要工具,它提供了简单易用的API接口,允许开发者方便地在Java应用中存取缓存数据。 - 版本2.6.1是该客户端的一个稳定...

    java memcached-session 配置

    2. **选择Java Memcached客户端库** 对于Java应用,我们需要一个客户端库来与Memcached通信。常见的选择有spymemcached和xmemcached。这里以spymemcached为例,你需要将其JAR文件(通常为`spymemcached-x.x.x.jar`...

    java_memcached-release_2.6.3.zip

    2. **java_memcached-release_2.6.3.jar**:这是Java Memcached客户端的核心库文件,包含了所有必要的类和方法,使得Java应用能够与Memcached服务器通信。这个库提供了API,让开发者可以方便地进行数据的存取、删除...

    memcached 完整的项目,服务端(win) 客户端 包括jar包

    4. **故障恢复**:当 Memcached 服务端宕机后,Java 客户端可能会遇到连接问题,需要有适当的重试机制。 总之,Memcached 项目为开发者提供了一个高效、易用的缓存解决方案,通过 Java 客户端可以轻松地在 Java ...

    MemCached开发java客户端的使用

    这是MemCached的java客户端连接使用的例子,里面包含了MemCached的增删改查操作,对字符串 list set map 对象的操作等。看就会就入门了,

    memcached 1.2.6 1.2.5

    Jellycan Code | memcached Home The Good Egg SimpleIni SimpleOpt MemCacheClient Moji memcached show_menu2 menusys StringWrapper ML Fancy Excerpt LangSelect Visual Studio CommentsThis page contains a ...

Global site tag (gtag.js) - Google Analytics