Blocking memcachedb single-thread access to bdb

Source: Internet
Author: User

Http://hi.baidu.com/jabber/blog/item/8b739a456a8a493b87947313.html

Memcacheq performance of a Message Queue developed in China
The presence in XMPP is suitable for Message Queue implementation, so it is always concerned about fast message queue implementation. We can see a memcacheq project on memcachedb, which is literally an MQ implementation. Because it also uses the memcache protocol, the previous performance test program of memcachedb was slightly modified and read the results. The environment is the same as the previous one, and the test data is not liable for any responsibility, for reference only :)

1. Write only to the queue, with 1 million
Thread: 2
Time elpased: 427 s
AVG: 2,349 puts/sec
Bdb data dir size: 945 m

2. Read Only the queue, 1 million entries, and use the queue Data Built in the previous step.
Thread: 2
Time elpased: 569 s
AVG: 1,763 gets/sec
Bdb data dir size: 1.7 GB (this is a problem, may not be completed yet ?)

3. Both inbound and outbound queues. This is in line with the actual situation of the application. the read-out queue program starts only after 0.1 million rows are written.
Thread: 2
Time elpased: 569 s
AVG: 1,049 puts/sec
AVG: 979 gets/sec
Bdb data dir size: 1.6g

Test summary:

  • In Test 3, the removal speed of 0.1 million records at the beginning is the same as that of the team, that is, the average operation speed is 1,000 messages per second (100 bytes ).
  • The speed tends to be the same. For more information, see my previous analysis on the blocking problem of memcachedb single-thread access to bdb.
  • In Test 2, database-related implementations may be problematic. The larger the data runs.
  • Because Apache activemq was used in the past, the next step is to compare it with the environment. See later: activemq Performance Research and comparison with memcacheq

2008/5/8: Read the memcacheq code and add several new ideas:

  • Memcacheq is a memcache protocol package based on Berkeley dB queue.
  • Memcacheq does not implement MQ-related algorithms. Therefore, the efficiency of the Berkeley dB in a single thread is tested.
  • The problem with larger space is that the Berkeley dB algorithm is delayed and deleted.
  • A friend asked about the test code, which is actually relatively simple, as shown below.


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.