-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Optimization for PG2 ETS insertion #1311
Conversation
…e for elements with same key
Optimization for PG2 ETS insertion
@gabiz You are my hero! This increased our arrival rate by 10x, as well as solved the mysterious contention causing our subscribe timeouts! Thanks so much!!! 😍🚀🚀 |
Awesome commit @gabiz |
@gabiz this is so awesome! |
@chrismccord just to document, it would be really nice to move the writes back to Local (both inserts and deletes) and see how they affect performance now that we are using the proper ETS type! Once you do, remove the |
That's the first thing on my todo list tomorrow Sent from my iPhone
|
@josevalim the keyless match_delete is very expensive. Needs to traverse the whole table. Have you considered using a reverse ETS table to store the pid -> topic info. Using that the delete is several order of magnitude faster and avoids blocking other gen_server operations. |
@josevalim I just noticed that we used to have a reverse HashDict pid to topic back in time. We certainly need something like that if we plan to move the deletes back to the Local. Otherwise a bunch of disconnects are going to trigger the expensive deletes and block incoming subscriptions. |
@gabiz - what tools do you recommend to profile Elixir code... To fix this kind of issues there must be a better way than looking at |
ETS :bag insertion for elements with the same key grows linearly (on the number of elements with same key). On the other hand :duplicate_bag insertion is constant.
This change does not increase the size of the ETS and there is no performance degradation for lookups and deletions.
I was able to replicate insertion timeouts when there are lots of elements with same key using :bag but it does not happen using :duplicate_bag.