Events: Optimize enrolls to avoid timeouts #396
Merged
+210
−85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problems experienced with the
enroll
endpoint are related to the following:enroll
operation itself is slowWhat has been done to address the issue so far
enroll
operationWhat is the next step
Optimization
This limit can be raised per request if needed by changing
ignoreOlderThan
field in the request (the value is integer - number of days). You may use0
to remove the limit and process the entire queuePreventing duplicate requests
We could utilize the fact the query continues on the background.
Implementation
{"status": "processing"}
(TTL 1 hour){"status": "done", "payload": EnrollResponseModel}
That way when the client re-request the same operation, we can return the cached response.
Testing
slothMode
argument to enroll endpoint was introduced. When enabled, database request becomes super slow (using a sleep inside select query) to simulate slow responses. Additionaly, when this mode is used, enroll is more verbose and prints what's happening to the server log (prefixed with a friendly sloth emoji)The following (or similar) script can be used to test the stability of the endpoint:
Underlying logic is unchanged, so the result is the same and changes are fully backwards compatible, but please, test with existing services.