Wtat's mcb ?

mcb is a benchmark tool for memcahed. mcb send the commands to memcached, and measures the execution time.
Because mcb is a MultiThreading program, the command can be concurrently sent.

How to use?

Download

Download here:mcb.c. License is GPL.

Compile

Linux:

gcc -Wall -lpthread -lnsl -o mcb mcb.c
Solaris:
cc -Wall -lpthread -lnsl -lsocket -o mcb mcb.c

usage

usage: mcb -c {set|add|get} [OPTIONS]
                -c command_type {set|add|get}          送信するコマンドを設定。設定できるのはset,add,getのみ
                -a server_address[127.0.0.1]           memcahedが稼働しているサーバのIPアドレス。デフォルトは127.0.0.1
                -p server_port[11211]                  memcahedが稼働しているサーバのport番号。デフォルトは11211
                -T connection Type {TCP|UDP|UNIX_SOCKET}  memcachedとの接続プロトコル。デフォルトはTCP
                -f unix socket path                    UNIXソケットのパス。"-T UNIX_SOCKET"と併用
                -t number_of_thread[1]                 送信するスレッド数。デフォルトは1
                -n number_of_command[1]                スレッド当たりの送信コマンド数。デフォルトは1
                -m max_key[1000]                       送信するコマンドの最大key値。デフォルトは1000
                -l data_length[10]                     setかaddコマンドで送信するデータ長。デフォルトは10バイト
                -v               :verbose
                -s               :single command        各スレッドで、1コマンド毎にQUITしてTCPコネクションを切る。
                                                        デフォルトはOFFで、1セッションですべてのコマンドを送信する。
                                                        旧バージョン(0.9alpha)とは意味が逆になり、デフォルトも逆なので注意。
                -h               :help

It starts by ten threads, and each thread sends command set by 1,000 commands. Therefore, the sent command total is 10,000.

# ./mcb -c set -a 192.168.1.100 -p 11211 -t 10 -n 1000 -l 100
condition =>
        connect to 192.168.1.100 TCP port 11211
        command = set
        10 thread run
        send 1000 command a thread, total 10000 command
        data length = 100
result =>
        interval =  0.419934 [sec]
        performance =  23813.263946 [command/sec]
        thread info:
          ave. = 0.230296[sec], min = 0.047713[sec], max = 0.393719[sec]

total execution time of the all commands is 0.419934 seconds. Therefore, it is a performance that can be executed by about 23813 commands a second.
Statistical information of thread:
Ten thread averages are 0.230296 seconds. Threads that end shortest are 0.047713 seconds. The longest is 0.393719 seconds.

Each thread connects to the memcached first. After that, the threads sent the command continuously. The connection holds until it finishes sending all the commands.
Please set optional "-s" when you want to cut the connection of each command execution. (See Remark below)

mcb can use not only tcp, but also udp and unix socket still version 1.0rc1.

Use udp:
Set "UDP" to option "-T", set the port number properly.

# ./mcb -c set -a 192.168.1.100 -p 11211 -t 10 -n 1000 -l 100 -T UDP

Use unix socket:
Set "UNIX_SOCKET" to option "-T", and socket path to option "-f".

# ./mcb -c set -t 10 -n 1000 -l 100 -T UNIX_SOCKET -f /tmp/memcached

If mcb does not work, please check:
(1) Do memcached start with unix socket?
(2) Can mcb access the unix socket? check the permission.


Remark

mcb version 0.9alphaをデフォルトで使用("-s"を*設定しない*)した場合、およびmcb version 0.9 beta以降で"-s"オプションを設定した場合、mcbはmemcachedに対して多量のコネクションを生成し切断します。 よってport番号を使い切ってしまう可能性があり、他のサービスに影響を及ぼす可能性があります。 mcbはテスト用のサーバ上で実行することをお勧めします。

また、もしも可能ならクライアントを動作させるサーバのカーネルパラメータ"tcp_fin_timeout"を一時的に変更して、TIME_WAIT状態を一時的に短縮する方法もあります。これによってport番号が不足することによる影響を多少とも減らすことができます。

# cat /proc/sys/net/ipv4/tcp_fin_timeout
 60
# echo 5 > /proc/sys/net/ipv4/tcp_fin_timeout


Last-modified: 2009-11-04