http://hi.baidu.com/jabber/blog/item/8b739a456a8a493b87947313.html
memcacheq一個國內開發的message queue之效能研究2008-05-07 14:40
| XMPP中的presence適合用Message Queue的方式來實現,所以一直對快速的message queue實現比較關心。剛好在 memcachedb 上看到了一個 memcacheq 的項目,從字面上看就是一個mq的實現。因為它也採用memcache的協議,所以將以前做的memcachedb的效能測試程式稍微修改看了下結果,環境和前面一樣,測試資料不承擔任何責任,僅供參考:)
1. 僅寫入隊列, 100萬條
Thread: 2
Time elpased: 427s
Avg: 2,349 puts / sec
bdb data dir size: 945M
2. 僅隊列讀出, 100萬條,使用上一步構建的隊列資料。
Thread: 2
Time elpased: 569s
Avg: 1,763 gets / sec
bdb data dir size: 1.7G (這個地方有問題,可能還沒完成?)
3. 同時出入隊列,這個是符合應用的真實的情況,寫入10萬行後才開始啟動讀出隊列程式。
Thread: 2
Time elpased: 569s
Avg: 1,049 puts / sec
Avg: 979 gets / sec
bdb data dir size: 1.6G
測試總結:
- 測試3中入隊去除剛開始單獨放10萬條記錄的速度,實際上出隊和入隊的速度是一樣的,即同時操作平均速度在每秒1,000條(100 byte message)。
- 速度趨於相同可參考我以前的分析 memcachedb單線程訪問bdb的阻塞問題
- 測試2中資料庫相關實現可能有問題,資料越跑越大。
- 因為以前用的是Apache ActiveMQ ,所以下一步打算在同環境比較一下。參看後文:ActiveMQ效能研究及與memcacheq比較
2008/5/8:看了一下memcacheq的代碼,補充一下幾個新看法:
- memcacheq 是基於 berkeley db queue 的 memcache 協議封裝
- memcacheq 本身沒有mq相關演算法實現,所以上面實際測試的是單線程下berkeley db的效率。
- 空間變大的問題是由於berkeley db演算法延後刪除,不是問題。
- 有朋友問測試代碼,其實比較簡單,如下。
import java.util.concurrent.atomic.AtomicInteger;
/** * Test client for memcache protocol servers * We use java memcached client, download from http://www.whalin.com/memcached/ * run: java MQTest [threads] [type], e.g. java MQTest 2 1 * @author Tim */ public class MQTest implements Runnable { CacheClient cc; public static AtomicInteger count = new AtomicInteger(); public static final String DATA100 = "TIM'S DATA AND CODE WITHOUT WARRANTY OF ANY KIND.#################" + "##################################";
// type: 0 - get, 1 - put private static int testType = 1; public static void main(String[] args) { int thread = 1;
if (args.length > 1) { thread = Integer.parseInt(args[0]); testType = Integer.parseInt(args[1]); }
System.out.println("Thread: " + thread); System.out.println("Test Type: " + (testType == 0 ? "get queue" : "put queue"));
long time1 = System.currentTimeMillis(); for (int i = 0; i < thread; i++) { MQTest test = new MQTest(); Thread t = new Thread(test); t.start(); }
printStat(time1); }
public MQTest() { cc = new CacheClient(); cc.setServerPort("server:11211"); }
public void run() { while (true) { if (testType != 0) set(); else get(); } }
public void get() { cc.get("q"); count.incrementAndGet(); }
public void set() { cc.set("q", DATA100); count.incrementAndGet(); }
private static void printStat(long time1) { while (true) { long time2 = System.currentTimeMillis(); if (time2 == time1) continue; int cnt = count.get();
System.out.println("---------------------------"); System.out.println("Total: " + cnt);
System.out.print("Time elapsed: "); System.out.println((time2 - time1) / 1000);
System.out.print("AVG: "); System.out.println(cnt * 1000l / (time2 - time1)); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
|