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

Optimise mnesia table loading time for busy tables #4575

Merged
merged 1 commit into from Mar 15, 2021

Conversation

ssmyczynski
Copy link
Contributor

This PR optimizes mnesia table loading time (on adding new table copy or just starting another mnesia node) for busy tables (a lot changes per second).

The problem with current implementation is that table receiver first subscribes for table changes, then starts downloading the content of the table from sender and only after receiving whole content of the table handles all the subscribed changes that happened in the meantime. For busy tables this causes receiver message queue to grow very quickly slowing down the downloading process.

The simple solution is to receive all mnesia_table_events that comes during table copying and store them in private ets table for later processing after table is succesfuly downloaded.

Currently:
pre

After applying changes in this PR:
post

@ssmyczynski
Copy link
Contributor Author

demo-script.zip

@rickard-green rickard-green added the team:PS Assigned to OTP team PS label Mar 8, 2021
@dgud
Copy link
Contributor

dgud commented Mar 10, 2021

Why an ets table and not the simple solution of just a adding to a list, performance?

@dgud dgud added the testing currently being tested, tag is used by OTP internal CI label Mar 10, 2021
@dgud
Copy link
Contributor

dgud commented Mar 10, 2021

Nice find, though..

@ssmyczynski
Copy link
Contributor Author

Why an ets table and not the simple solution of just a adding to a list, performance?

Actually this was my first thought as also keeping order of events is simple in list - you prepend the list with new events, and just before replying those events just do once a lists:reverse - so the performance was not the reason of using private ets table.

The main reason is that I didn't want to change the return spec of a function returned by table_init_fun (and later make_table_fun), because that it is used later internally in ets module (see ets:init_table_continuation) for ram_copies/disc_copies tables, and in dets module for disc_only_copies, so I decided to store SubscrCache in process dictionary - and storing a huge list in process dictionary is not a good idea at all :)

And as a bonus we don't have to worry about garbage collection when collecting those subscriptions.

@dgud dgud merged commit 83cb6d3 into erlang:maint Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants