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

只谈情不闲聊 提交于 2019-12-03 14:35:48

It is logically very simple to process a request on a single core. Just have code that receives the request, and deals with it.

It is not nearly so simple to process a single request on 2 cores, because doing so requires you to break up the request into components, farm out the work, synchronize the answers, and then build up a single response. And if you do this work, while you can reduce wallclock time (how much time the clock on the wall sees pass), you're invariably going to make the request take more CPU time (total CPU resources consumed).

In a system like MongoDB where you expect to have a lot of different clients making requests, there is no need to try to parallelize the handling of a single request, and every reason not to.

The bigger question is why Oracle didn't increase concurrency after 4 CPUs. There are any number of possible reasons, but one reasonable guess is that you encountered some sort of locking which is needed to guarantee consistency. (MongoDB does not offer you consistency, and so avoids this type of bottleneck.)

Oracle doesn't lock data for consistency but it does write data to redo and undo files for transactions and read consistency. Oracle is a MVCC system. See http://en.wikipedia.org/wiki/Multiversion_concurrency_control .

You have to use parameterized queries to make Oracle fast, else Oracle will spend too much time parsing queries. This is especially important when a lot of small queries run simultaneously, the situation you are testing.

MongoDB does lock on writes.

edit 1:

Another big difference between Oracle and MongoDB is durability. MongoDB doesn't offer durability if you use the default configuration. It writes once every minute data to the disk. Oracle writes to disk with every commit. So Oracle does a lot more fsyncing.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!