memcached performance性能到底有多快
今天写了个Java程序从 MySQL 读入数据,然后写到LAN中另外一台Server的 memcached, 通过memcached Java Client API进行访问,瓶颈明显在 memcached 这边,MySQL 读入数据用我前几天改进的 limit 改进方法速度太快了,根本不用关心。程序测试当中发现memcached RPS最高达到20k,以为问题解决了,后来又发现是统计方法错误,最后优化再优化RPS结果是6,666。 好数字,可惜没达到我的期望值。
测试写入数据
1 million, 100 万条
key = Integer
Value = 32个字节的 string
Client 环境
线程: 5个,发现再加线程也没有用了
Java 5.0
Windows XP
CPU: P4 2.8G
CPU 占用率:> 60%
Memcached 环境
CPU: Xeon 3G
CPU 占用率:< 20%
RAM: 1024M for memcached
Linux 64-bit
LAN: 1G
疑问:
1. set 能不能批量写?现在每次只能写一条,据说 Get 可以批量返回结果。
2. client api 为什么每个 set 都需要复杂的计算使用哪个 connection, 为什么 connection 不能重用?
3. 为什么client增加线程不起作用?为什么client CPU占用率高,感觉 Java Client API有问题。
我期望的结果应该要10k以上,因为client/server之间是重用连接,就象http keep-alive一样,网络的开销应该非常小。
摘录自作者的一段话
A final optimization worth noting is that the protocol allows fetching multiple keys at once. This is useful if your application knows it needs to load a few hundred keys. Instead of retrieving them all sequentially, which would take a fraction of a second in network round-trips, the application can fetch them all in one request. When necessary, the client libraries automatically split multi-key loads from the application into separate parallel multi-key loads to the Memcached instances. Alternatively, applications can provide explicit hash values with keys to keep groups of data on the same instance. That also saves the client library a bit of CPU time by not needing to calculate hash values.
原文:http://www.linuxjournal.com/article/7451
网上另外还有个人比较每种语言的速度,得出的结论是php client最快,可惜他的CPU太慢(P3 650),样本空间太小(1万条),线程比我多(20个),最后他的结果最快的速度是我的1/100,所以他这个结果对我来说没什么借鉴意义。
http://dealnews.com/developers/memcached.html
有时间还要进一步分析。
测试写入数据
1 million, 100 万条
key = Integer
Value = 32个字节的 string
Client 环境
线程: 5个,发现再加线程也没有用了
Java 5.0
Windows XP
CPU: P4 2.8G
CPU 占用率:> 60%
Memcached 环境
CPU: Xeon 3G
CPU 占用率:< 20%
RAM: 1024M for memcached
Linux 64-bit
LAN: 1G
疑问:
1. set 能不能批量写?现在每次只能写一条,据说 Get 可以批量返回结果。
2. client api 为什么每个 set 都需要复杂的计算使用哪个 connection, 为什么 connection 不能重用?
3. 为什么client增加线程不起作用?为什么client CPU占用率高,感觉 Java Client API有问题。
我期望的结果应该要10k以上,因为client/server之间是重用连接,就象http keep-alive一样,网络的开销应该非常小。
摘录自作者的一段话
A final optimization worth noting is that the protocol allows fetching multiple keys at once. This is useful if your application knows it needs to load a few hundred keys. Instead of retrieving them all sequentially, which would take a fraction of a second in network round-trips, the application can fetch them all in one request. When necessary, the client libraries automatically split multi-key loads from the application into separate parallel multi-key loads to the Memcached instances. Alternatively, applications can provide explicit hash values with keys to keep groups of data on the same instance. That also saves the client library a bit of CPU time by not needing to calculate hash values.
原文:http://www.linuxjournal.com/article/7451
网上另外还有个人比较每种语言的速度,得出的结论是php client最快,可惜他的CPU太慢(P3 650),样本空间太小(1万条),线程比我多(20个),最后他的结果最快的速度是我的1/100,所以他这个结果对我来说没什么借鉴意义。
http://dealnews.com/developers/memcached.html
有时间还要进一步分析。