magento2: Storing sessions in Redis causes longer loads
Preconditions (*)
- Magento Community Edition 2.4.1
- store sessions with redis
- store cache with redis
- varnish as fpc
Steps to reproduce (*)
This is tricky, I haven’t found a way to consistently reproduce this issue. But the behaviour seems a lot like what PR #22829 fixes. After receiving feedback from a customer we noticed that some steps in the checkout takes quite a bit of time, when profiling the checkout with Blackfire we noticed that some end points (f/e estimate-shipping-methods) sometimes take over 4s to complete. It looksl like to be coming from the class Magento\Framework\Session\Savehandler\Redis::read() method, which calls Cm\RedisSession\Handler::read. In the latter it uses usleep to wait for locks. Which on occasion takes 2s or more.
session config in env.php
'session' => [ 'save' => 'redis', 'redis' => [ 'host' => 'x.x.x.x', 'port' => 'xxxx', 'password' => '', 'timeout' => '2.5', 'persistent_identifier' => '', 'database' => '1', 'compression_threshold' => '0', 'compression_library' => 'gzip', 'log_level' => '2', 'max_concurrency' => '6', 'break_after_frontend' => '5', 'break_after_adminhtml' => '30', 'first_lifetime' => '600', 'bot_first_lifetime' => '60', 'bot_lifetime' => '7200', 'disable_locking' => '0', 'min_lifetime' => '60', 'max_lifetime' => '2592000' ] ],
Expected result (*)
Less lockout time
Actual result (*)
Lockouts +2s
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 24 (3 by maintainers)
Read this:
https://objectsource.co.uk/magento-2-performance-issue-with-sessions/
BTW I used Redis with locking disabled for almost a year now, including Black Friday and no issues whatsoever. It is much faster with locking disabled and there are no race conditions to be afraid of.
@GuiltyNL thank you, we’ve found that article as well. We’ve disabled locking, which helps lots indeed.
I’ve come up with an acceptable solution for this: https://github.com/colinmollenhour/php-redis-session-abstract/issues/50
To temporarily fix this issue, here are the patches to apply:
On
colinmollenhour/php-redis-session-abstractmodule => implement-write-lock-and-diff-patch.txtAnd on
magento/frameworkmodule => set-php-serialize-handler-patch.txtIf you want the full story and a potential definitive fix: https://github.com/magento/magento2/issues/34758#issuecomment-1312524791
@engcom-Hotel it’s my understanding that disabling the locking mechanism can result in race conditions and severe session data loss in high traffic websites. Why did you close this issue when in reality disabling the locking mechanism is a workaround to the real issue and not a solution? The underlying issue is that multiple simultaneous requests like ajax requests on the checkout will cause huge locks on the session, that can span over seconds causing huge delays in page loads.
We actually face the same issue and trying to find an alternative to disabling the locking mechanism.
Would you be so kind as to reopen the issue?
Moreover, I notice this can happen if using files for session too because php will by default lock the session files also.
An example here
We get similar hanging profiles with REDIS and FILES as session storage.
Is there any update about this issue? I am using one custom payment method which redirects to the bank page for payment. The module used afterPlaceOrder method to redirect the customer to the bank page and created a controller where they are trying to get orderId using checkoutSession->getLastRealOrderId() function. After debugging, I found that this orderId is undefined.
FYI, we are using Redis for caching and the module has disabled FPC from the layout of the page by making block cacheable false.
✅ Jira issue https://jira.corp.magento.com/browse/AC-2062 is successfully created for this GitHub issue.