Mongodb data reads getting slow

Hi,

I have a MongoDB cluster set up in an Openshift container platform. A replica set of 3 is set to this MongoDB instance (1 primary, 1 secondary, and 1 stationery). The application connects to this primary MongoDB cluster to execute queries and retrieve data. For a certain period of time, both the data reads and writes seems to be quite fast and completes within 5 secs. After the cluster has been running for 2 days, all the data reads get slower and take 45mins to complete. The application is multi-threaded and this data slowness attributes to the subsequent calls to hung or fail and greatly affects the performance.

Query to retrieve a list of student ids from a college dept.

db.getCollection(‘college_dept’).distinct(“student_id”,{“dept”: “BS”,“alias”:{ $not: /^chem/ } })

Kindly advise on ways to resolve this issue.

Thanks for your time.

Hi @jegadees_B Can you mention more specifics? Is the size of data increasing over the two days? If yes, how much? Can you also check the memory usage of your mongodb cluster over time?

1 Like

Adding to what shrey_batra says: you may want to look at your oplog to see what is happening. Let us know what that says and hopefully that’ll help us pinpoint the problem.

1 Like

Hi @jegadees_B,

Did you create the index {"dept": 1, "alias": 1, "student_id": 1} on this collection which - I think - would make this query covered.

Cheers,
Maxime.

For fast querying always use the indexed field. It will be much faster then the other fields.
Make sure that you have the same field indexed as per the query for more detail about indexing check this link.

~ Thanks