- 浏览: 70484 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (121)
- luence (7)
- MoveLuceneRebuild (0)
- ehcache (0)
- memcached (12)
- WeiXin (1)
- hy (0)
- alipay (0)
- Wxap (0)
- 学习笔记 (14)
- java generic (1)
- threadpool (0)
- Awmazon (0)
- com.yulong.businessCache (0)
- com.yulong.util (1)
- com.wxap (0)
- com.yulong.wxshop (0)
- com.alipay (0)
- com.yulong.session (0)
- com.yulong.handler (0)
- kafka (0)
- http://www.cnblogs.com/oubo/archive/2012/02/04/2394646.html (0)
- redis (0)
- MongoDB (2)
- Nginx (1)
- java (10)
- 云搜索 (4)
- Hadoop (1)
- Spring (15)
- Thread (1)
- 博客链接 (0)
- AJAX与CSS (7)
- 项目管理 (1)
- restful架构 (1)
- 多线程 (3)
- Java面试 (6)
- 牛人博客 (2)
- Linux (1)
- java集合 (1)
- Socket与Nio (1)
- SQL开发 (2)
- Spring Boot (3)
- Spring4.1 (4)
- tomcat配置 (1)
- JVM (5)
- Hibernate (1)
- Dubbo (7)
- MQ (2)
- java常见错误 (0)
最新评论
/**
* Copyright (c) 2008 Greg Whalin
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the BSD license
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
*
* You should have received a copy of the BSD License along with this
* library.
*
* @author Greg Whalin <greg@meetup.com>
*/
package com.meetup.memcached.test;
import java.util.Hashtable;
import com.yulong.memcached.MemcachedClient;
import com.yulong.memcached.SockIOPool;
public class MemcachedTest {
// store results from threads
private static Hashtable<Integer,StringBuilder> threadInfo =
new Hashtable<Integer,StringBuilder>();
/**
* This runs through some simple tests of the MemcacheClient.
*
* Command line args:
* args[0] = number of threads to spawn
* args[1] = number of runs per thread
* args[2] = size of object to store
*
* @param args the command line arguments
*/
public static void main(String[] args) {
String[] serverlist = { "cache1.int.meetup.com:12345", "cache0.int.meetup.com:12345" };
// initialize the pool for memcache servers
SockIOPool pool = SockIOPool.getInstance();
pool.setServers( serverlist );
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(50);
pool.setMaintSleep(30);
pool.setNagle(false);
pool.initialize();
int threads = Integer.parseInt(args[0]);
int runs = Integer.parseInt(args[1]);
int size = 1024 * Integer.parseInt(args[2]); // how many kilobytes
// get object to store
int[] obj = new int[size];
for (int i = 0; i < size; i++) {
obj[i] = i;
}
String[] keys = new String[size];
for (int i = 0; i < size; i++) {
keys[i] = "test_key" + i;
}
for (int i = 0; i < threads; i++) {
bench b = new bench(runs, i, obj, keys);
b.start();
}
int i = 0;
while (i < threads) {
if (threadInfo.containsKey(new Integer(i))) {
System.out.println( threadInfo.get( new Integer( i ) ) );
i++;
}
else {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
pool.shutDown();
System.exit(1);
}
/**
* Test code per thread.
*/
private static class bench extends Thread {
private int runs;
private int threadNum;
private int[] object;
private String[] keys;
private int size;
public bench(int runs, int threadNum, int[] object, String[] keys) {
this.runs = runs;
this.threadNum = threadNum;
this.object = object;
this.keys = keys;
this.size = object.length;
}
public void run() {
StringBuilder result = new StringBuilder();
// get client instance
MemcachedClient mc = new MemcachedClient();
mc.setCompressEnable(false);
mc.setCompressThreshold(0);
// time deletes
long start = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
mc.delete(keys[i]);
}
long elapse = System.currentTimeMillis() - start;
float avg = (float) elapse / runs;
result.append("\nthread " + threadNum + ": runs: " + runs + " deletes of obj " + (size/1024) + "KB -- avg time per req " + avg + " ms (total: " + elapse + " ms)");
// time stores
start = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
mc.set(keys[i], object);
}
elapse = System.currentTimeMillis() - start;
avg = (float) elapse / runs;
result.append("\nthread " + threadNum + ": runs: " + runs + " stores of obj " + (size/1024) + "KB -- avg time per req " + avg + " ms (total: " + elapse + " ms)");
start = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
mc.get(keys[i]);
}
elapse = System.currentTimeMillis() - start;
avg = (float) elapse / runs;
result.append("\nthread " + threadNum + ": runs: " + runs + " gets of obj " + (size/1024) + "KB -- avg time per req " + avg + " ms (total: " + elapse + " ms)");
threadInfo.put(new Integer(threadNum), result);
}
}
}
* Copyright (c) 2008 Greg Whalin
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the BSD license
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
*
* You should have received a copy of the BSD License along with this
* library.
*
* @author Greg Whalin <greg@meetup.com>
*/
package com.meetup.memcached.test;
import java.util.Hashtable;
import com.yulong.memcached.MemcachedClient;
import com.yulong.memcached.SockIOPool;
public class MemcachedTest {
// store results from threads
private static Hashtable<Integer,StringBuilder> threadInfo =
new Hashtable<Integer,StringBuilder>();
/**
* This runs through some simple tests of the MemcacheClient.
*
* Command line args:
* args[0] = number of threads to spawn
* args[1] = number of runs per thread
* args[2] = size of object to store
*
* @param args the command line arguments
*/
public static void main(String[] args) {
String[] serverlist = { "cache1.int.meetup.com:12345", "cache0.int.meetup.com:12345" };
// initialize the pool for memcache servers
SockIOPool pool = SockIOPool.getInstance();
pool.setServers( serverlist );
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(50);
pool.setMaintSleep(30);
pool.setNagle(false);
pool.initialize();
int threads = Integer.parseInt(args[0]);
int runs = Integer.parseInt(args[1]);
int size = 1024 * Integer.parseInt(args[2]); // how many kilobytes
// get object to store
int[] obj = new int[size];
for (int i = 0; i < size; i++) {
obj[i] = i;
}
String[] keys = new String[size];
for (int i = 0; i < size; i++) {
keys[i] = "test_key" + i;
}
for (int i = 0; i < threads; i++) {
bench b = new bench(runs, i, obj, keys);
b.start();
}
int i = 0;
while (i < threads) {
if (threadInfo.containsKey(new Integer(i))) {
System.out.println( threadInfo.get( new Integer( i ) ) );
i++;
}
else {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
pool.shutDown();
System.exit(1);
}
/**
* Test code per thread.
*/
private static class bench extends Thread {
private int runs;
private int threadNum;
private int[] object;
private String[] keys;
private int size;
public bench(int runs, int threadNum, int[] object, String[] keys) {
this.runs = runs;
this.threadNum = threadNum;
this.object = object;
this.keys = keys;
this.size = object.length;
}
public void run() {
StringBuilder result = new StringBuilder();
// get client instance
MemcachedClient mc = new MemcachedClient();
mc.setCompressEnable(false);
mc.setCompressThreshold(0);
// time deletes
long start = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
mc.delete(keys[i]);
}
long elapse = System.currentTimeMillis() - start;
float avg = (float) elapse / runs;
result.append("\nthread " + threadNum + ": runs: " + runs + " deletes of obj " + (size/1024) + "KB -- avg time per req " + avg + " ms (total: " + elapse + " ms)");
// time stores
start = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
mc.set(keys[i], object);
}
elapse = System.currentTimeMillis() - start;
avg = (float) elapse / runs;
result.append("\nthread " + threadNum + ": runs: " + runs + " stores of obj " + (size/1024) + "KB -- avg time per req " + avg + " ms (total: " + elapse + " ms)");
start = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
mc.get(keys[i]);
}
elapse = System.currentTimeMillis() - start;
avg = (float) elapse / runs;
result.append("\nthread " + threadNum + ": runs: " + runs + " gets of obj " + (size/1024) + "KB -- avg time per req " + avg + " ms (total: " + elapse + " ms)");
threadInfo.put(new Integer(threadNum), result);
}
}
}
发表评论
-
Memcached处理
2015-07-21 14:00 372Memcached有两个核心 ... -
memcached工作原理与优化建议
2015-01-07 10:30 337工作原理 基本概念:slab,page,chunk。 ... -
TestMemcached
2014-11-10 09:08 396/** * Copyright (c) 2008 Greg ... -
MemcachedBench
2014-11-10 09:09 389/** * Copyright (c) 2008 Greg ... -
MemcachedService
2014-11-10 09:10 462package com.yulong.memcached.se ... -
TestDropMemcacheUser
2014-11-10 09:10 482package com.yulong.memcached; ... -
TestAddMemcacheMemberAddress
2014-11-12 09:23 242package com.yulong.memcached; ... -
SockIOPool
2014-11-12 09:24 1453/** * Copyright (c) 2008 Greg ... -
NestedIOException
2014-11-12 09:24 818/** * Copyright (c) 2008 Greg ... -
NativeHandler
2014-11-12 09:24 290/** * Copyright (c) 2008 Greg ... -
MemcachedClient
2014-11-12 09:24 1824/** * Copyright (c) 2008 Greg ... -
MccErrorHandler
2014-11-07 22:10 0package com.yulong.memcached; ... -
Logger
2014-11-07 22:10 0/** * Copyright (c) 2008 Greg ... -
LineInputStream
2014-11-07 22:10 0/** * Copyright (c) 2008 Greg ... -
ErrorHandler
2014-11-07 22:09 0/** * Copyright (c) 2008 Greg ... -
ContextObjectInputStream
2014-11-07 22:09 0/** * Copyright (c) 2008 Greg ... -
ByteBufArrayInputStream
2014-11-07 22:08 0/** * Copyright (c) 2008 Greg ... -
MemberInfoMemcachedService
2014-11-07 17:55 0package com.yulong.memcached.se ... -
GrabMemcachedService
2014-11-07 17:50 0package com.yulong.memcached.se ...
相关推荐
标题中的"memcachedtest"指的是一个使用Java编写的Memcached测试程序。Memcached是一种高性能、分布式内存对象缓存系统,常用于加速动态Web应用。它通过将数据存储在内存中来减少数据库的负载,提高数据读取速度。在...
`MemcachedTest`可能是项目的测试项目,其中包含各种测试用例,以确保Enyim.Caching库的功能正确性和性能表现。测试对于任何软件开发都是至关重要的,尤其是对于像Memcached这样的关键基础设施组件。 **Enyim....
在测试类`MemcachedTest`中,首先初始化`MemCachedClient`,并设置服务器列表(默认是本地11211端口)。`SockIOPool`用于管理连接池,通过`setServers()`方法配置服务器地址,并调用`initialize()`方法初始化。 `...
在实际开发中,`MemcachedTest` 文件可能包含了一些示例代码或测试用例,用于演示如何使用 `MemcachedProviders` 进行缓存操作,例如初始化客户端、设置和获取缓存项、使用计数器以及管理 Session 等。 总的来说,`...
压缩包中的“memcachedTest”可能是用于测试memcached功能的脚本或代码。通过运行这个测试,我们可以验证memcached的正确配置和操作,确保其正常工作。 总结,danga memcached是一个高效、轻量级的分布式缓存系统,...
在提供的压缩包中,可能包含了一些关于如何使用或测试Memcached的资源,如`MemcachedTest`可能是用于测试Memcached的脚本或工具,而`网盘资源搜索-【51pansou.com】.txt`和`51pansou-海量网盘资源任意搜索.url`可能...
public class MemcachedTest { public static void main(String[] args) { try { MemcachedClient client = new MemcachedClient(new ConnectionFactoryBuilder().build(), AddrUtil.getAddresses("your_server_...
public class MemcachedTest { public static void main(String[] args) { try { MemcachedClient client = new MemcachedClient(new ConnectionFactoryBuilder().build(), AddrUtil.getAddresses("localhost:...
public class MemcachedTest { @Autowired private MemcachedClient memcachedClient; @Test public void testMemcached() { // 使用 memcachedClient 对象进行缓存操作 } } ``` 通过以上步骤,我们可以成功...