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

Configure MySQL transaction isolation level to READ UNCOMMITTED in tracking to avoid gap locks. READ COMMITTED for better performance overall #14619

Closed
mattab opened this issue Jul 3, 2019 · 5 comments
Labels
c: Performance For when we could improve the performance / speed of Matomo. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.

Comments

@mattab
Copy link
Member

mattab commented Jul 3, 2019

Goal: minimise possible locks in Tracker to improve performance.

Concerns: what could be the worst side effects? inconsistent tracking data stored in some cases?

Note: this should ONLY apply in Tracker mode, not for API/UI/etc.

https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html#isolevel_read-uncommitted

SELECT statements are performed in a nonlocking fashion, but a possible earlier version of a row might be used. Thus, using this isolation level, such reads are not consistent. This is also called a dirty read. Otherwise, this isolation level works like READ COMMITTED.

dirty read

  • An operation that retrieves unreliable data, data that was updated by another transaction but not yet committed. It is only possible with the isolation level known as read uncommitted.
  • This kind of operation does not adhere to the ACID principle of database design. It is considered very risky, because the data could be rolled back, or updated further before being committed; then, the transaction doing the dirty read would be using data that was never confirmed as accurate.
  • Its opposite is consistent read, where InnoDB ensures that a transaction does not read information updated by another transaction, even if the other transaction commits in the meantime.
  • See Also ACID, commit, consistent read, isolation level, READ UNCOMMITTED, rollback.
@mattab mattab added Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change. c: Performance For when we could improve the performance / speed of Matomo. labels Jul 3, 2019
@mattab mattab added this to the 3.12.0 milestone Jul 3, 2019
@tsteur
Copy link
Member

tsteur commented Sep 3, 2019

FYI: So far we have barely any deadlocks anymore. I reckon it might not really be needed anymore so much. Seems the changes we did helped avoid the deadlocks

@mattab mattab modified the milestones: 3.13.0, 4.0.0 Oct 23, 2019
@mattab mattab removed this from the 4.0.0 milestone Feb 20, 2020
@tsteur
Copy link
Member

tsteur commented Aug 2, 2021

For performance it might be actually quite good to change the isolation mode during tracking to read committed. This is also the default for most other RDBS and it should faster since less versions need to be maintained etc.

It be interesting to try this as it's quick to implement (we already have a way to set this for aurora using the aurora_readonly_read_committed ini setting) but the more difficult part is actually measuring it.

@tsteur tsteur added this to the Priority Backlog (Help wanted) milestone Aug 2, 2021
@tsteur
Copy link
Member

tsteur commented Aug 2, 2021

Overall it be also worth considering using read committed instead of repeatable read. Meaning for every query, whether it's archiving or something else.

@tsteur tsteur changed the title Tracker mode: configure MySQL transaction isolation level to READ UNCOMMITTED. to avoid gap locks Configure MySQL transaction isolation level to READ UNCOMMITTED in tracking to avoid gap locks. READ COMMITTED for better performance overall Aug 2, 2021
@tsteur
Copy link
Member

tsteur commented Jan 13, 2022

If someone has issues with gap locks, please comment and let us know about it.

@mattab
Copy link
Member Author

mattab commented Dec 11, 2023

So far it seems not needed so I will close this. Please comment if you experience a related issue 👍

@mattab mattab closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
@sgiehl sgiehl added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Performance For when we could improve the performance / speed of Matomo. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Projects
None yet
Development

No branches or pull requests

3 participants