REDIS cache for Mod_Pagespeed

76 views
Skip to first unread message

Rob

unread,
Mar 16, 2022, 8:22:35 AMMar 16
to mod-pagespeed-discuss
Hello everyone!
I've been using Mod_Pagespeed for many years now, and recently moved to REDIS for storing its optimized resources (using ModPagespeedRedisServer and ModPagespeedRedisDatabaseIndex). A regular disk cache is configured as well, as per instructions, though my understanding is that the bulk of cached resources will go to REDIS. It's working fine so far.

My question is about the need (or not) of persistence for the REDIS cache: We use sharding in Mod_Pagespeed (via ModPagespeedShardDomain) and Amazon Cloudfront as a CDN. Let's say I set up REDIS so it no longer saves itself to disk (ie. no persistence, it will start empty every time there is a restart). I understand Pagespeed will have to recreate the optimized resources each time it restarts and "warm up the cache" again. I'm fine with that. What I would like to know is if the optimized resources will get the same name, in other words, is their name based on the original file name, modification date and such with a hash function that creates the exact same file name each time as long as the resource didn't change?

If that is the case (the optimized resource name and URL doesn't change, even after a restart/recreation) it would mean the CDN does not have to re-fetch all the resources, things would work nicely. If on the other hand the resource names are random, and change with each time they are optimized, it would mean sending over multiple Gigabytes to the CDN with each restart, and that is something I would like to avoid.

I would like to set REDIS so it no longer uses a disk-based backend, and save a few Gb in storage (and unneeded disk writes), but not if it means sending all those optimized resources over to the CDN with every restart.

Anyone know the answer to this one?
Thanks!

-Rob-

Joshua Marantz

unread,
Mar 16, 2022, 9:18:50 AMMar 16
to mod-pagesp...@googlegroups.com
The cache keys for optimized resources are deterministic based on original name and content-hash.  There is also a metadata cache key based on the original name and relevant context (Accepts header, <img> tag width/height, etc).

Modification date is not part of the cache key.




--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mod-pagespeed-discuss/9914efdd-2431-41cd-b485-820139bbec50n%40googlegroups.com.
Message has been deleted

Longinos

unread,
Mar 17, 2022, 6:39:30 AMMar 17
to mod-pagespeed-discuss
Hi
And... why don´t do a BGSAVE before shtdown? This make don´t need to warm u the cache each restart.

Rob

unread,
Mar 17, 2022, 8:09:29 AMMar 17
to mod-pagespeed-discuss
Seems REDIS does a SAVE no matter what, even if snapshotting is disabled, upon receiving a SHUTDOWN according to the docs:

When Redis receives a request to shut down by the SHUTDOWN command, or it receives a standard TERM signal, Redis will perform a SAVE, blocking clients from performing any further commands, and then shut down.

That would mean it always starts with a warm cache. I'll do a bit more experimenting to see if that's true or not

On another note, my previous reply got deleted, presumably by a moderator of this forum. It is disconcerting when messages disappear (and for no apparent reason, there was nothing untoward in there, just an attempt at clarification)...

-Rob- 

Longinos

unread,
Mar 17, 2022, 9:06:44 AMMar 17
to mod-pagespeed-discuss
Hi Rob

Perform a blocking SAVE if at least one save point is configured.
Note: A Redis instance that is configured for not persisting on disk (no AOF configured, nor "save" directive) will not dump the RDB file on SHUTDOWN,

So if no savepoint is configured, no save at shutdown is done unless you do a "shutdown save" command.

Rob

unread,
Mar 17, 2022, 9:53:56 AMMar 17
to mod-pagespeed-discuss
Testing revealed that when snapshotting is turned off (setting save "" in REDIS.INI) there is no auto-SAVE on a clean shutdown of REDIS. In any event, for the purpose of mod_pagespeed and wordpress I'm OK with a non-persistent cache. As long as the CDN doesn't have to reload all the optimized resources I'm fine with the cache having to warm up again on a restart.

Joshua Marantz

unread,
Mar 18, 2022, 8:08:57 AMMar 18
to mod-pagesp...@googlegroups.com
Yes, exactly!


On Fri, Mar 18, 2022 at 8:08 AM 'Rob' via mod-pagespeed-discuss <mod-pagesp...@googlegroups.com> wrote:
Thanks Josh!
I've read through the article, and while it does not explicitly state this, I gather from it and your reply that the mapped-URL-names for optimized resources are invariant as long as the original resource has not changed (and other conditions are met, such expiration date/time).

To answer my questions: That then means there is no need to have REDIS be persistent and store on disk. Clearing out the Pagespeed cache will not result in re-sending all the optimized resources to the CDN, it'll generate the same optimized URLs (and re-use what's already cached by the CDN).

If I got this wrong please correct me!
Cheers,

-Rob-

Reply all
Reply to author
Forward
0 new messages