wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Adding exclusive lock (to avoid unnecessary CPU usage) when WP Rocket knows a page can be cached?

Open trendymail opened this issue 2 years ago • 5 comments

Hello!

I am just wondering why "maybe_process_buffer()" doen't use an exclusive lock when it detects that a page can be put in cache.

For instance, if a page is not in cache and there are 10 simultaneous requests to it within a short laps of time, then WP Rocket will let PHP render this page from scratch many times until a cached version is written and detected.

Is it intended? (Maybe yes, I am unaware of possible gotchas)

In Varnish, this process is called "request coalescing": fetch/process a resource once (lock) then deliver it to any pending requests.

Have a great day!

trendymail avatar Jul 24 '22 22:07 trendymail

Hello @trendymail and thank you for starting the discussion.

@Tabrisrp what would be your opinion here? 🤔

piotrbak avatar Jul 25 '22 11:07 piotrbak

It's an interesting idea, I don't know if it's something that can be achieved through PHP though.

remyperona avatar Jul 25 '22 13:07 remyperona

AFAIK, mkdir() is atomic (except over NFS, SSHFS, other?) so this function could be used to set/get an exclusive lock in PHP.

Not sure that PHP flock() is thread safe.

trendymail avatar Jul 25 '22 20:07 trendymail