-
Notifications
You must be signed in to change notification settings - Fork 418
OAK-11766 Write Throttling Mechanism - Session.save() delay #2339
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
Commit-Check ✔️ |
return cachedMbean; | ||
} | ||
|
||
public long delayIfNeeded() { |
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.
Can this method be called by multiple threads?
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.
Yes. By default it is disabled. We need to be extremely careful that there is no error, or performance issue, if disabled.
If enabled, I think we don't need synchronization. It is fine if the configuration is read multiple times in some edge cases. But even in this case, we should try to prevent errors (NPE etc, setting the interrupt flag). But performance issues are not the highest priority in this case.
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.
Good point. I think that the disabled path is fine. The enabled path is a bit tricky though: since we access non-volatile fields from multiple threads without any synchronization, we have race conditions (according to the Java memory model). This might work fine but is hard to analyze. For example, if one thread sets lastConfig
and another thread reads the new value, I'm not sure if we don't risk NPE accessing individual fields of the referenced object (since there was no safe publish of the object). IMHO, protecting the "enabled" path with a single lock, even a simple synchronized { ... }
block, has less chance of introducing errors than unsafe access.
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.
It is sufficient if the fields of SessionSaveDelayerConfig are final; see https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.1
that means the JVM memory model guarantees that other threads see the fully constructed object if the constructor returns, via memory barrier.
We actually had an issue where we missed this, and this caused issues for ARM CPUs: https://issues.apache.org/jira/browse/OAK-9634
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionSaveDelayer.java
Outdated
Show resolved
Hide resolved
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionSaveDelayer.java
Show resolved
Hide resolved
|
A minimal configuration for this is:
Staring the process using
-Doak.sessionSaveDelayer=true
RepositoryManagement - SessionSaveDelayerConfig:
{"entries":[{"delayMillis":1,"threadNameRegex":".*"}]}