-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Huge performance hit in my code? #2307
Comments
Hmm you may want to try reducing the batch size, its kinda huge. Also, do you have an index on |
Hi vkarpov, Yes I have index on completed. I need to think of changing the batch size. |
But when I run the same query on mongo shell, its really fast. The streaming takes lot of time. Not sure if it is latency between servers or just something wrong with the code. Many thanks, |
Are you using the same batch size with the shell? The tricky bit with the large batch size is that the node driver waits until it gets all the documents before it starts sending them to you. Furthermore, pushing all 90k documents into an array is also a fairly expensive operation, and defeats the point of streaming: with streaming, ideally you're processing one document at a time and then letting the garbage collector reclaim that memory. You could probably trim a fair bit off of your runtime by just printing in the |
Thank you so much for your help @vkarpov15 |
I have a collection similar to below BSON. The whole table(baskets) count is 900k for about 60 stores. The largest store collection is 90k. I have a custom date filter for our dashboard to display some graphs and numbers.
I have used native mongo driver to aggregate and reduce the result set and squeeze it to completed date hourly. The query I used in my nodejs application looks something similar to this.
I use native driver technique after the mongoose cursor failed to work(you can refer to my previous post in #2306).
Now I get results like
Aggregated hourly
Total record size: 90K documents.
Aggregated Size: 2897 documents
Time taken to execute the aggregated same raw query in mongo shell: 1300ms
Total string length for aggregate size: 40876933
Time taken to print the final pushed array: 79575ms(1.15 mins)
My internet speed at the time of querying: 70mbps
Please help me further optimise the query. Is my approach wrong? I am completely clueless.
Many thanks,
Karthik
The text was updated successfully, but these errors were encountered: