-
Improvement
-
Resolution: Fixed
-
Minor
-
3.9
-
MOODLE_39_STABLE
-
MOODLE_39_STABLE
-
MDL-68577-redis-lock-tuning -
Discovered in MDL-58018
The redis session handle polls for a lock, and it waits a random time from 100-1000ms so on average each blocked http request waits 550ms. We aim for a performance budget of say 200ms for a small ajax request, and lets assume there are 5 queued up to run so in a perfect world they run in serial right after each other and take 1000ms.
Lets assume call A grabs the lock first, the others are all blocks and wait for random times: B: 100, C: 400, D: 900, E: 1000
B will still be blocked by A after 100 and poll again, lets say it gets 550 the second time.
C will run after 400ms, but there is already a 200ms gap from when A had finished that was wasted.
B runs again at 750 but could have started at 600, so another 150ms wasted.
D will run at 900ms but it blocked and so goes back again (say another +550)
E runs at 1000ms
D runs eventually on average at 1450.
Visually, scenario above:
A: ==== 0 + 200 = 200
B: ==|===========|==== 100 + 550 + 200 = 850
C: ========|==== 400 + 200 = 600
D: ==================|===========|==== 900 + 550 + 200 = 1650
E: ====================|==== 1000 + 200 = 1200
Everything is finished at 1650 vs 1000ms in the ideal case so we're 65% worse off. But also we have 200 + 850 + 600 + 1650 + 1200 = 4500 total process time.
With improved lock polling
A: ==== 0 + 200 = 200
B: ==|==|==== 100 x 2 + 200 = 400 (100% better)
C: ==|==|==|==|==== 100 x 4 + 200 = 600
D: ==|==|==|==|==|==|==== 100 x 6 + 200 = 800 (100% better)
E: ==|==|==|==|==|==|==|==|==== 100 x 7 + 200 = 1000 (10% better)
Everything is finished at 1000ms in the ideal case so we're 65% better off total elapsed time. Total process time is 200 + 400 + 600 + 800 + 1000 = 3000, or 33% better with 1500ms saved on server processes / php fpm workers.
With pure readonly and no locks
A: ==== 0 + 200 = 200
B: ==== 0 + 200 = 200
C: ==== 0 + 200 = 200
D: ==== 0 + 200 = 200
E: ==== 0 + 200 = 200
Total time is 200ms, total process time 1000ms so another 2000ms better that this tracker alone.
Some fraction of ajax requests will never be readonly, you may genuinely need the session lock, or it's all third party code and hard to improve.
- has a non-specific relationship to
-
MDL-71768 More tuning of the redis session handler to reduce blocking wait time
- Open
- has been marked as being related by
-
MDL-68611 SESSION->wanturls set during a read-only session
- Closed
- will be (partly) resolved by
-
MDL-58018 Reduce session lock contention with opt-in READ_ONLY_SESSION
- Closed
- will help resolve
-
MDL-68689 redis session uses us instead of ms for retry_interval
- Open