memcachedb單線程訪問bdb的阻塞問題

來源:互聯網
上載者:User

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();
}
}
}
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.