Skip to content

Redis Session locking makes add to cart action very slow and cpu spikes #39824

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

Open
5 tasks
ioweb-gr opened this issue Apr 17, 2025 · 11 comments
Open
5 tasks

Redis Session locking makes add to cart action very slow and cpu spikes #39824

ioweb-gr opened this issue Apr 17, 2025 · 11 comments
Labels
Area: Framework Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Reported on 2.4.8 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@ioweb-gr
Copy link
Contributor

Preconditions and environment

  • Magento version 2.4.8
  • Use redis sessions and set disable_locking = 0

Steps to reproduce

  1. Create a profile with 10000 simple products in a category
  2. Visit the category
  3. Set pagination to something like 50 so that you can easily do the test
  4. Start adding the products to cart one by one in sequence without waiting

You will notice lots of profile recordings like this

Image

First of all the speed of adding to cart shouldn't be affected so hard.

Secondly as a side-effect, while this is occuring the php-fpm requests are hanging in the CPU occupying fpm children and leading to the cores being fully utilized preventing other operations from occurring.

When this happens in bulk , e.g. from spiders like META, Google , Bytedance etc etc the load on a server can go really high.

Expected result

Add to cart is processed normally

For example if we disable locking

Image

Actual result

The add-to-cart action slows down a lot and especially the more products we have to the cart it increases further

Additional information

No response

Release note

No response

Triage and priority

  • 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”.
Copy link

m2-assistant bot commented Apr 17, 2025

Hi @ioweb-gr. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 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, join the Community Contributions Triage session to discuss the appropriate ticket.

@github-project-automation github-project-automation bot moved this to Ready for Confirmation in Issue Confirmation and Triage Board Apr 17, 2025
@engcom-Bravo engcom-Bravo added Reported on 2.4.8 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it labels Apr 17, 2025
@engcom-Hotel
Copy link
Contributor

Hello @ioweb-gr,

Thanks for the report and collaboration!

We have tried to reproduce this issue in the latest 2.4-develop branch and 2.4.8 vanilla instance but it seems the issue is not reproducible for us. We have followed the below steps to reproduce the issue:

  1. Enable redis session via the below command:
    bin/magento setup:config:set --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-log-level=4 --session-save-redis-db=2 --session-save-redis-disable-locking=1

  2. Please refer to the below screenshot from the app/etc/env.php file:

Image

  1. Ran performance toolkit to install the 10k simple products:

Image

  1. For us when we starts adding product into the cart, the request has been completed in the milleseconds. Please refer to the below screencast for the same:
Category-1.webm

Please let us know if we missed anything.

Thanks

@engcom-Hotel engcom-Hotel self-assigned this May 2, 2025
Copy link

m2-assistant bot commented May 2, 2025

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • 5. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Hotel engcom-Hotel added Issue: needs update Additional information is require, waiting for response and removed Issue: ready for confirmation labels May 2, 2025
@ct-prd-projects-boards-automation ct-prd-projects-boards-automation bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board May 2, 2025
@ioweb-gr
Copy link
Contributor Author

ioweb-gr commented May 2, 2025

In your install command you have set disable-locking=1 not 0 that's why it's not replicating

Please set disable-locking to 0 and retry

@engcom-Hotel
Copy link
Contributor

Hello @ioweb-gr,

We have made the disable-locking as 0 and try to reproduce the issue again, and added almost 71 products to the cart. But the issue is still not reproducible for us.

Please refer to the below screencast:

1-min.mp4

Let us know if we missed anything.

Thanks

@ioweb-gr
Copy link
Contributor Author

ioweb-gr commented May 5, 2025

OK I checked your video. It seems you're adding the item , pausing until it's added, adding the item, pausing until it's added etc etc.

Try it without pausing in between pressing add to cart button and check the network waterfall in the inspector. Only then will locking take place for a really long period while still occupying the php-fpm processes

@engcom-Hotel
Copy link
Contributor

Hello @ioweb-gr,

Thanks for the reply!

But still we are unable to reproduce the issue. Can you please share some screencast, it helps us in issue reproduction?

Thanks

@ioweb-gr
Copy link
Contributor Author

ioweb-gr commented May 7, 2025

Here's an example with a simplified way to reproduce it

Add a few products in your cart and then visit the category page.

On the console tab write this command to simultaneously click on all add to cart buttons

document.querySelectorAll('.action.tocart.primary').forEach(el => el.click());
firefox_i8HKewAisp.mp4

Watch the network tab after filtering for cart/add

You will notice the duration fluctuates due to session locking

The problem comes because nowdays this can be spammed a lot by a lot of automated tools bringing down the whole server. I've seen loads spike up to 500 on a 48 core machine because someone is spamming add to cart button.

That's effectively a DoS attack by just clicking add to cart button

@engcom-Hotel
Copy link
Contributor

Hello @ioweb-gr,

Thanks for more information on this issue. We are able to reproduce this issue now in the 2.4-develop branch. Please refer to the below screenshot for the reference:

Image

Hence confirming the issue.

Thanks

@engcom-Hotel engcom-Hotel added Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Priority: P3 May be fixed according to the position in the backlog. Area: Framework and removed Issue: needs update Additional information is require, waiting for response labels May 8, 2025
@ct-prd-projects-boards-automation ct-prd-projects-boards-automation bot moved this from Needs Update to Confirmed in Issue Confirmation and Triage Board May 8, 2025
@ct-prd-projects-boards-automation ct-prd-projects-boards-automation bot moved this to Ready for Development in Low Priority Backlog May 8, 2025
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-14609 is successfully created for this GitHub issue.

Copy link

m2-assistant bot commented May 8, 2025

✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Reported on 2.4.8 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Ready for Development
Development

No branches or pull requests

4 participants