ITeye博客

令人振奋的结果:memcached 访问速度达到66000TPS

uniseraph · 2008-10-27 13:45 · 企业架构 · Markdown

今天找了两台服务器进行Memcached Client java的测试,其中 服务器为: CPU:2* Socket Designation: CPU1 Version: Intel(R) Xeon(R) CPU E5320 @ 1.86GHz 内存:8G

起8个线程,运行memcached-1.2.6

客户端为: CPU: 2* Socket Designation: CPU1 Version: Intel(R) Xeon(R) CPU E5310 @ 1.60GHz 内存:8G

jdk1.6

代码分支:https://commons-client.googlecode.com/svn/trunk 版本:144

测试多次以后发现,最高达到:66000TPS,基本稳定在61000TPS

评论(45)

  1. #45 楼 · uniseraph · 2008-11-05 09:12

    sdh5724 writes:

    可以借用你的代码继续开发么? 我想在周边做些实验, 估计要比较大的改动代码. 可以么? 行的话, PM我下. 因为我这样可以节省时间网络/协议的代码.

    当然可以,呵呵。

  2. #44 楼 · sdh5724 · 2008-11-04 23:04

    可以借用你的代码继续开发么? 我想在周边做些实验, 估计要比较大的改动代码. 可以么? 行的话, PM我下. 因为我这样可以节省时间网络/协议的代码.

  3. #43 楼 · uniseraph · 2008-11-03 19:48

    明天再发官方客户端的测试报告

  4. #42 楼 · uniseraph · 2008-11-03 19:40

    客户端:T61,2g ,ubuntu-8.04 , Intel(R) Core(TM)2 Duo CPU T7100 @ 1.80GHz 服务端:CPU 2* Socket Designation: CPU1 Version: Intel(R) Xeon(R) CPU E5310 @ 1.60GHz 8G 内存 测试结果:

    uniseraph@uniseraph-laptop:~/mywork/commons-client$ ant run -Dthread=50 && ant run -Dthread=100 && ant run -Dthread=150 Buildfile: build.xml

    run: INFO (Test.java:139) - thread num=50, repeat=10000,size=2, all=1000000 ,velocity=23527 , using time:42503

    BUILD SUCCESSFUL Total time: 48 seconds Buildfile: build.xml

    run: Deleting directory /home/uniseraph/mywork/commons-client/logs INFO (Test.java:139) - thread num=100, repeat=10000,size=2, all=2000000 ,velocity=25591 , using time:78152

    BUILD SUCCESSFUL Total time: 1 minute 24 seconds Buildfile: build.xml

    run: Deleting directory /home/uniseraph/mywork/commons-client/logs INFO (Test.java:139) - thread num=150, repeat=10000,size=2, all=3000000 ,velocity=28091 , using time:106793

    BUILD SUCCESSFUL Total time: 1 minute 52 seconds

  5. #41 楼 · uniseraph · 2008-11-03 19:21

    测试结果: $ ant run -Dthread=50 && ant run -Dthread=100 && ant run -Dthread=200 && ant run -Dthread=300 && ant run -Dthread=400 Buildfile: build.xml

    run: Deleting directory /home/zhengtao.wuzt/work/commons-client/logs INFO (Test.java:139) - thread num=50, repeat=10000,size=8, all=1000000 ,velocity=47229 , using time:21173

    BUILD SUCCESSFUL Total time: 21 seconds Buildfile: build.xml

    run: Deleting directory /home/zhengtao.wuzt/work/commons-client/logs INFO (Test.java:139) - thread num=100, repeat=10000,size=8, all=2000000 ,velocity=52649 , using time:37987

    BUILD SUCCESSFUL Total time: 38 seconds Buildfile: build.xml

    run: Deleting directory /home/zhengtao.wuzt/work/commons-client/logs INFO (Test.java:139) - thread num=200, repeat=10000,size=8, all=4000000 ,velocity=59557 , using time:67162

    BUILD SUCCESSFUL Total time: 1 minute 7 seconds Buildfile: build.xml

    run: Deleting directory /home/zhengtao.wuzt/work/commons-client/logs INFO (Test.java:139) - thread num=300, repeat=10000,size=8, all=6000000 ,velocity=62657 , using time:95758

    BUILD SUCCESSFUL Total time: 1 minute 36 seconds Buildfile: build.xml

    run: Deleting directory /home/zhengtao.wuzt/work/commons-client/logs INFO (Test.java:139) - thread num=400, repeat=10000,size=8, all=8000000 ,velocity=64883 , using time:123298

    BUILD SUCCESSFUL Total time: 2 minutes 3 seconds

    硬件: CPU:2* Socket Designation: CPU1 Version: Intel(R) Xeon(R) CPU E5320 @ 1.86GHz 内存:8G

  6. #40 楼 · uniseraph · 2008-11-03 13:33

    uniseraph writes:

    今天找了两台服务器进行Memcached Client java的测试,其中 服务器为: CPU:2* Socket Designation: CPU1 Version: Intel(R) Xeon(R) CPU E5320 @ 1.86GHz 内存:8G

    起8个线程,运行memcached-1.2.6

    客户端为: CPU: 2* Socket Designation: CPU1 Version: Intel(R) Xeon(R) CPU E5310 @ 1.60GHz 内存:8G

    jdk1.6

    代码分支:https://commons-client.googlecode.com/svn/trunk 版本:144

    测试多次以后发现,最高达到:66000TPS,基本稳定在61000TPS

    刚才发现dev分支最新版本比144版本的性能差25%不知道哪儿改出问题了,呵呵。查一下,然后拿spymemcached做一把对比测试。

  7. #39 楼 · sdh5724 · 2008-11-03 10:02

    uniseraph, 你的代码的性能差异基本在垃圾收集上, 也就是说, 你设计产生了过多的临时对象, 如果你能改善下, 基本还是跟spymemcached有的一比的, 甚至要超过。因为整个协议的分析,包括写数据都是很简单, 那么临时创建对象的结果就导致性能稍微有点下降, 在多线程下, 差异很容易被放大。

  8. #38 楼 · yeshucheng · 2008-11-03 01:10

    LZ有人帮你辛苦了,呵呵。所以大伙关心的数据也就看到了!

  9. #37 楼 · raymond2006k · 2008-11-02 22:48

    测试类在那儿?

    我那条回复的附件中啊。

  10. #36 楼 · raymond2006k · 2008-11-02 22:46

    有点事情要出去一下,先说一下分析结果,比较仓促,不一定对。

    commons-client 在windows和linux下性能相差比较大,怀疑和不同thread操作系统下的实现相关,明天我回公司做一下测试。

    spymemcached的set方法是异步的,他没有等待返回结果,所以比同步的get方法快,有点不公平,呵呵。

    spymemcached用了一些spy的底层实现,而且不是开源的,不好分析,头痛,明天具体测一下好了。

    只是希望对你的开源项目有所帮助。另外你的代码里 start 参数, cdl 参数 似乎只看到传入,没看到使用,这是我的一点疑问,请赐教,呵呵。

    你说的有道理。今天是在家里本本上 windows+ubuntu 测试的。 明天回公司再全用linux测测。 其实 spymemcache 的 MemcacheClient类也有点问题,比较原始,像一个connection,需要再做pool化才行,50个thread时,由于量大,已经 内存暴了,加大到 160m才行 ; 好像 javaeye 的 wenchu 已经对 whalin 做了封装,明天我测测whalin 。

    另外,我觉得测压力,thread 到一定值就可以了,一般服务器系统thread pool到一定数值就可以了,有pool就可以应付高并发了, 只要用非阻塞io就能保证性能。 大系统主要看memcached 对海量数据的处理能力,如集群时的性能和可靠性。

    因为最近要选型,几种client 都要用用才行,最后会选一种。

  11. #35 楼 · uniseraph · 2008-11-02 21:58

    raymond2006k writes:

    我花了点时间对 spmemcache 和 楼主的 commons-client 做了一下测试。测试代码采用楼主的源码中的测试代码写法。

    主要变量:线程数thread,最大值repeat。 我略微修改了一下楼主的MemcacheClient中的 测试代码, 将 write,read分开。

    key,value策略: key,value 相同,1 - repeat , 其中repeat是最大值

    (测试环境: 硬件:机器: 酷睿T2350,1.86G双核,2G内存。 系统1:XP,运行memcached客户端测试。 测试程序,JDK1.6.0_10, -Xmx=160m 系统2:Ubuntu 8.0.4,运行于VMWare虚拟机中。memcached 1.2.6 + libevent 1.3, memcached 进程 1个,32M内存,最大256并发连接 ) 引用 1  spymemcache测试结果

    1线程 write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=21367 , using time:468 read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3516 , using time:2844

    10线程 write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=14712 , using time:6797 read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=5258 , using time:19016

    50线程 write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=8355 , using time:59844 read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5631 , using time:88781

    2 commons-client测试结果

    1线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=2806 , using time:3563 INFO [main] (MemcachedClient.java:309) - read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3351 , using time:2984

    10线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=5855 , using time:17078 INFO [main] (MemcachedClient.java:309) - read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=4815 , using time:20765

    50线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=5856 , using time:85375 INFO [main] (MemcachedClient.java:309) - read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5612 , using time:89094

    测试结果可能没楼主的TPS大,只反映我机器上的结果。主要是有同样的测试基准才好对比。

    从测试结果看spymemcached的 velocity反映较好一些。spymemcache client, commons-client都 用了nio。 其中read性能表现较低,不知为什么?

    我将测试类附上,楼主可以分析一下结果。或者也对 spymemcache做做测试。

    有点事情要出去一下,先说一下分析结果,比较仓促,不一定对。

    commons-client 在windows和linux下性能相差比较大,怀疑和不同thread操作系统下的实现相关,明天我回公司做一下测试。

    spymemcached的set方法是异步的,他没有等待返回结果,所以比同步的get方法快,有点不公平,呵呵。

    spymemcached用了一些spy的底层实现,而且不是开源的,不好分析,头痛,明天具体测一下好了。

  12. #34 楼 · uniseraph · 2008-11-02 21:01

    raymond2006k writes:

    我花了点时间对 spmemcache 和 楼主的 commons-client 做了一下测试。测试代码采用楼主的源码中的测试代码写法。

    主要变量:线程数thread,最大值repeat。 我略微修改了一下楼主的MemcacheClient中的 测试代码, 将 write,read分开。

    key,value策略: key,value 相同,1 - repeat , 其中repeat是最大值

    (测试环境: 硬件:机器: 酷睿T2350,1.86G双核,2G内存。 系统1:XP,运行memcached客户端测试。 测试程序,JDK1.6.0_10, -Xmx=160m 系统2:Ubuntu 8.0.4,运行于VMWare虚拟机中。memcached 1.2.6 + libevent 1.3, memcached 进程 1个,32M内存,最大256并发连接 ) 引用 1  spymemcache测试结果

    1线程 write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=21367 , using time:468 read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3516 , using time:2844

    10线程 write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=14712 , using time:6797 read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=5258 , using time:19016

    50线程 write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=8355 , using time:59844 read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5631 , using time:88781

    2 commons-client测试结果

    1线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=2806 , using time:3563 INFO [main] (MemcachedClient.java:309) - read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3351 , using time:2984

    10线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=5855 , using time:17078 INFO [main] (MemcachedClient.java:309) - read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=4815 , using time:20765

    50线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=5856 , using time:85375 INFO [main] (MemcachedClient.java:309) - read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5612 , using time:89094

    测试结果可能没楼主的TPS大,只反映我机器上的结果。主要是有同样的测试基准才好对比。

    从测试结果看spymemcached的 velocity反映较好一些。spymemcache client, commons-client都 用了nio。 其中read性能表现较低,不知为什么?

    我将测试类附上,楼主可以分析一下结果。或者也对 spymemcache做做测试。

    测试类在那儿?

  13. #33 楼 · uniseraph · 2008-11-02 20:57

    raymond2006k writes:

    我花了点时间对 spmemcache 和 楼主的 commons-client 做了一下测试。测试代码采用楼主的源码中的测试代码写法。

    主要变量:线程数thread,最大值repeat。 我略微修改了一下楼主的MemcacheClient中的 测试代码, 将 write,read分开。

    key,value策略: key,value 相同,1 - repeat , 其中repeat是最大值

    (测试环境: 硬件:机器: 酷睿T2350,1.86G双核,2G内存。 系统1:XP,运行memcached客户端测试。 测试程序,JDK1.6.0_10, -Xmx=160m 系统2:Ubuntu 8.0.4,运行于VMWare虚拟机中。memcached 1.2.6 + libevent 1.3, memcached 进程 1个,32M内存,最大256并发连接 ) 引用 1  spymemcache测试结果

    1线程 write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=21367 , using time:468 read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3516 , using time:2844

    10线程 write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=14712 , using time:6797 read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=5258 , using time:19016

    50线程 write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=8355 , using time:59844 read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5631 , using time:88781

    2 commons-client测试结果

    1线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=2806 , using time:3563 INFO [main] (MemcachedClient.java:309) - read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3351 , using time:2984

    10线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=5855 , using time:17078 INFO [main] (MemcachedClient.java:309) - read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=4815 , using time:20765

    50线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=5856 , using time:85375 INFO [main] (MemcachedClient.java:309) - read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5612 , using time:89094

    测试结果可能没楼主的TPS大,只反映我机器上的结果。主要是有同样的测试基准才好对比。

    从测试结果看spymemcached的 velocity反映较好一些。spymemcache client, commons-client都 用了nio。 其中read性能表现较低,不知为什么?

    我将测试类附上,楼主可以分析一下结果。或者也对 spymemcache做做测试。

    多谢反馈,

    raymond2006k writes:

    我花了点时间对 spmemcache 和 楼主的 commons-client 做了一下测试。测试代码采用楼主的源码中的测试代码写法。

    主要变量:线程数thread,最大值repeat。 我略微修改了一下楼主的MemcacheClient中的 测试代码, 将 write,read分开。

    key,value策略: key,value 相同,1 - repeat , 其中repeat是最大值

    (测试环境: 硬件:机器: 酷睿T2350,1.86G双核,2G内存。 系统1:XP,运行memcached客户端测试。 测试程序,JDK1.6.0_10, -Xmx=160m 系统2:Ubuntu 8.0.4,运行于VMWare虚拟机中。memcached 1.2.6 + libevent 1.3, memcached 进程 1个,32M内存,最大256并发连接 ) 引用 1  spymemcache测试结果

    1线程 write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=21367 , using time:468 read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3516 , using time:2844

    10线程 write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=14712 , using time:6797 read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=5258 , using time:19016

    50线程 write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=8355 , using time:59844 read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5631 , using time:88781

    2 commons-client测试结果

    1线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=2806 , using time:3563 INFO [main] (MemcachedClient.java:309) - read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3351 , using time:2984

    10线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=5855 , using time:17078 INFO [main] (MemcachedClient.java:309) - read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=4815 , using time:20765

    50线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=5856 , using time:85375 INFO [main] (MemcachedClient.java:309) - read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5612 , using time:89094

    测试结果可能没楼主的TPS大,只反映我机器上的结果。主要是有同样的测试基准才好对比。

    从测试结果看spymemcached的 velocity反映较好一些。spymemcache client, commons-client都 用了nio。 其中read性能表现较低,不知为什么?

    我将测试类附上,楼主可以分析一下结果。或者也对 spymemcache做做测试。

    多谢反馈,我没有用windows测过,不知道有没有关系。另外你把线程数加到100试试。commons-client比较适合高并发的情况,并发不高反而没有优势。

    你测试时候的两个系统是在一台物理机器上么?

    spymemcached我没测试过,待会看看。

  14. #32 楼 · raymond2006k · 2008-11-02 16:38

    我花了点时间对 spmemcache 和 楼主的 commons-client 做了一下测试。测试代码采用楼主的源码中的测试代码写法。

    主要变量:线程数thread,最大值repeat。 我略微修改了一下楼主的MemcacheClient中的 测试代码, 将 write,read分开。

    key,value策略: key,value 相同,1 - repeat , 其中repeat是最大值

    (测试环境: 硬件:机器: 酷睿T2350,1.86G双核,2G内存。 系统1:XP,运行memcached客户端测试。 测试程序,JDK1.6.0_10, -Xmx=160m 系统2:Ubuntu 8.0.4,运行于VMWare虚拟机中。memcached 1.2.6 + libevent 1.3, memcached 进程 1个,32M内存,最大256并发连接 )

    1 spymemcache测试结果

    1线程 write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=21367 , using time:468 read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3516 , using time:2844

    10线程 write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=14712 , using time:6797 read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=5258 , using time:19016

    50线程 write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=8355 , using time:59844 read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5631 , using time:88781

    2 commons-client测试结果

    1线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=1, repeat=10000,size=1, all=10000 ,velocity=2806 , using time:3563 INFO [main] (MemcachedClient.java:309) - read test: thread num=1, repeat=10000,size=1, all=10000 ,velocity=3351 , using time:2984

    10线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=10, repeat=10000,size=1, all=100000 ,velocity=5855 , using time:17078 INFO [main] (MemcachedClient.java:309) - read test: thread num=10, repeat=10000,size=1, all=100000 ,velocity=4815 , using time:20765

    50线程 INFO [main] (MemcachedClient.java:282) - write test:thread num=50, repeat=10000,size=1, all=500000 ,velocity=5856 , using time:85375 INFO [main] (MemcachedClient.java:309) - read test: thread num=50, repeat=10000,size=1, all=500000 ,velocity=5612 , using time:89094

    测试结果可能没楼主的TPS大,只反映我机器上的结果。主要是有同样的测试基准才好对比。

    从测试结果看spymemcached的 velocity反映较好一些。spymemcache client, commons-client都 用了nio。 其中read性能表现较低,不知为什么?

    我将测试类附上,楼主可以分析一下结果。或者也对 spymemcache做做测试。

  15. #31 楼 · yeshucheng · 2008-11-02 01:51

    codeutil writes:

    javabean实现Externalizable 接口,自己实现byte转换,就可以不依赖描述信息。 bdb无非也是用bind接口来干同样的事情而已。

    [quote=sdh5724]最近,我陷入一个郁闷。 就是JAVA的序列化问题。 当你向MEMCACHED直接写序列化的对象的时候, 一个对象完整的描述将会被写进memcached。 那么如果写1000W个对象给memcached, 对象描述将会被写无数次。 序列化描述大小往往远远大于对象的实际数据的, 因此, 我们的内存就被大量这些信息浪费了。 谁解决了这个问题? 我在研究berkleydb java edition的解决方案。 这个问题对于内存节约使用是非常重要的。 我现在4台memcache机器吃了我20G内存, 再涨下去, 就要买机器了。 很不划算啊。[/quote]

    楼上的,看来你确实没有注意到这位朋友说的话。不妨可以一试。而且这位朋友已经实现了,呵呵

  16. #30 楼 · sdh5724 · 2008-11-01 18:31

    代码写算是还成吧。 不过, 缺乏考虑多SERVER的平衡, 有些地方我感觉过度设计了。 哈:)

  17. #29 楼 · uniseraph · 2008-11-01 02:56

    uniseraph writes:

    fly_hyp 写道我比较欣赏 uniseraph 的源代码没有一行注释。注释是少了点,不过还是有的,呵呵。不想写中文注释,不利于项目的以后发展,如果写英文注释,会打断思路,所以写得比较少,呵呵。不过我觉得现在的代码结构还是比较清晰的,需要注释的地方应该不多。欢迎指正。

    新的改动,可以自由选择maven or ant+ivy 编译/运行测试用例,呵呵。

  18. #28 楼 · uniseraph · 2008-11-01 02:47

    fly_hyp writes:

    我比较欣赏 uniseraph 的源代码没有一行注释。

    注释是少了点,不过还是有的,呵呵。

    不想写中文注释,不利于项目的以后发展,如果写英文注释,会打断思路,所以写得比较少,呵呵。

    不过我觉得现在的代码结构还是比较清晰的,需要注释的地方应该不多。

    欢迎指正。

  19. #27 楼 · fly_hyp · 2008-10-31 19:55

    我比较欣赏 uniseraph 的源代码没有一行注释。

  20. #26 楼 · tiyi · 2008-10-31 17:40

    转换成byte 的思想在网络协议里面非常常见,就是自己要实现数据序列化和反序列化了。不过跳脱sun给的好东西(真的是好又多,方便了,信息量就大了),可以精简很多数据。

评论功能维护中,当前仅展示历史评论。