Memlink用于持久化存储论坛中forum=>thread list,thread=>post list数据,下面对比了不同数据存储引擎存储上述逻辑关系的查询性能和内存开销。
硬件
OS:CentOS release 4.6 (Final)
内存:4G
CPU:Intel(R) Xeon(R) CPU E5405 @ 2.00GHz (四核)
硬盘:250G SATA
数据模型
CREATE TABLE `ThreadList` ( `forumid` int(11) NOT NULL, `threadid` char(12) NOT NULL, `status` bit(1) DEFAULT 0, `reply_time` datetime NOT NULL, KEY `threadlist` (`forumid`,`reply_time`,`status`) ) ENGINE=Innodb DEFAULT CHARSET=utf8;
memlink
c:表示c客户端每秒操作成功条数,py:表示python客户端每秒操作成功条数,php:为php客户端每秒操作成功条数。mem:表示memlink server消耗内存。 insert为插入操作,range为获取列表某个范围的操作。插入的列表中的数据每条为12字节。
redis
redis测试一样每条数据是12字节。redis只测试c客户端,使用hiredis。用LRANGE命令获取列表,用LPUSH向队列插入数据。redis是默认配置。
mysql
mysql使用上面的数据库表结构。插入语句为:insert into ThreadList values (1, 'xxxx', 0, now()) 查询列表的语句为:select threadid from ThreadList where forumid=1 order by reply_time limit frompos,len
1. 一个客户端,长连接
memlink
操作 | 1w | 10w | 100w | 1000w |
insert mem:4764K | c:16296 py:12558 php:12153 mem:5032K | c:14125 py:12565 php:12144 mem:6628K | c:13868 py: 13096 php: 12521 mem:18M | c:13187 py:12611 php:12124 mem:139M |
range first100 | c:10874 py:8275 php:9185 | c:11429 py:8273 php:9171 | c:10994 py:8068 php:9136 | c:11663 py:8256 php:10071 |
range first200 | c:8045 py:6015 php:6544 | c:8041 py:6017 php:6545 | c:7863 py:5941 php:6542 | c:7970 py:6024 php:7010 |
range first1000 | c:1362 py:1446 php:1466 | c:1362 py:1448 php:1468 | c:1354 py:1440 php:1462 | c:1362 py:1444 php:1492 |
range last100 | c:11153 py:8137 php:8996 | c:10318 py:7526 php:8263 | c:5519 py:4410 php:4691 | c:112 py:97 php:97 |
range last200 | c:7938 py:5956 php:6461 | c:7515 py:5629 php:6078 | c:4615 py:3688 php:3899 | c:111 py:96 php:97 |
range last1000 | c:1358 py:1442 php:1458 | c:1345 py:1421 php:1440 | c:1209 py:1251 php:1272 | c:103 py:91 php:91 |
redis
操作 | 1w | 10w | 100w | 1000w |
insert mem:1060K | 15183 mem:1920K | 14997 mem:9044 | 14828 mem:78M | 14788 mem:771M |
range first100 | 1328 | 1329 | 1324 | 1332 |
range first200 | 708 | 709 | 705 | 709 |
range first1000 | 147 | 148 | 148 | 147 |
range last100 | 1221 | 212 | 19 | 2 |
range last200 | 675 | 184 | 19 | 2 |
range last1000 | 147 | 92 | 17 | 2 |
mysql
操作 | 1w | 10w | 100w | 1000w |
insert | 10891 | 10297 | 10022 | 9718 |
range first100 | 1550 | 1563 | 1559 | 1307 |
range first200 | 956 | 954 | 956 | 941 |
range first1000 | 230 | 230 | 230 | 235 |
range last100 | 31 | 3 | 0.3 | 0.04 |
range last200 | 31 | 3 | 0.3 | 0.04 |
range last1000 | 30 | 3 | 0.3 | 0.03 |
2. 一个客户端, 全部是短连接。一次请求一个连接。
memlink
操作 | 1w | 10w | 100w | 1000w |
insert mem:4760K | c:6560 py:6138 php:6064 mem:5108K | c:6466 py:5990 php:5986 mem:6704K | c:6675 py:6092 php:6010 mem:18M | c:6719 py:6012 php:6003 mem:139M |
range first100 | c:5467 py:4535 php:5064 | c:5472 py:4450 php:4944 | c:5662 py:4495 php:4712 | c:5484 py:4475 php:4779 |
range first200 | c:4533 py:3746 php:4124 | c:4563 py:3693 php:4049 | c:4709 py:3724 php:3893 | c:4567 py:3708 php:3931 |
range first1000 | c:1206 py:1254 php:1291 | c:1200 py:1249 php:1285 | c:1215 py:1253 php:1263 | c:1202 py:1250 php:1266 |
range last100 | c:5468 py:4451 php:4970 | c:5229 py:4233 php:4692 | c:3763 py:3055 php:3155 | c:110 py:96 php:96 |
range last200 | c:4558 py:3692 php:4053 | c:4355 py:3545 php:3886 | c:3323 py:2680 php:2790 | c:110 py:95 php:96 |
range last1000 | c:1198 py:1247 php:1284 | c:1191 py:1226 php:1267 | c:1096 py:1093 php:1125 | c:102 py:91 php:91 |
redis
操作 | 1w | 10w | 100w | 1000w |
insert | 10891 | 10297 | 10233 | 10135 |
range first100 | 1058 | 1172 | 1166 | 1163 |
range first200 | 654 | 651 | 669 | 667 |
range first1000 | 146 | 145 | 145 | 144 |
range last100 | 994 | 271 | 32 | 3 |
range last200 | 630 | 233 | 32 | 3 |
range last1000 | 144 | 104 | 27 | 3 |
mysql
操作 | 1w | 10w | 100w | 1000w |
insert | 3313 | 3251 | 3108 | 3001 |
range first100 | 923 | 1158 | 1031 | 885 |
range first200 | 815 | 823 | 783 | 743 |
range first1000 | 227 | 230 | 226 | 212 |
range last100 | 20 | 3 | 0.21 | 0.02 |
range last200 | 30 | 3 | 0.3 | 0.04 |
range last1000 | 30 | 3 | 0.3 | 0.03 |
3. 10个客户端,并发长连接。
memlink内部开启4个处理线程。仅c客户端测试。
操作 | 1w | 10w | 100w | 1000w |
insert | 23021 | 22210 | 22200 | 22242 |
range first100 | 45451 | 53463 | 55645 | 48283 |
range first200 | 23768 | 33966 | 35045 | 35417 |
range first1000 | 4269 | 4305 | 4281 | 4271 |
range last100 | 53719 | 48948 | 24086 | 295 |
range last200 | 35593 | 34264 | 21830 | 292 |
range last1000 | 4285 | 4270 | 4336 | 277 |
redis
操作 | 1w | 10w | 100w | 1000w |
insert | 29401 | 30929 | 29109 | 30278 |
range first100 | 1443 | 1384 | 1396 | 1339 |
range first200 | 667 | 641 | 636 | 655 |
range first1000 | 114 | 115 | 114 | 115 |
range last100 | 1584 | 229 | 19 | 2 |
range last200 | 696 | 220 | 19 | 2 |
range last1000 | 114 | 142 | 19 | 2 |
mysql
操作 | 1w | 10w | 100w | 1000w |
insert | 13704 | 12786 | 12087 | 11023 |
range first100 | 2011 | 2059 | 2015 | 2387 |
range first200 | 1637 | 1768 | 1854 | 1614 |
range first1000 | 654 | 641 | 648 | 631 |
range last100 | 91 | 8 | 1 | - |
range last200 | 96 | 9 | 1 | - |
range last1000 | 91 | 8 | 1 | - |
上面的 - 表示时间太长,数百秒也没有结果。
4. 10个客户端,并发短连接
Memlink内部开启4个处理线程。仅c客户端测试。
操作 | 1w | 10w | 100w | 1000w |
insert | 9665 | 9650 | 10078 | 10183 |
range first100 | 17400 | 17504 | 16614 | 17292 |
range first200 | 15786 | 15772 | 15964 | 16180 |
range first1000 | 3795 | 3918 | 3703 | 3250 |
range last100 | 16989 | 16502 | 13118 | 319 |
range last200 | 15915 | 15596 | 12203 | 316 |
range last1000 | 3893 | 3641 | 3332 | 299 |
redis
操作 | 1w | 10w | 100w | 1000w |
insert | 9381 | 9489 | 8993 | 8976 |
range first100 | 1695 | 1637 | 1696 | 1586 |
range first200 | 711 | 711 | 719 | 692 |
range first1000 | 118 | 115 | 116 | 114 |
range last100 | 2132 | 240 | 20 | 2 |
range last200 | 743 | 229 | 20 | 2 |
range last1000 | 120 | 174 | 19 | 2 |
mysql
操作 | 1w | 10w | 100w | 1000w |
insert | 5623 | 5621 | 5468 | 5306 |
range first100 | 2210 | 2286 | 1955 | 1611 |
range first200 | 1444 | 1791 | 1870 | 1402 |
range first1000 | 550 | 692 | 620 | 686 |
range last100 | 80 | 8 | 1 | - |
range last200 | 94 | 9 | 1 | - |
range last1000 | 94 | 9 | 1 | - |