Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb parallel queries via nodejs

I am trying to run a number of mongodb queries via node Async. But they are still taking time to run.. The database is indexed and completely optimised. Is there a way by which I can increase the query speed time via mongodb admin ... or like increase its performance by allocating more memory to it.

The queries are running one by one when I see on the console. and some are taking too long ... resulting in no response..

2015-12-29T10:31:48.958-0800 I COMMAND  [conn63] command consumers.$cmd command: count { count: "consumer1s", query: { ZIP: 37089, $or: [ { ADULTS_F_18_24: "Y" }, { ADULTS_F_24_35: "Y" } ] } } planSummary: IXSCAN { ZIP: 1.0, GENDER: 1.0 } keyUpdates:0 writeConflicts:0 numYields:1 reslen:44 locks:{ Global: { acquireCount: { r: 4 } }, MMAPV1Journal: { acquireCount: { r: 4 } }, Database: { acquireCount: { r: 2 } }, Collection: { acquireCount: { R: 2 }, acquireWaitCount: { R: 2 }, timeAcquiringMicros: { R: 54270 } } } 146ms

2015-12-29T10:31:54.925-0800 I COMMAND  [conn62] command consumers.$cmd command: count { count: "consumer1s", query: { ZIP: 37024, $or: [ { ADULTS_F_18_24: "Y" }, { ADULTS_F_24_35: "Y" } ] } } planSummary: IXSCAN { ZIP: 1.0, GENDER: 1.0 } keyUpdates:0 writeConflicts:0 numYields:88 reslen:44 locks:{ Global: { acquireCount: { r: 178 } }, MMAPV1Journal: { acquireCount: { r: 172 } }, Database: { acquireCount: { r: 89 } }, Collection: { acquireCount: { R: 89 }, acquireWaitCount: { R: 83 }, timeAcquiringMicros: { R: 1654781 } } } 6114ms

Hi please see the logs to understand my question ... 2 queries following same plan .. have a large execution time difference ... Please tell me the reason and how to fix it

Following info must be handy. I am working this application on a Macintosh System. OSX Yosemite 10.10.2 Processor 3.2Ghz Intel Core i5. Memory is 8GB 1600MHz DDR3. Any suggestions how I can allocate more virtual memory to the mongodb

like image 267
Satyam S Avatar asked Dec 28 '15 11:12

Satyam S


1 Answers

As @Martin said, you need to profile. Use something like cursor.explain to make sure the query is using indexes and to find weak points. Use whatever resource monitor your system has (like top/htop on linux) to see if it's running out of memory or if it's CPU-bound.

"The queries are running one by one" -- I assume you're not using async.series or similar, which is sequential.

like image 128
ZachB Avatar answered Nov 02 '22 00:11

ZachB