Why does MongoDB work better with a multi-threaded client compared to a single threaded client?

We recently compared Oracle 10g and MongoDB with YCSB ( https://github.com/brianfrankcooper/YCSB/wiki ) when we tried to increase the number of threads for 1,000,000 datasets, Oracle performance remained constant after 4 threads, however MongoDB continued to work better and better, up to 8 threads, and after that only reading was better, writes and updates (operations / sec) remained constant.

We conducted this test on the dual-core Xeon CPU core (8 cores in total) + 8 GB of RAM in the local network.

We observed that MongoDB worked better with a multi-threaded client than a single-threaded client, my question is: when MongoDB can work better with a higher load, why can't it do the same with a lower load (say, just a couple of threads) using multiple cores ?

+6
source share
2 answers

Logically, it is very simple to process the request on one core. Just get the code that receives the request and deals with it.

It is not so easy to process one request on 2 cores, because this requires breaking the request into components, doing work, synchronizing the answers, and then creating one answer. And if you do this work, while you can reduce the time spent on the wall (how long the clock on the wall sees), you will always make a request for more processor time (consumed shared CPU resources).

On a system like MongoDB, where you expect that you will have many different clients running queries, there is no need to try to parallelize the processing of one request, and each reason should not.

The bigger question is why Oracle did not increase concurrency after 4 processors. There are several possible reasons, but it is reasonable to assume that you are faced with some kind of lock that is necessary to ensure consistency. (MongoDB does not offer you consistency and therefore avoids this type of bottleneck.)

+6
source

Oracle does not lock data for consistency, but records data for retrying and canceling files for transactions and read consistency. Oracle is an MVCC system. See http://en.wikipedia.org/wiki/Multiversion_concurrency_control .

You must use parameterized queries to make Oracle fast, otherwise Oracle will spend too much time parsing the queries. This is especially important when many small queries are launched at the same time, in the situation that you are testing.

MongoDB locks records.

change 1:

Another big difference between Oracle and MongoDB is durability. MongoDB does not provide longevity if you use the default configuration. It writes data once per minute to disk. Oracle writes to disk with each commit. Thus, Oracle does a lot more fsyncing.

+3
source

Source: https://habr.com/ru/post/891789/


All Articles