在这里 我们对比测试了 Sphinx 3.0.2 和 Manticore 2.6.2。那是8个月前的事了,从那时起 Manticore 和 Sphinx 都有所变化。正如 Sphinx 3.0.3 发布公告 所说,Sphinx 3.0.3 相比 3.0.2 速度提升了2倍,所以再做一次基准测试很有意思。这次让我们用真实数据集 - Hacker News 评论来测试。
基准测试在以下条件下进行:
- Hacker News 精选评论数据集 2016年的 CSV 格式数据
- 操作系统: 16.04.4 LTS (Xenial Xerus), 内核: 4.15.0-30-generic
- CPU: Intel(R) Xeon(R) CPU E3-1275 v5 @ 3.60GHz, 8核
- 64G 内存
- HDD 硬盘
- Docker 版本 17.05.0-ce, build 89658be
- 索引和 searchd 的基础镜像 - alpine:3.6
- Manticore Search 在此环境下编译,Sphinx 二进制文件从官网下载因为没有开源代码可供编译
- 使用 stress-tester 做基准测试
Manticore 和 Sphinx 使用相同的配置:
source full
{
type = csvpipe
csvpipe_command = cat /root/hacker_news_comments.prepared.csv|grep -v line_number
csvpipe_attr_uint = story_id
csvpipe_attr_timestamp = story_time
csvpipe_field = story_text
csvpipe_field = story_author
csvpipe_attr_uint = comment_id
csvpipe_field = comment_text
csvpipe_field = comment_author
csvpipe_attr_uint = comment_ranking
csvpipe_attr_uint = author_comment_count
csvpipe_attr_uint = story_comment_count
}
index full
{
path = /root/idx_full
source = full
html_strip = 1
mlock = 1
}
searchd
{
listen = 9306:mysql41
query_log = /root/query.log
log = /root/searchd.log
pid_file = /root/searchd.pid
binlog_path =
qcache_max_bytes = 0
}
索引创建
索引创建耗时 Manticore 682秒, Sphinx 645秒:
Manticore:
indexing index 'full'...
collected 11654429 docs, 6198.6 MB
sorted 1115.7 Mhits, 100.0% done
total 11654429 docs, 6198580642 bytes
total <b>681.732 sec</b>, 9092389 bytes/sec, 17095.30 docs/sec
total 11676 reads, 1.811 sec, 452.6 kb/call avg, 0.1 msec/call avg
total 9431 writes, 4.878 sec, 1065.3 kb/call avg, 0.5 msec/call avg
Sphinx:
using config file '/root/manticore.conf'...
indexing index 'full'...
collected 11654429 docs, 6198.6 MB
sorted 1115.7 Mhits, 100.0% done
total 11654429 docs, 6.199 Gb
total <b>645.7 sec</b>, 9.600 Mb/sec, 18049 docs/sec
所以在这个数据集和索引方案下,Manticore 的索引速度比 Sphinx 慢 5.6%。
性能测试
测试前两个实例都进行了预热。索引大小相同且都完全在操作系统缓存中:
Manticore:
snikolaev@dev:~$ sudo ls -lah /var/lib/docker/volumes/4702617c7b0d970ba660514053706125fd88f2a4b7fce7222aab1f53fba2b56d/_data/
total 4.6G
drwx------ 2 root root 4.0K Jan 25 04:50 .
drwxr-xr-x 3 root root 4.0K Jan 25 04:43 ..
-rw-r--r-- 1 root root 362M Jan 25 03:51 idx_full.spa
-rw-r--r-- 1 root root 3.1G Jan 25 03:56 idx_full.spd
-rw-r--r-- 1 root root 27M Jan 25 03:56 idx_full.spe
-rw-r--r-- 1 root root 601 Jan 25 03:56 idx_full.sph
-rw-r--r-- 1 root root 6.3M Jan 25 03:56 idx_full.spi
-rw-r--r-- 1 root root 0 Jan 25 03:51 idx_full.spk
-rw------- 1 root root 0 Jan 25 04:50 idx_full.spl
-rw-r--r-- 1 root root 0 Jan 25 03:51 idx_full.spm
-rw-r--r-- 1 root root 1.1G Jan 25 03:56 idx_full.spp
-rw-r--r-- 1 root root 1 Jan 25 03:56 idx_full.sps
-rw-rw-r-- 1 root root 750 Jan 25 03:27 manticore.conf
lrwxrwxrwx 1 root root 11 Jan 25 03:57 query.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Jan 25 03:57 searchd.log -> /dev/stdout
-rw------- 1 root root 2 Jan 25 04:50 searchd.pid
snikolaev@dev:~$ sudo vmtouch /var/lib/docker/volumes/4702617c7b0d970ba660514053706125fd88f2a4b7fce7222aab1f53fba2b56d/_data/
vmtouch: WARNING: not following symbolic link /var/lib/docker/volumes/4702617c7b0d970ba660514053706125fd88f2a4b7fce7222aab1f53fba2b56d/_data/searchd.log
vmtouch: WARNING: not following symbolic link /var/lib/docker/volumes/4702617c7b0d970ba660514053706125fd88f2a4b7fce7222aab1f53fba2b56d/_data/query.log
Files: 12
Directories: 1
Resident Pages: 1190485/1190682 4G/4G 100%
Elapsed: 0.070337 seconds
Sphinx:
snikolaev@dev:~$ sudo ls -lah /var/lib/docker/volumes/0aa7c89baeaa4c1bd2c52d2fbffe6f05fde5f43243534d5725482a702a90fd5b/_data
total 4.6G
drwx------ 3 root root 4.0K Jan 25 04:50 .
drwxr-xr-x 3 root root 4.0K Jan 25 04:43 ..
-rw-r--r-- 1 root root 362M Jan 25 03:37 idx_full.spa
-rw-r--r-- 1 root root 3.1G Jan 25 03:41 idx_full.spd
-rw-r--r-- 1 root root 27M Jan 25 03:41 idx_full.spe
-rw-r--r-- 1 root root 648 Jan 25 03:41 idx_full.sph
-rw-r--r-- 1 root root 6.3M Jan 25 03:41 idx_full.spi
-rw-r--r-- 1 root root 8 Jan 25 03:37 idx_full.spj
-rw-r--r-- 1 root root 1.4M Jan 25 03:37 idx_full.spk
-rw------- 1 root root 0 Jan 25 04:50 idx_full.spl
-rw-r--r-- 1 root root 1.1G Jan 25 03:41 idx_full.spp
-rw-rw-r-- 1 root root 750 Jan 25 03:27 manticore.conf
lrwxrwxrwx 1 root root 11 Jan 25 03:42 query.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Jan 25 03:42 searchd.log -> /dev/stdout
-rw------- 1 root root 2 Jan 25 04:50 searchd.pid
drwxr-sr-x 8 root root 4.0K Jan 23 08:01 sphinx-3.1.1
snikolaev@dev:~$ sudo vmtouch /var/lib/docker/volumes/0aa7c89baeaa4c1bd2c52d2fbffe6f05fde5f43243534d5725482a702a90fd5b/_data
vmtouch: WARNING: not following symbolic link /var/lib/docker/volumes/0aa7c89baeaa4c1bd2c52d2fbffe6f05fde5f43243534d5725482a702a90fd5b/_data/searchd.log
vmtouch: WARNING: not following symbolic link /var/lib/docker/volumes/0aa7c89baeaa4c1bd2c52d2fbffe6f05fde5f43243534d5725482a702a90fd5b/_data/query.log
Files: 156
Directories: 18
Resident Pages: 1195648/1210212 4G/4G 98.8%
Elapsed: 0.075835 seconds
测试1 - 处理集合中前1000个词的时间
首先让我们运行一个简单的测试 - 找出包含集合中前1000个最常见词的文档需要多长时间:
for n in `head -1000 hn_top.txt|awk '{print $1}'`; do
mysql -P9306 -hhn_$engine -e "select * from full where match('@(comment_text,story_text,comment_author,story_author) $n') limit 10 option max_matches=1000" > /dev/null
done
结果是:Sphinx 32.9秒,Manticore 28.1秒。所以在这个测试中Manticore Search 比 Sphinx Search 快16.7%。
测试2 - 将集合中前1000个高频词按组分类(前1-50,50-100等)
现在让我们看看 Sphinx 和 Manticore 在处理前1000个高频词的不同子组时有什么不同:
Manticore 比 Sphinx 在95%延迟上快24%,在吞吐量上快21%。
测试3 - 集合中前1000个高频词按组分类 + 来自1-100组的1个词
让我们通过添加另一个高频词来测试文档集的交集性能:
Manticore 再次比 Sphinx 在吞吐量上快21%,在95%延迟上平均快13%。虽然在900-950和950-1000组中,Sphinx 显示出略好的95%延迟 - 分别快1.3%和4.6%(但吞吐量仍然比 Manticore Search 分别低15%和14%)
测试4 - 集合中前1000个高频词按组分类 + 来自1-100组的1个词,两个词都用引号括起来形成短语
平均而言 Manticore 再次更快:吞吐量快20%,95%延迟快11%。与上一个测试一样,Sphinx 在850-900、900-950和950-1000组的95%延迟较低 - 分别为1.4%、4.9%和4.9%,但吞吐量仍然显著低14-15%。
测试5 - 来自600-750组的2个词在不同并发度下的测试
这个测试旨在显示不同查询并发度下吞吐量的差异。以下是我们得到的结果:
因此,Manticore 在所有并发度下平均快14%,在并发度为8时快17%,同时95%延迟也低17%。
结论
Sphinx 显示出略好的索引性能。
在搜索性能方面,Manticore 2.7.5在所有测试中显示出更高的吞吐量,在绝大多数测试中延迟也更低。
该测试完全容器化并 在我们的github开源 。详细结果可以在 这里 找到。如果您能在您的硬件上运行相同的测试或向测试套件添加不同的测试并让我们知道结果,我们将非常感谢。
感谢阅读!