连接池方式测试ehcache 独立server的性能,ehcacheserver,仿照 官网例子,jedi
分享于 点击 11112 次 点评:129
连接池方式测试ehcache 独立server的性能,ehcacheserver,仿照 官网例子,jedi
仿照 官网例子,jedis多线程benchmark, 用Httpclient 3 测试ehcache 独立server的性能,通过restful协议。
独立server部署在1个linux 的weblogic 16G内存 16cpu上。
java运行在另一个 同配置linux上 8540 ops 性能比spymemcache,jedis 都慢 好几倍, 这还不包括读响应流时间 。分析可能因http 协议包装开销,服务器从url里解析参数key耗时。之前一直没找到性能数据,官网有谁找到过的。也有人说1.3万。自己测了下,不知道大家测的结果。有文章说encache 比memcache,redis都快。据此数据,正好相反了。还是我带写的有问题? 请大家斧正
import java.io.InputStream;import java.io.OutputStream;import java.net.HttpURLConnection;import java.net.URL;import java.util.ArrayList;import java.util.List;import java.util.concurrent.atomic.AtomicInteger;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;import org.apache.commons.httpclient.methods.GetMethod;import org.apache.commons.httpclient.methods.PutMethod;import org.apache.commons.pool.impl.GenericObjectPool.Config;/*** A simple example Java client which uses the built-in java.net.URLConnection.** @author BryantR* @author Greg Luck*/public class BenchMark {private static String TABLE_COLUMN_ELEMENT = "http://x.x.x.x:7001/ehcache-server-1.0.0/rest/tableColumn/1";/*** Creates a new instance of EHCacheREST*/public static void main(String[] args) { URL url; HttpURLConnection connection = null; InputStream is = null; OutputStream os = null; int result = 0; try { withPool(); } catch (Exception e) { e.printStackTrace(); } finally { if (os != null) try { os.close(); } catch (Exception ignore) { } if (is != null) try { is.close(); } catch (Exception ignore) { } if (connection != null) connection.disconnect(); }}private static final int TOTAL_OPERATIONS = 100000;private static void withPool() throws Exception { // wang.hailong 2012-4-24上午11:37:55 创建连接池 MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setMaxTotalConnections(100); connectionManager.setMaxConnectionsPerHost(100); final HttpClient client = new HttpClient(connectionManager);// 在某个线程中。 long begin = System.currentTimeMillis(); List<Thread> tds = new ArrayList<Thread>(); final AtomicInteger ind = new AtomicInteger(); for (int i = 0; i < 100; i++) { Thread hj = new Thread(new Runnable() { boolean print = false; public void run() { for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) { try { PutMethod put = new PutMethod(TABLE_COLUMN_ELEMENT+i); put.setRequestBody("bar"+i); client.executeMethod(put); if(print) System.out.println(" put statust:" + put.getStatusCode()); put.releaseConnection(); GetMethod get = new GetMethod(TABLE_COLUMN_ELEMENT+i); client.executeMethod(get); InputStream is = get.getResponseBodyAsStream(); boolean readResponse = false; if(readResponse) { byte[] response1 = new byte[4096]; int result = 0; result = is.read(response1); while (result != -1) { // wang.hailong 2012-4-16下午04:48:42 从返回读出4096字节,关于缓存tableColumn对象的服务器配置 if(print) { System.out.write(response1, 0, result); result = is.read(response1); } } if (is != null) try { is.close(); } catch (Exception ignore) { } } get.releaseConnection(); } catch (Exception e) { e.printStackTrace(); } } } }); tds.add(hj); hj.start(); } for (Thread t : tds) t.join(); long elapsed = System.currentTimeMillis() - begin; System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); //pool.destroy(); connectionManager.deleteClosedConnections();}}//该片段来自于http://byrx.net
用户点评