110 million comments from Hacker News benchmark
Published: 2022-05-31 15:03:47



## Intro

In this article we’ll observe another test added to https://db-benchmarks.com/ — 1.1M Hacker News curated comments with numeric fields from https://zenodo.org/record/45901 multiplied by 100.

## Data collection

The source of the data collection is https://zenodo.org/record/45901.

The record structure is:

```
"properties": {
   "story_id": {"type": "integer"},
   "story_text": {"type": "text"},
   "story_author": {"type": "text", "fields": {"raw": {"type":"keyword"}}},
   "comment_id": {"type": "integer"},
   "comment_text": {"type": "text"},
   "comment_author": {"type": "text", "fields": {"raw": {"type":"keyword"}}},
   "comment_ranking": {"type": "integer"},
   "author_comment_count": {"type": "integer"},
   "story_comment_count": {"type": "integer"}
}
```

## Databases
So far we have made this test available for 3 databases:

- [Clickhouse](https://github.com/ClickHouse/ClickHouse) - a powerful OLAP database,
- [Elasticsearch](https://github.com/elastic/elasticsearch) - general purpose “search and analytics engine”,
- [Manticore Search](https://github.com/manticoresoftware/manticoresearch/) - “database for search”, Elasticsearch alternative.

In this test we make **as little changes to database default settings as possible** to not give either of them an unfair advantage. Testing at max tuning is no less important, but it's a subject for another benchmark. Here we want to understand what latency a regular non-experienced user can get after just installing a database and running it with its default settings. But to make it fair to compare one with another we still had to change a few settings:

- Clickhouse: [no tuning](https://github.com/db-benchmarks/db-benchmarks/blob/main/tests/hn/ch/init) , just `CREATE TABLE ... ENGINE = MergeTree() ORDER BY id` and standard [clickhouse-server](https://github.com/db-benchmarks/db-benchmarks/blob/main/docker-compose.yml) docker image.
- Elasticsearch: as we saw in [another test](https://db-benchmarks.com/test-logs10m/#elasticsearch-with-no-tuning-vs-tuned) sharding can help Elasticsearch signficantly, so given 100+ M documents is not the smallest dataset we decided it would be more fair to:
 - let Elasticsearch make [32 shards](https://github.com/db-benchmarks/db-benchmarks/tree/main/tests/hn/es/logstash_tuned) : (`"number_of_shards": 32`), otherwise it couldn’t utilize the CPU which has 32 cores on the server, since as [said](https://www.elastic.co/guide/en/elasticsearch/reference/current/size-your-shards.html#single-thread-per-shard) in Elasticsearch official guide “Each shard runs the search on a single CPU thread”.
 - we also tuned it by setting `bootstrap.memory_lock=true` since as said on https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_disable_swapping it needs to be done for performance.
 - the docker image is [standard](https://github.com/db-benchmarks/db-benchmarks/blob/main/docker-compose.yml)

- Manticore Search is also used in a form of [their official docker image + the columnar library they provide.](https://github.com/db-benchmarks/db-benchmarks/blob/main/docker-compose.yml) The following updates have been [made](https://github.com/db-benchmarks/db-benchmarks/blob/main/tests/hn/manticore/generate_manticore_config.php) to their defaults:
 - `min_infix_len = 2` since in Elasticsearch by default you can do infix full-text search and it would be not fair to let Manticore run in lighter mode (w/o infixes). Unfortunately it’s not possible in Clickhouse at all, so it’s given the handicap.
 - `secondary_indexes = 1` which enables secondary indexes while filtering (when loading data that’s built anyway). Since Elasticsearch uses secondary indexes by default and it’s fairly easy to enable the same in Manticore it makes sense to do it. Unfortunately in Clickhouse user would have to make quite an effort to do the same, hence it’s not done, since it would then be considered a heavy tuning which would then require further tuning of the other databases which would make things too complicated and unfair.
 - we tested Manticore in two modes:

 1. row-wise storage which is a default one, therefore is worth testing
 2.   columnar storage: the data collection is of medium size, so provided Elasticsearch and Clickhouse internally use column-oriented structures it seems fair to compare them with Manticore’s columnar storage too.

## About caches

We've also configured the databases to not use any internal caches. Why this is important:
1. In this benchmark, we conduct an **accurate latency measurement** to find out what response time users can expect if they run one of the tested queries at a random moment, not after running the same query many times consequently.
2. Any cache is a shortcut to low latency. As written in [Wikipedia](https://en.wikipedia.org/wiki/Cache_(computing)) "cache stores data so that future requests for that data can be served faster". But caches are different, they can be divided into 2 main groups:
   - 👌 those that just cache raw data stored on disk. For example many databases use `mmap()` to map the data stored on disk to memory, access it easily and let the operating system take care about the rest (reading it from disk when there's free memory, removing it from memory when it's needed for something more important etc). This is ok in terms of performance testing, because we let **each** database leverage the benefit of using the OS page cache (or its internal similar cache that just reads data from disk)
     **That's exactly what we do in this benchmark.**
   - ❗ those that are used to save results of previous calculations. And it's fine in many cases, but in terms of this benchmark letting database enable such a cache is a bad idea, because:
     - it breaks proper measuring: instead of measuring calculation time you start measuring how long it takes to find a value by a key in memory. It's not something we want to do in this test (but it's interesting in general and we'll perhaps do it in the future and publish some article "Benchmark of caches").
     - even if they save not a full result of a particular query, but results of its sub-calculations it's not good, because it breaks the idea of the test - "what response time users can expect if they run one of the tested queries at a random moment".
     - some databases have such a cache (it's usually called "query cache"), others don't so if we don't disable database internal caches we'll give an unfair advantage to those having that.

     So we do everything to make sure none of the database does this kind of caching.

What exactly we do to achieve that:

- Clickhouse:
 - `SYSTEM DROP MARK CACHE`, `SYSTEM DROP UNCOMPRESSED CACHE`, `SYSTEM DROP COMPILED EXPRESSION CACHE` [before testing each new query](https://github.com/db-benchmarks/db-benchmarks/blob/main/plugins/clickhouse.php) (not each attempt of the same query).

- Elasticsearch:
 - `"index.queries.cache.enabled": false` in its configuration
 - `/_cache/clear?request=true&query=true&fielddata=true` [before testing each new query](https://github.com/db-benchmarks/db-benchmarks/blob/main/plugins/elasticsearch.php)(not each attempt of the same query).

- Manticore Search (in configuration file):
 - `qcache_max_bytes = 0`
 - `docstore_cache_size = 0`

- Operating system:
 - we do `echo 3 > /proc/sys/vm/drop_caches; sync` before each **NEW** query (**NOT** each attempt). I.e. for each new query we:
    - stop database
    - drop OS cache
    - start it back
    - make the very first cold query and measure its time
    - and make tens more attempts (up to 100 or until the coefficient of variation is low enough to consider the test results high quality)

## Queries
The query set consists of both full-text and analytical (filtering, sorting, grouping, aggregating) queries:

```
[
"select count(*) from hn",
"select count(*) from hn where comment_ranking=100",
"select count(*) from hn where comment_ranking=500",
"select count(*) from hn where comment_ranking > 300 and comment_ranking < 500",
"select story_author, count(*) from hn group by story_author order by count(*) desc limit 20",
"select story_author, avg(comment_ranking) avg from hn group by story_author order by avg desc limit 20",
"select comment_ranking, count(*) from hn group by comment_ranking order by count(*) desc limit 20",
"select comment_ranking, avg(author_comment_count) avg from hn group by comment_ranking order by avg desc, comment_ranking desc limit 20",
"select comment_ranking, avg(author_comment_count+story_comment_count) avg from hn group by comment_ranking order by avg desc, comment_ranking desc limit 20",
"select comment_ranking, avg(author_comment_count+story_comment_count) avg from hn where comment_ranking < 10 group by comment_ranking order by avg desc, comment_ranking desc limit 20",
{
    "manticoresearch": "select comment_ranking, avg(author_comment_count) avg from hn where match('google') group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "clickhouse": "select comment_ranking, avg(author_comment_count) avg from hn where (match(story_text, '(?i)\\Wgoogle\\W') or match(story_author,'(?i)\\Wgoogle\\W') or match(comment_text, '(?i)\\Wgoogle\\W') or match(comment_author, '(?i)\\Wgoogle\\W')) group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "elasticsearch": "select comment_ranking, avg(author_comment_count) avg from hn where query('google') group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "mysql": "select comment_ranking, avg(author_comment_count) avg from hn where match(story_text,story_author,comment_text,comment_author) against ('google') group by comment_ranking order by avg desc, comment_ranking desc limit 20"
},
{
    "manticoresearch": "select comment_ranking, avg(author_comment_count) avg from hn where match('google') and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "clickhouse":"select comment_ranking, avg(author_comment_count) avg from hn where (match(story_text, '(?i)\\Wgoogle\\W') or match(story_author,'(?i)\\Wgoogle\\W') or match(comment_text, '(?i)\\Wgoogle\\W') or match(comment_author, '(?i)\\Wgoogle\\W')) and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "elasticsearch":"select comment_ranking, avg(author_comment_count) avg from hn where query('google') and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "mysql":"select comment_ranking, avg(author_comment_count) avg from hn where match(story_text,story_author,comment_text,comment_author) against ('google') and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20"
},
{
    "manticoresearch": "select comment_ranking, avg(author_comment_count+story_comment_count) avg from hn where match('google') and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "clickhouse": "select comment_ranking, avg(author_comment_count+story_comment_count) avg from hn where (match(story_text, '(?i)\\Wgoogle\\W') or match(story_author,'(?i)\\Wgoogle\\W') or match(comment_text, '(?i)\\Wgoogle\\W') or match(comment_author, '(?i)\\Wgoogle\\W')) and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "elasticsearch": "select comment_ranking, avg(author_comment_count+story_comment_count) avg from hn where query('google') and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20",
    "mysql": "select comment_ranking, avg(author_comment_count+story_comment_count) avg from hn where match(story_text,story_author,comment_text,comment_author) against ('google') and comment_ranking > 200 group by comment_ranking order by avg desc, comment_ranking desc limit 20"
},
{
    "manticoresearch": "select * from hn where match('abc') limit 20",
    "clickhouse": "select * from hn where (match(story_text, '(?i)\\Wabc\\W') or match(story_author,'(?i)\\Wabc\\W') or match(comment_text, '(?i)\\Wabc\\W') or match(comment_author, '(?i)\\Wabc\\W')) limit 20",
    "elasticsearch": "select * from hn where query('abc') limit 20",
    "mysql": "select * from hn where match(story_text,story_author,comment_text,comment_author) against ('google') limit 20"
},
{
    "manticoresearch": "select * from hn where match('abc -google') limit 20",
    "clickhouse": "select * from hn where (match(story_text, '(?i)\\Wabc\\W') or match(story_author,'(?i)\\Wabc\\W') or match(comment_text, '(?i)\\Wabc\\W') or match(comment_author, '(?i)\\Wabc\\W')) and not (match(story_text, '(?i)\\Wgoogle\\W') or match(story_author,'(?i)\\Wgoogle\\W') or match(comment_text, '(?i)\\Wgoogle\\W') or match(comment_author, '(?i)\\Wgoogle\\W')) limit 20",
    "elasticsearch": "select * from hn where query('abc !google') limit 20",
    "mysql": "select * from hn where match(story_text,story_author,comment_text,comment_author) against ('abc -google') limit 20"
},
{
    "manticoresearch": "select * from hn where match('\"elon musk\"') limit 20",
    "clickhouse": "select * from hn where (match(story_text, '(?i)\\Welon\\Wmusk\\W') or match(story_author,'(?i)\\Welon\\Wmusk\\W') or match(comment_text, '(?i)\\Welon\\Wmusk\\W') or match(comment_author, '(?i)\\Welon\\Wmusk\\W')) limit 20",
    "elasticsearch": "select * from hn where query('\\\"elon musk\\\"') limit 20",
    "mysql": "select * from hn where match(story_text,story_author,comment_text,comment_author) against ('\"elon musk\"') limit 20"
},
{
    "manticoresearch": "select * from hn where match('abc') order by comment_ranking asc limit 20",
    "clickhouse": "select * from hn where (match(story_text, '(?i)\\Wabc\\W') or match(story_author,'(?i)\\Wabc\\W') or match(comment_text, '(?i)\\Wabc\\W') or match(comment_author, '(?i)\\Wabc\\W')) order by comment_ranking asc limit 20",
    "elasticsearch": "select * from hn where query('abc') order by comment_ranking asc limit 20",
    "mysql": "select * from hn where match(story_text,story_author,comment_text,comment_author) against ('abc') order by comment_ranking asc limit 20"
},
{
    "manticoresearch": "select * from hn where match('abc') order by comment_ranking asc, story_id desc limit 20",
    "clickhouse": "select * from hn where (match(story_text, '(?i)\\Wabc\\W') or match(story_author,'(?i)\\Wabc\\W') or match(comment_text, '(?i)\\Wabc\\W') or match(comment_author, '(?i)\\Wabc\\W')) order by comment_ranking asc, story_id desc limit 20",
    "elasticsearch": "select * from hn where query('abc') order by comment_ranking asc, story_id desc limit 20",
    "mysql": "select * from hn where match(story_text,story_author,comment_text,comment_author) against ('abc') order by comment_ranking asc, story_id desc limit 20"
},
{
    "manticoresearch": "select count(*) from hn where match('google') and comment_ranking > 200",
    "clickhouse": "select count(*) from hn where (match(story_text, '(?i)\\Wgoogle\\W') or match(story_author,'(?i)\\Wgoogle\\W') or match(comment_text, '(?i)\\Wgoogle\\W') or match(comment_author, '(?i)\\Wgoogle\\W')) and comment_ranking > 200",
    "elasticsearch": "select count(*) from hn where query('google') and comment_ranking > 200",
    "mysql": "select count(*) from hn where match(story_text,story_author,comment_text,comment_author) against ('google') and comment_ranking > 200"
},
{
    "manticoresearch": "select story_id from hn where match('me') order by comment_ranking asc limit 20",
    "clickhouse": "select story_id from hn where (match(story_text, '(?i)\\Wme\\W') or match(story_author,'(?i)\\Wme\\W') or match(comment_text, '(?i)\\Wme\\W') or match(comment_author, '(?i)\\Wme\\W')) order by comment_ranking asc limit 20",
    "elasticsearch": "select story_id from hn where query('me') order by comment_ranking asc limit 20",
    "mysql": "select story_id from hn where match(story_text,story_author,comment_text,comment_author) against ('me') order by comment_ranking asc limit 20"
},
{
    "manticoresearch": "select story_id, comment_id, comment_ranking, author_comment_count, story_comment_count, story_author, comment_author from hn where match('abc') limit 20",
    "clickhouse": "select story_id, comment_id, comment_ranking, author_comment_count, story_comment_count, story_author, comment_author from hn where (match(story_text, '(?i)\\Wabc\\W') or match(story_author,'(?i)\\Wabc\\W') or match(comment_text, '(?i)\\Wabc\\W') or match(comment_author, '(?i)\\Wabc\\W')) limit 20",
    "elasticsearch": "select story_id, comment_id, comment_ranking, author_comment_count, story_comment_count, story_author, comment_author from hn where query('abc') limit 20",
    "mysql": "select story_id, comment_id, comment_ranking, author_comment_count, story_comment_count, story_author, comment_author from hn where match(story_text,story_author,comment_text,comment_author) against ('abc') limit 20"
},
"select * from hn order by comment_ranking asc limit 20",
"select * from hn order by comment_ranking desc limit 20",
"select * from hn order by comment_ranking asc, story_id asc limit 20",
"select comment_ranking from hn order by comment_ranking asc limit 20",
"select comment_ranking, story_text from hn order by comment_ranking asc limit 20",
"select count(*) from hn where comment_ranking in (100,200)",
"select story_id from hn order by comment_ranking asc, author_comment_count asc, story_comment_count asc, comment_id asc limit 20"
]
```

## Results
You can find all the results on the [results page](https://db-benchmarks.com/?cache=fast_avg&engines=mysql_tuned&tests=hn&memory=1024&queries=0%2C1%2C2%2C3%2C6%2C7%2C8%2C9%2C12%2C13%2C15%2C16%2C17%2C18%2C19%2C20%2C21%2C23%2C24%2C25%2C26) by selecting “Test: hn”.

Remember that **the only high quality metric is “Fast avg” since it guarantees low [coefficient of variation](https://en.wikipedia.org/wiki/Coefficient_of_variation) and high queries count conducted for each query.** The other 2 (“Fastest” and “Slowest”) are provided with no guarantee since:

- **Slowest** - is a single attempt result, in most cases the very first coldest query. Even though we purge OS cache before each cold query it can’t be considered stable. So it can be used for informational purposes only (even though many benchmark authors publish such results without any disclaimer).
- **Fastest** - just the very fastest result, it should be in most cases similar to the “Fast avg” metric, but can be more volatile from run to run.
Remember the tests including the results are 100% transparent as well as everything in this project, so:
 - you can use **the test framework** to learn how they were made
 - and find raw test results in the [results](https://github.com/db-benchmarks/db-benchmarks/tree/main/results) directory.

**Unlike other less transparent and less objective benchmarks we are not making any conclusions, we are just leaving screenshots of the results here:**

**4 competitors at once**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/obyhlvgg7wz2lqyga9th.png)

**Clickhouse vs Elasticsearch**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/87tsoe80ahpzzrde256c.png)

**Manticore Search (columnar storage) vs Elasticsearch**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s3mm7lfy75kjf24m0m5v.png)

**Manticore Search (columnar storage) vs Clickhouse**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37ch9nqj912ww2dnrr2u.png)

**Manticore Search row-wise storage vs columnar storage**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lw0qveoj0aoc9naa6lui.png)

**What about MySQL?**
As you can see on the screenshots MySQL has been also tested, but we don’t compare it with the others here since it was [heavily tuned](https://github.com/db-benchmarks/db-benchmarks/blob/main/tests/hn/mysql/init) - keys were added based on the queries.

**Disclaimer**
The author of this test and the test framework is a member of [Manticore Search](https://manticoresearch.com/) core team and the test was initially made to compare Manticore Search with Elasticsearch, but as shown above and can be verified in the [open source code](https://github.com/db-benchmarks/db-benchmarks) and by running the same test yourself Manticore Search wasn’t given any unfair advantage, so the test can be considered unprejudiced. However, if something is missing or wrong (i.e. non-objective) in the test feel free to make a pull request or an issue on [Github](https://github.com/db-benchmarks/db-benchmarks). Your take is appreciated! Thank you for spending your time reading this!