-
Notifications
You must be signed in to change notification settings - Fork 275
perf(api): Improve asynchronous behaviour #3638
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIP types, all ndb.Futures now. LGTM, great fix!
| return vulnerability_pb2.Vulnerability(id=self.id(), modified=modified) | ||
|
|
||
| def to_vulnerability(self, | ||
| include_source=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something better suited to a followup PR, but I would suggest removing all these flags and force callers to use the async version if they want to include stuff.
| return vulnerability_pb2.Vulnerability(id=self.id(), modified=modified) | ||
|
|
||
| @ndb.tasklet | ||
| def to_vulnerability_minimal_async(self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also be converting to_vulnerability_minimal to just call the async version then blocking so they both return the same data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might just leave it for now, since it's kind of the opposite of your other comment.
(I don't think to_vulnerability_minimal() is even used anymore anyway)
Bump the max concurrent requests from 5 to 10 for the API backend, to help with container instance scaling. This is not for the batch query backend, which still is just 1. Hopefully this won't have a notable performance impact. I don't really want to change this and #3638 at the same time, since I want to be able to measure the individual impacts of both. We could probably push this out with the release this week, and let #3638 stage until next week.
Change all(?) the ndb calls used throughout the API handlers to use the async versions, and rewrote a few functions to not block on the completion of futures that it doesn't need to (particularly, converting the Bug to a proto, and populating the related/alias/upstream fields of those protos). Testing on my private instance, this should be a 3-5x speedup for queries with lots of vulnerabilities. I've also made the batch queries properly set the modified time from the alias/upstream group (which might actually be a tiny performance loss) to ensure the modified time is always the same for the batch query and the get by ID. I've added `@ndb.synctasklet` to the rpc handlers to let us use `yield` instead of `.result()`, just to discourage usage of it (using `.result()` in a tasklet can cause stack overflows)
Change all(?) the ndb calls used throughout the API handlers to use the async versions, and rewrote a few functions to not block on the completion of futures that it doesn't need to (particularly, converting the Bug to a proto, and populating the related/alias/upstream fields of those protos).
Testing on my private instance, this should be a 3-5x speedup for queries with lots of vulnerabilities.
I've also made the batch queries properly set the modified time from the alias/upstream group (which might actually be a tiny performance loss) to ensure the modified time is always the same for the batch query and the get by ID.
I've added
@ndb.synctaskletto the rpc handlers to let us useyieldinstead of.result(), just to discourage usage of it (using.result()in a tasklet can cause stack overflows)