Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query of one large (7MB) record by primary key from MongoDB runs CPU 100% for 5 seconds

Tags:

mongodb

I have a replication set of three mongod processes running on my laptop (i7, SSD, 16GB RAM). I create an empty database and add a single 7MB record to it. I then query that record out from the command line:

echo "db.items.find({_id:'.......'})" | mongo mydb >tmp/junk

The client application "mongo" (not mongod or mongos) takes 100% CPU for several seconds before spitting out the response. If I read the record out using the Java client for MongoDB, my JVM process uses 100% CPU for several seconds before giving the response.

What could be going on here? How can I troubleshoot this?

Update: The replication set seems to be irrelevant; if I connect mongo directly to the master mongod, the performance is the same.

Update: The PHP client can get the data in some fraction of a second. Wha...?

like image 959
Ben Dilts Avatar asked Nov 18 '25 21:11

Ben Dilts


1 Answers

Sounds like it takes mongo several seconds to decode the document's BSON into a Javascript object in C++, and several seconds for the Java driver to decode the BSON into a Java object. You could use mongodump to dump that one document to a bson file using mongodump's --query argument, then try:

time bsondump file.bson > /dev/null

That'll give you a basis for comparison: the time it takes a C++ program to decode the BSON document and format it as JSON. If that's lengthy, then the sheer size of the document is the main cost.

like image 159
A. Jesse Jiryu Davis Avatar answered Nov 22 '25 00:11

A. Jesse Jiryu Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!