I have a small app and I use MongoDb (Mongoid). The collection is relatively small (about 300 records), however the query is taking a long time (approximately 12s). Here's my query:
query = Lead.order(:post_date.desc).cache
query = query.page(params['page_number']).cache if params['page_number']
query = query.per(params['page_size']).cache if params['page_size']
query = query.where(read: params['read']).cache if params['read']
query = query.where(important: @user.id.to_s).cache if params['important'] == "true"
query = query.where(starred: @user.id.to_s).cache if params['starred'] == "true"
And I have the fowling indexing setup on the Model:
index({ post_date: 1 }, { background: true })
index({ read: 1 }, { background: true })
index({ important: 1 }, { background: true })
index({ starred: 1 }, { background: true })
So my question is, 1) how can I improve the performance of this query and 2) is there a tool (like NewRelic although NewRelic doesn't provide details on how improve performance for queries) or service that can monitor the queries and suggest improvements?
Thanks in advance!
CloudManager is a paid-for GUI which provides (amongst others) performance analysis "like NewRelic".
A built-in profiler logs slow queries (> 100ms) by default, but can be turned on (with caution) to log everything.
An .explain() to analyse performance of a particular query.
Compas is an official GUI with some performance insights.
More monitoring tools: https://docs.mongodb.com/manual/administration/monitoring/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.