Memcached跟Mysql数据存储测试对比

Memcached和Mysql数据存储测试对比

昨晚写了个关于Memcached和Mysql的数据存储与读取的数据对比,然后让服务器跑了一晚上,一直担心把电脑跑崩溃,还好没有,测试结果和预测的差不多。

      测试的平台是Memcached-1.4.13和MySql-14.14;

      访问数据库工具是iBatIS+JDBC;

      操作系统CentOS6;

      CPU:Pentium(R) Dual-Core  CPU      E5300  @ 2.60GHz双核;

      网络环境:本地自环回路;

      测试线程100条,每条线程分别进行100次读写,统计平均时间和总时间。

      最后的结论是Memcached的单独删除操作平均耗时是5~6ms,单独写操作平均耗时是2~3.5ms,单独读操作平均耗时是1.5~3ms,可见读操作和写操作的耗时基本上是一样的,这跟Memcached内部采用Hash查找算法有关吧,而删除操作是写和读的两倍的原因是删除操作要先查找再写,所以时间消耗是其两倍。

      而对Mysql的测试没有做关于delete操作和update操作的统计,只对insert和select操作进行了统计,而且数据表中的操作只有两个键,项越多,数据库越复杂,耗时应该更大。统计结果表明,向空数据表中写100条数据的平均耗时是39ms(一条一条的写,非批量写),向含有10240(10KB)条记录的数据库中读数据的情况为:单独读100条数据的平均耗时为:15ms~25ms,而批量读数据(一次读100条记录)的耗时是50~150ms,平均到每条记录的读取时间是0.5~1.5ms。

       心得体会:在进行数据库读数据的时候如果数据比较集中,建议先批量读出来存放到缓冲区,现在很多数据库访问工具都集成了对缓冲区的管理。在进行数据的分散读写操作的时候建议先采用缓冲操作,再进行对数据库的相应操作,使用本地内存缓冲的速度应该比Memcached更快。

下面附录上具体的测试结果,免得以后想用的时候又找不到了,我一向的收拾不好,而且忘性还很大,呵呵。

thread 40: runs: 100 stores of obj 10KB — avg time per req 3.64 ms (total: 364 ms)

thread 40: runs: 100 gets of obj 10KB — avg time per req 1.8 ms (total: 180 ms)

thread 41: runs: 100 deletes of obj 10KB — avg time per req 5.1 ms (total: 510 ms)

thread 41: runs: 100 stores of obj 10KB — avg time per req 3.33 ms (total: 333 ms)

thread 41: runs: 100 gets of obj 10KB — avg time per req 2.29 ms (total: 229 ms)

thread 42: runs: 100 deletes of obj 10KB — avg time per req 5.28 ms (total: 528 ms)

thread 42: runs: 100 stores of obj 10KB — avg time per req 3.64 ms (total: 364 ms)

thread 42: runs: 100 gets of obj 10KB — avg time per req 1.83 ms (total: 183 ms)

thread 43: runs: 100 deletes of obj 10KB — avg time per req 5.65 ms (total: 565 ms)

thread 43: runs: 100 stores of obj 10KB — avg time per req 3.29 ms (total: 329 ms)

thread 43: runs: 100 gets of obj 10KB — avg time per req 1.65 ms (total: 165 ms)

thread 44: runs: 100 deletes of obj 10KB — avg time per req 5.94 ms (total: 594 ms)

thread 44: runs: 100 stores of obj 10KB — avg time per req 2.98 ms (total: 298 ms)

thread 44: runs: 100 gets of obj 10KB — avg time per req 1.65 ms (total: 165 ms)

thread 45: runs: 100 deletes of obj 10KB — avg time per req 5.42 ms (total: 542 ms)

thread 45: runs: 100 stores of obj 10KB — avg time per req 2.93 ms (total: 293 ms)

thread 45: runs: 100 gets of obj 10KB — avg time per req 1.8 ms (total: 180 ms)

thread 46: runs: 100 deletes of obj 10KB — avg time per req 6.05 ms (total: 605 ms)

thread 46: runs: 100 stores of obj 10KB — avg time per req 3.43 ms (total: 343 ms)

thread 46: runs: 100 gets of obj 10KB — avg time per req 1.38 ms (total: 138 ms)

thread 47: runs: 100 deletes of obj 10KB — avg time per req 5.36 ms (total: 536 ms)

thread 47: runs: 100 stores of obj 10KB — avg time per req 3.06 ms (total: 306 ms)

thread 47: runs: 100 gets of obj 10KB — avg time per req 2.22 ms (total: 222 ms)

thread 48: runs: 100 deletes of obj 10KB — avg time per req 6.29 ms (total: 629 ms)

thread 48: runs: 100 stores of obj 10KB — avg time per req 2.62 ms (total: 262 ms)

thread 48: runs: 100 gets of obj 10KB — avg time per req 1.62 ms (total: 162 ms)

thread 49: runs: 100 deletes of obj 10KB — avg time per req 4.09 ms (total: 409 ms)

thread 49: runs: 100 stores of obj 10KB — avg time per req 3.34 ms (total: 334 ms)

thread 49: runs: 100 gets of obj 10KB — avg time per req 2.62 ms (total: 262 ms)

thread 50: runs: 100 deletes of obj 10KB — avg time per req 5.56 ms

Memcached跟Mysql数据存储测试对比

相关文章:

你感兴趣的文章:

标签云: