-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Storing sessions in Redis causes longer loads #32754
Comments
Hi @vrielsa. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. Please, add a comment to assign the issue:
🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
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. |
Hi @engcom-Bravo. Thank you for working on this issue.
|
Hi @engcom-Echo. Thank you for working on this issue.
|
@GuiltyNL Indeed we use this also for long! No side effects :-) |
Hi @vrielsa , It would be really helpful, if you can provide us with more information regarding the steps to re-produce the issue Thanks |
Hello @vrielsa, It seems that your issue has been resolved by disable locking in Redis. And also we have not received any update from your side from past 14 days, so we are closing this issue for now. If you still facing any issue, either you can reopen this ticket or create new ticket. Thanks |
Hi @engcom-Hotel. Thank you for working on this issue.
|
@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. |
@ioweb-gr I can confirm that there are no issues at al when you disable the locking. I've tested it during Black Friday resulting in 180 to 300 orders per hour. With no issues at all. |
@GuiltyNL I've actually had issues when disabling session locking \Magento\Checkout\Model\Session:getLastRealOrderId() would sometimes return null after redirection It may be something else causing but just saying that the default behaviour is faulty, it doesn't mean we should resort to a workaround as it might not work in all cases so in my opinion this shouldn't be closed. |
:( Shoot! Strange that it is running without issues on our server. :( |
yeah I know it's a bummer :( I thought it would solve it quickly for us too |
@GuiltyNL Have you tried tuning the parameters for: session-save-redis-max-concurrency https://devdocs.magento.com/guides/v2.4/config-guide/redis/redis-session.html |
The recommendation is to set to 10% of the php processes of the server. For me with about 90 fpm processes concurrently I raised from 6 to 9 Then just for kicks raised to 15 and 30. The issue remains, in certain page loads it would take 1.5 to 5 seconds longer waiting on the redis session to start. I profiled with blackfire and other profilers continuously I could only mitigate this by offloading session storage to the DB. But this increased mysql CPU usage a lot. |
Hi @engcom-Echo. Thank you for working on this issue.
|
Hi @vrielsa, We tried again to reproduce it on Magento 2.4.1/2.4-dev but the issue is not reproducible on the local system as we are not able to generate the required traffic. But as given in the ticket we have analysed the Redis session code file (src/Cm/RedisSession/Handler.php, line no 554). After analysis, I found the following code which is the possible reason for the delay in request also it is logging the wait lock activity as well.
By looking at the code and its implementation confirming this issue. Thank You |
✅ Jira issue https://jira.corp.magento.com/browse/AC-2062 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Echo. Thank you for verifying the issue. |
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. |
Yes, no difference in performance. |
Pretty sure this is happening to most of our clients under high load. |
I've come up with an acceptable solution for this: colinmollenhour/php-redis-session-abstract#50 To temporarily fix this issue, here are the patches to apply: On And on If you want the full story and a potential definitive fix: #34758 (comment) |
Preconditions (*)
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.
The text was updated successfully, but these errors were encountered: