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

Various reliability fixes #76

Merged
merged 10 commits into from
Oct 15, 2024
Merged

Various reliability fixes #76

merged 10 commits into from
Oct 15, 2024

Conversation

mgdaily
Copy link
Contributor

@mgdaily mgdaily commented Sep 17, 2024

  • Construct the queue filename from the version_set within the request body sent by the ingester lib, rather than querying it from the newly created frame object. There is sometimes a race condition that causes the version_set on the Frame object to be None shortly after it's created. This seems to be a function of DB load.
  • Add include_related_frames query param for frames queries. This defaults to true if not set to preserve API compatibility, but can be turned off by setting ?include_related_frames=false. This is to reduce the load on the service and database from repeated queries to frames that have many thousands of related frames that take a long time to fetch and serialize.

We want to isolate any sort of replication lag from the DB to make sure that we get any and all attributes and foreign keys after object save. There have been some instances where the version_set is empty.
Copy link
Member

@jnation3406 jnation3406 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is doing what you think its doing? My understanding is that the local frame instance will already be up to date since you just passed it around to create all these links... But you want something querying the archive later (from the queue) to get up to date data rather than whats on the read replica. Depending on how it queries for the frame data, we could have some fallback where it looks for the frame in the read DB and then if it doesn't find it it tries the write DB before returning a 404? Or just add retry logic in whatever is pulling it off the queue and querying for it since the read db should update itself relatively quickly.

This avoids a query to the version_set, which we've seen issues reading from due to a race condition which has been quite hard to pin down.
BPMs, for instance, have up to hundreds of thousands of related frames. BANZAI queries for these frequently and we don't need related frames in the response, so it's wasteful for us to include them.
@@ -158,7 +159,10 @@ def as_dict(self, include_thumbnails=False):

if self.area:
ret_dict['area'] = json.loads(self.area.geojson)
ret_dict['related_frames'] = list(self.related_frames.all().values_list('id', flat=True))
if self.configuration_type in settings.EXCLUDE_RELATED_FRAME_TYPES:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because there are many related frames for BPM? Should we do this for other calibration types too like Bias/Dark/Lampflat? Is this just for efficiency of using less resources on an untargeted /frames/ query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. I don't think there is a need for other frame types, but I've left it configurable for that purpose.

This is on by default, but currently users will be able to request to exclude related frames from their queries. Also update the get_queryset method to avoid prefetching related frames if we know we're not going to use them.
@mgdaily mgdaily changed the title Refresh frame object from DB after all foreign keys have been saved Various reliability fixes Oct 7, 2024
@mgdaily mgdaily requested a review from jnation3406 October 9, 2024 16:34
If the user has passed ?include_related_frames=false, then do not prefetch related frames, as this is wasteful. Update tests.
@mgdaily mgdaily merged commit 155eeb7 into main Oct 15, 2024
13 checks passed
@mgdaily mgdaily deleted the fix/refresh-frame branch October 15, 2024 23:18
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

Successfully merging this pull request may close these issues.

2 participants