Spring Boot MongoDB write replicable set separation

 

A version of the project just recently iterations up, and then after another device to access to the system.

Parsed data produced by the device, after processing fell in MongoDB, but only 10w of data led to very slow paging query, count operation is slow moving.

The morning after the addition of the index, down more than 10 seconds from 5 seconds, but this rate is still very Mana, this TM is not coming until the access equipment on the bombing.

Then in the afternoon to start troubleshooting, look at the code in slow query.

Finally found a phenomenon that is: Navicat go through the same query statements faster than find and count several times in the code, the client query is a normal phenomenon.

I wonder, database and project code client connections in a linked database is consistent ah, is a fast feathers a slow?

Later he asked O & M, the original buy Ali cloud MongoDB instance can be copied with the set, then the database is the main one on the back.

Although the project code in the database configuration and connection of a client's hair, like Navicat, but the project is code inside the main library of the investigation, but the investigation is Navicat client from the library.

Then do an experiment, Navicat to connect to the main library, and sure enough, Nima click on the slow speed a lot.

This TM is really pit father.

Fortunately, however, that the problem be found, a big step forward.

 

Let's analyze it, connected to the main library query why so slow? On the main library I have built an index ah!

Preliminary analysis, the read and write operations are concentrated in the main library, not just read this paging query, there are a lot of other read operations. And many write the main library; There is also a 5min execution of scheduled tasks, need to read data and write data are concentrated in the main library. So here my analysis, can be resource contention on the main library more powerful. This is left to continue the follow-up analysis.

 

Since the master and slave have, why not read from the library?

The need to find out how the principles can MongoDB replication set, and Spring Boot is configured to read and write separation of MongoDB .

 

Originally tonight is ready to read and write separate from the main configuration finished in walking, but since a train to catch on the first down, slow queries on it a little slow, and did not hang at least know where the reason!

 

good night everybody!

 

Guess you like

Origin www.cnblogs.com/tuhooo/p/11141281.html