-
Notifications
You must be signed in to change notification settings - Fork 23
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
Many handlers perf #3305
Merged
Merged
Many handlers perf #3305
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The idea is the same as in db events. Later the commonalities could be refactored away.
The AddressException happens when there is an invalid character in the email address (e.g. `;`). Let's drop those from the outbox immediately so they won't be re-tried.
If there are 100 handlers, this means a lot of unnecessary users are returned making the response unnecessarily big. We need the active handlers for the table. There could be a better API but let's make v2 sometime to return only slim results and joining an option.
There's two changes here of which one is more subtle. The original logic from years ago was such that all users rights were updated whenever there was any change. This was fast for a while. Last year, updates were implemented to only touch users that were involved in the applications of the events. This was much faster. There is however a flaw in this version. Consider a case where one application was changed but there are 100 potential handlers in the organization. All the rights of these 100 handlers were updated by considering all their applications. Handlers tend to be members of all applications so that could be 100 times the application count of updates, e.g. 300K for 3000 applications. This adds up to a few hundred milliseconds, which is too slow for us now, ,specially after adding more performance test data (10 handlers in production so 100 handlers in performance test data). We can avoid this amount of changes by recording how many times you have a role instead of only whether you have the role. Then we remove the role once per member of the old application and add 1 per member of new application. This will total 100 changes for 100 users in one application, which is as good as it can be. We could also record which application gives which role, but that is slightly more memory consuming for no additional gain. The other subtler change is to cache only ids of applications that a person has, not the personalized applications. 100 handlers with 3000 applications could result in 300K applications being cached. Clojure's persistent data structures do help us here and in practice that would not happen. However, we can avoid this by doing the personalization in the functions that return results instead and have less memory use for some runtime cost. We do store the enriched applications, so this personalization is only in-memory code, so it should be fast. These changes seem to be fast for the handled applications case, so it should be fast enough for the other cases.
7 tasks
NB: add also note about removing the shake animation
aatkin
approved these changes
May 23, 2024
This makes the functions cleaner and enables us to test the implementation at least a little bit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Tries to fix the many handlers perf problems from #3283
There's two changes here of which one is more subtle.
The original logic from years ago was such that all users rights were
updated whenever there was any change. This was fast for a while.
Last year, updates were implemented to only touch users that were
involved in the applications of the events. This was much faster.
There is however a flaw in this version.
Consider a case where one application was changed but there are 100
potential handlers in the organization. All the rights of these 100
handlers were updated by considering all their applications. Handlers
tend to be members of all applications so that could be 100 times the
application count of updates, e.g. 300K for 3000 applications. This
adds up to a few hundred milliseconds, which is too slow for us now,
,specially after adding more performance test data (10 handlers in
production so 100 handlers in performance test data).
We can avoid this amount of changes by recording how many times you have a
role instead of only whether you have the role. Then we remove the
role once per member of the old application and add 1 per member of new
application. This will total 100 changes for 100 users in one
application, which is as good as it can be. We could also record which
application gives which role, but that is slightly more memory
consuming for no additional gain.
The other subtler change is to cache only ids of applications that a person
has, not the personalized applications. 100 handlers with 3000
applications could result in 300K applications being cached.
Clojure's persistent data structures do help us here and in practice
that would not happen. However, we can avoid this by doing the
personalization in the functions that return results instead and
have less memory use for some runtime cost. We do store the enriched
applications, so this personalization is only in-memory code, so it
should be fast.
These changes seem to be fast for the handled applications case, so it
should be fast enough for the other cases.
Further changes can be done in a new PR also, after we get all the improvement PRs integrated.
Main changes:
/handled
APIPotential future tasks:
Checklist for author
Remove items that aren't applicable, check items that are done.
Reviewability
Backwards compatibility
Documentation
Testing
Follow-up