Issue background:
Company and Teng Xun co-developed a hand-tour, the need to develop a background management platform to statistics daily game data; The data volume is relatively large collection of two, one is User_info, about 2,453 data, the other is Room_data, about 8,456 data.
Question content:
Feature development completed, but query MongoDB database and display data particularly slow, time is about 10S. What the hell is this, and why is it so slow?
Problem Solving methods:
The first thing to think about is to add an index to the collection, and still not solve the problem after adding the set of operations to the index! Sweat! What's the reason? Let's go and ask the Niang first! Asked a painful question is still not solved. Since the degree Niang can not solve, or calm calm yourself check the code bar. Because statistics more data, so need to query the database multiple times, write 12 methods for its service. The data for the query needs to be de-processed, because the first time you use a MongoDB database, so it is not very familiar, so the deduplication process was done using PHP. It was this that went over to deal with my own life. Leave the first method, comment out all other called methods, and find that the query time is not abnormal. When you open a comment that calls the second method, you find that the query time is noticeably slower. Next try to modify the second method of the de-processing to MongoDB to do, surprised to find that the time is much faster, the original problem is in this, quickly all the methods of the process to be changed from MongoDB to do, again test discovery time is 338ms, greatly saving time overhead.
Problem revelation:
The revelation of the problem is that the database is designed to handle stored data, so the database can do as much as possible. Of course, there are exceptions, compared to MySQL multi-table query or less use, inefficient.
PHP Query MongoDB Slow problem