# Manticore 2.7.5 vs Sphinx 3.1.1

[Здесь](https://manticoresearch.com/blog/sphinx-3-vs-manticore-performance-benchmark/) мы провели бенчмарк Sphinx 3.0.2 против Manticore 2.6.2. Это было 8 месяцев назад, и с тех пор Manticore и Sphinx изменились. Как сказано в [анонсе Sphinx 3.0.3](http://sphinxsearch.com/blog/2018/03/31/sphinx-3-0-3-released/) Sphinx 3.0.3 работает до 2 раз быстрее по сравнению с 3.0.2, поэтому интересно провести ещё один бенчмарк. На этот раз давайте протестируем реальный набор данных — Hacker News comments.

The benchmark was conducted with the following conditions:
- [Набор отобранных комментариев Hacker News](https://zenodo.org/record/45901/export/xd#.XEqiuc8zaU0) 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 ядер
- 64 ГБ ОЗУ
- HDD
- Docker версии 17.05.0-ce, сборка 89658be
- Базовый образ для индексации и searchd — alpine:3.6
- Manticore Search был собран там, бинарные файлы Sphinx были загружены с сайта, так как нет открытого кода для сборки
- [stress-tester](http://github.com/Ivinco/stress-tester) для бенчмаркинга

The config is identical for Manticore and Sphinx:

```ini
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
}

```


### Indexation

Indexation took **682 секунды для Manticore** и **645 секунд для Sphinx**:

Manticore:

```bash
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:

```bash
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 %**.  

## Performance tests

---

Both instances were warmed up before testing. The indexes were of the same size and were fully in OS cache:

Manticore:

```bash
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:

```bash
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
```

### Test 1 - time to process top 1000 terms from the collection

First of all let's just run a simple test — how much it takes to find documents containing top 1000 terms from the collection:

```bash
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

```
**32.9 seconds for Sphinx** and **28.1 seconds for Manticore.**Итак в этом тесте **Manticore Search быстрее, чем Sphinx Search, на 16,7 %**.  

### Test 2 - top 1000 frequent terms from the collection broken down by groups (top 1-50, top 50-100 etc.)

Now let's see how Sphinx and Manticore are different in processing terms from sub-groups of the group of top 1000 frequent terms:

![](./manticore-2-7-5-vs-sphinx-3-1-1/test2_tp.png)
![](./manticore-2-7-5-vs-sphinx-3-1-1/test2_lat.png)

**Manticore быстрее, чем Sphinx, на 24 % по 95‑процентной задержке и на 21 % по пропускной способности.**  

### Test 3 - top 1000 frequent terms from the collection broken down by groups + 1 term from group 1-100

Let's test document sets intersection performance by adding one more frequent term to the query:

![](./manticore-2-7-5-vs-sphinx-3-1-1/test3_tp.png)
![](./manticore-2-7-5-vs-sphinx-3-1-1/test3_lat.png)

Снова Manticore быстрее, чем Sphinx, на 21 % по пропускной способности и в среднем на 13 % по 95‑процентной задержке. Хотя для групп 900‑950 и 950‑1000 Sphinx показал немного лучшую 95‑процентную задержку — 1,3 % и 4,6 % соответственно (но всё же пропускная способность была хуже — на 15 % и 14 % соответственно по сравнению с Manticore Search)

### Test 4 - top 1000 frequent terms from the collection broken down by groups + 1 term from group 1-100, both terms enclosed in quotes to make a phrase

![](./manticore-2-7-5-vs-sphinx-3-1-1/test4_tp.png)
![](./manticore-2-7-5-vs-sphinx-3-1-1/test4_lat.png)

В среднем Manticore снова быстрее: на 20 % по пропускной способности и на 11 % по 95‑процентной задержке. Как и в предыдущем тесте, Sphinx показывает более низкую 95‑процентную задержку для групп 850‑900, 900‑950 и 950‑1000 — на 1,4 %, 4,9 % и 4,9 % соответственно, однако пропускная способность всё ещё значительно ниже — на 14‑15 %.

### Test 5 - 2 terms each from group 600-750 under different concurrencies

This test aims to show the difference in throughput under different query concurrencies. Here's what we get:

![](./manticore-2-7-5-vs-sphinx-3-1-1/test5_tp.png)
![](./manticore-2-7-5-vs-sphinx-3-1-1/test5_lat.png)

Таким образом, Manticore быстрее при всех уровнях параллельности в среднем на 14 % и на 17 % при параллельности 8, что даёт максимальную пропускную способность при 95‑процентной задержке, сниженой также на 17 %.


# Conclusions

Sphinx демонстрирует немного лучшую производительность индексации.

С точки зрения производительности поиска Manticore 2.7.5 показывает значительно более высокую пропускную способность во всех тестах и гораздо более низкую задержку в подавляющем большинстве тестов.

Тест полностью докеризован и [открыт в нашем github](https://github.com/manticoresoftware/benchmarks/tree/master/hn_sphinx_manticore). Подробные результаты можно найти [здесь](https://docs.google.com/spreadsheets/d/17RuSzkkloMwMoqrOdo0FjdI5Z-lELSLWffW-mkS5RNU/edit#gid=794362147). Мы

будем признательны, если вы запустите те же тесты на вашем оборудовании или добавите разные тесты в набор и сообщите нам результаты.
