Can someone explain what is local node caching?

Can someone explain what is local node caching?

by Diane Soini -
Number of replies: 10

What is local node caching? And what are the differences between these. What is the purpose/difference between tempdir, cachedir and localcachedir, seeing as how if I observe the editpdf document conversion it uses localcachedir as a temporary file location.

//     $CFG->tempdir = '/var/www/moodle/temp';        // Directory MUST BE SHARED by all cluster nodes.
//     $CFG->cachedir = '/var/www/moodle/cache';      // Directory MUST BE SHARED by all cluster nodes, locking required.
//     $CFG->localcachedir = '/var/local/cache';      // Intended for local node caching.

Average of ratings: Useful (1)
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
If you have multiple web servers pointing at the same Moodle database, tempdir/cachedir must be on a directory that is shared across all web servers (nodes) where-as "localcachedir" can be a local directory on the webserver and not shared.

Usually shared file systems are slower than a local disk, and you typically want cache's to be "fast" - so where you can, you use local disk/local filesystem to store a cache.

If you host your Moodle system on a single webserver - just ignore it completely.

Does that help?
Average of ratings: Useful (3)
In reply to Dan Marsden

Re: Can someone explain what is local node caching?

by Diane Soini -
That didn't answer the question. What are "local nodes"? Why does localcache appear to store temp files unrelated to htmlpurifier, js, mustache, requirejs, and theme files?
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Cool - let me try again. smile

At a high level - it's referring to individual webservers as "nodes"

"local node" is referring to a locally hosted file system (not shared across multiple webservers) on a single webserver.
If you think about this in the context of "old school" clusters it might make more sense.
eg a bare-metal web server with a hard-drive in the server - the hard-drive in that web server is "local" to that web server.
In an old-school cluster you'd have a separate file server in the rack with it's own hard-drive and you would share that file server across all your web servers. accessing this file-server is slower than accessing the local disk on the web-server itself.
Some things (like student uploaded files/images/videos hosted on the site.) have to be available to all webservers so you put it on the slower "shared" disk.
Some things don't need to be stored on both servers and can use the faster "local node" or faster local file system.

localcache is basically a "bucket" used by multiple things in Moodle when the developer writing the code decides "this doesn't need to be on shared disk - use the fast option"

does that help?
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Luis de Vasconcelos -
In reply to Luis de Vasconcelos

Re: Can someone explain what is local node caching?

by Diane Soini -
From https://docs.moodle.org/dev/Server_clustering_improvements_proposal
"All files there must use unique revision numbers or hashes because the cached data cannot be invalidated by other mechanism - it will support only adding of new files, but no file deletes or overrides. The $CFG->localcachedir will be growing over time, all local cache files will be deleted during purge_all_caches() (automatically during upgrades)."

This appears to be untrue as I have watched this directory add temp files and remove them when the editpdf document conversion script runs. I think I have found a bug somewhere in the application. I have another post where I am trying to find out what part of the application is writing files to this directory. These files have a pattern of:
$CFG->localcache/a322c22c-36b3-4688-ae50-96390b85bf54/a322c22c-36b3-4688-ae50-96390b85bf54Assignment images-20210208.zip.8yt68t

I have not been able to find what script produces a file with that naming pattern.
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
yeah - that's an old doc - written as a "proposal" prior to development - the final implementation is a bit different... and has evolved over time since Moodle 2.6.
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Diane Soini -
Also another question, if we've set localcachedir does that change where tempdir is? Do both need to be set? There is a tempdir in the dataroot directory. But something is using localcache as a tempdir. I am watching it happen.
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
tmpdir and localcachedir are both "types" of temporary storage - localcachedir is used when files don't need to be stored on shared disk - tmpdir is used when it needs to be on shared disk.

Quite a lot of diferent core code will end up storing stuff in localcachedir - for example calls to "get_request_storage_directory" will return a path in localcachedir.
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Diane Soini -
We figured out what was going on. mod_folder uses localcache as a scratch space to create a zip file when you click on "download folder". We had localcachedir pointing at ramfs and download folder used up all the space.
In reply to Diane Soini

Re: Can someone explain what is local node caching?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
ah - missed that you were having problems becuase it was running out of space - localcachedir does needs a decent amount of available space sad

Nice work tracking it down!