OAK-11766 Write Throttling Mechanism - Session.save() delay#2339
OAK-11766 Write Throttling Mechanism - Session.save() delay#2339thomasmueller merged 4 commits intotrunkfrom
Conversation
Commit-Check ✔️ |
| return cachedMbean; | ||
| } | ||
|
|
||
| public long delayIfNeeded() { |
There was a problem hiding this comment.
Can this method be called by multiple threads?
There was a problem hiding this comment.
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.
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.
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=trueRepositoryManagement - SessionSaveDelayerConfig:
{"entries":[{"delayMillis":1,"threadNameRegex":".*"}]}