Skip to content
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

Why running queries in parallel is slow? #2088

Closed
sergey-shpak opened this issue Jul 24, 2024 · 2 comments
Closed

Why running queries in parallel is slow? #2088

sergey-shpak opened this issue Jul 24, 2024 · 2 comments
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. needs more info This issue needs more information from the customer to proceed. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@sergey-shpak
Copy link

Hey, I'm trying to run couple queries in parallel and getting some weird performance results:

// total execution time of this example is ~200ms
const queries = [
  db.collection('path').where('propId', '==', 'firestore-prop-id').get()
]
const res = await Promise.all(queries)

but when trying to add one more query exec time increases to ~800ms ( 4 times !!! )

// total execution time of this example is ~800ms
const queries = [
  db.collection('path').where('propId', '==', 'firestore-prop-id').get(),
  db.collection('path').where('propId', '==', 'firestore-prop-id').get(),
]
const res = await Promise.all(queries)

what is more interesting, when trying to add even more queries, now total exec time remains almost the same ~800ms

// total execution time of this example is ~800ms
const queries = [
  db.collection('path').where('propId', '==', 'firestore-prop-id').get(),
  db.collection('path').where('propId', '==', 'firestore-prop-id').get(),
  db.collection('path').where('propId', '==', 'firestore-prop-id').get(),
  db.collection('path').where('propId', '==', 'firestore-prop-id').get(),
  db.collection('path').where('propId', '==', 'firestore-prop-id').get(),
]
const res = await Promise.all(queries)

Why running >1 query in parallel has such exec time difference?
Is there any bottleneck, or am I missing something?

To mention, I checked query.explain with analyze param and there is no noticeable time difference in executionDuration of the queries.

@sergey-shpak sergey-shpak added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Jul 24, 2024
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Jul 24, 2024
@cherylEnkidu cherylEnkidu self-assigned this Jul 24, 2024
@cherylEnkidu
Copy link
Contributor

Hi @sergey-shpak ,

Thank you for filling the ticket!

I tested the code with the same scenario and didn't reproduce the same behaviour.

Usually, when the SDK execute the query for the first time, it takes a little bit longer since it needs to establish the connection with the backend.

After that, every same query just take a little bit more time since they can reuse the previous connection.

So what is happened in the example you provided is, the query execution usually takes ~ 800 ms and the 200 ms one happens occasionally.

If you believe this reason doesn't fully explain your case, you please provide more data for us to look further? For example running the query multiple times to get a average time spent.

Also if you have not, please try the use the latest version of SDK.

@cherylEnkidu cherylEnkidu added the needs more info This issue needs more information from the customer to proceed. label Jul 24, 2024
Copy link

github-actions bot commented Oct 4, 2024

This has been closed since a request for information has not been answered for 15 days. It can be reopened when the requested information is provided.

@github-actions github-actions bot closed this as completed Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. needs more info This issue needs more information from the customer to proceed. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants