Skip to content

usleep Statments in Cache Loader causing Pathological Page Load Times #22824

@astorm

Description

@astorm

Preconditions (*)

  1. Magento 2.3.1

Steps to reproduce (*)

  1. Clear Cache
  2. Load Page

Expected result (*)

Page loads in less than 30 - 45 seconds

Actual result (*)

Page loads in 30 - 45 seconds under unknown circumstances

If this is possible, I'd like to nominate a bit of code for removal/refactoring. It looks like it was introduced in Magento 2.3.1

acdc770#diff-cbe30020f802e5ab5b7cf6399e91e178

And currently lives here: https://github.com/magento/magento2/blob/2.3-develop/lib/internal/Magento/Framework/Cache/LockGuardedCacheLoader.php#L72

I've had reports from users/customers (who will hopefully be able to comment below) of one of my extensions (Commerce Bug) that they're seeing uncached Magento 2 page loads taking between 30 and 45 seconds, with the majority of this being spent in this call to usleep. The delay is inconsistent and seems dependent on resource contention in the host system (i.e. it may only show up when/if file loading is slower/faster than normal, a certain number of simultaneous requests is present, etc)

I'm reasonably certain my extension isn't to blame -- it's just that my extension makes an early call to Magento\Developer\Helper\Data::isDevLoaded in an event observer, and is the first thing to trigger this cache being loaded. As mentioned the problem is inconsistent, so I can't be fully certain what is or isn't to blame.

It also seems like at least one other extension vendor has this problem.

https://twitter.com/jissereitsma/status/1126746140534165504

Beyond this being a specific problem that real users have run into -- I don't think this is the right solution for the problem, (the problem as listed in the commit comment)

MC-6275: Conflict of simultaneous write in Redis cache

  1. The pattern in use here may be OK in a language with asynchronous callbacks, but PHP's execution model is single threaded and synchronous. This means the call to usleep blocks everything in the request. This is what's causing the 30 - 45 seconds uncached load times for users. In most organizations I've worked for and projects I've worked on a sleep statement of any-kind in user facing PHP code would have a high bar to make it into the repo -- while MC-6275 is an important issue to solve, I'm not sure this is the right solution for this problem

  2. If this code is meant to solve simultaneous Redis writes -- then it belong in the redis cache implementation. Having this code up here means that every cache implementation (Redis, Filesystem, etc) is effected.

  3. The recent change to move this from a .1 second sleep to a .02 second sleep are a welcome improvement, but this seems like a work around that's destined to cause future problem for users and customers.

Metadata

Metadata

Assignees

Labels

Component: CacheIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions