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

Huge amount of reads for within. Is this normal? #73

Open
mmmoli opened this issue Sep 11, 2019 · 5 comments
Open

Huge amount of reads for within. Is this normal? #73

mmmoli opened this issue Sep 11, 2019 · 5 comments

Comments

@mmmoli
Copy link

mmmoli commented Sep 11, 2019

Issue

Worried about ongoing costs 😟

Observation

12k READ queries over a few hours

Expected

Maybe an order of magnitude fewer.

Fixes

Either reset expectation and prepare to pay or fix crazy code?


Context

I've developed a graphql API to list 27k Projects stored in Firestore. I'm using geoFirex to find Projects within a certain radius.

As part of development, I ran this function 30 times or so:

export const getProjectsNearPoint = async (
  point: Location,
  searchRadiusKm: number = 10,
  queryFn: QueryFn = ref => ref.limit(3) // Bug: This is not working
) => {
  const center = geo.point(point.latitude, point.longitude);

  const field = "location";

  const query = geo
    .collection(COLLECTION, queryFn)
    .within(center, searchRadiusKm, field);

  const nearbyProjects = await get(query);

  const result = nearbyProjects.map(
    ({ queryMetadata, ...project }: GeoQueryDocument) => ({
      distance: queryMetadata.distance,
      ...project
    })
  );

  return result;
};

Screenshot 2019-09-10 at 23 39 04


Questions

  • Is this normal?
  • Would an index help?
  • does anyone suspect my graphql resolvers are doing anything necessarily recursive?

Thanks.

@danieltanasec
Copy link

danieltanasec commented Sep 30, 2019

Did you find any fix to this ?. I also tested the code and when I receive 4 points on my map I have 800 reads in firebase.

@codediodeio
Copy link
Owner

codediodeio commented Nov 7, 2019

Additional reads beyond the radius result is expected, but a bug was fixed in 0.1.0 where get was not unsubscribing from the underlying callback - I suspect that was the root of your issue.

Limit does not work as you might expect. A regular firestore query is made for 9 different square hashes, so your worst case limit would actually be applied as 9 x 3. I don't recommend using limit, but rather a smaller query radius or where with ==.

Also, you can now enable logging to track the total documents returned in a query within(c, r, f, { log: true }) to monitor the results clientside.

@alexmasita
Copy link

@mmmoli I am looking to using this library but I am curious to know if this issue is resolved for you as of this moment as per update suggested by @codediodeio ?

@mmmoli
Copy link
Author

mmmoli commented Apr 14, 2020

To be honest, I freaked out.

Between that and spending $30k in 72 hours I decided it wasn't worth it and moved away.

I think that's more of reflection of Fb's pricing model that this library though 🙏

@mmmoli
Copy link
Author

mmmoli commented Jun 15, 2020

@VincentDufour I didn't. I wasn't part of that engineering team.

From my link to the blog post describing their disaster:

This means that every session to our site read the same number of documents as we have of number of payments. #UnaVacaPorDeLaCalle received more than 16,000 supporters, so: 2 million sessions x 16,000 documents = more than 40 Billion requests to Firestore on less than 48 hours.

In summary: think, hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants