PHP Query MongoDB Slow problem

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.