1

We are running Craft in a load-balanced environment according to the docs: https://craftcms.com/knowledge-base/configuring-load-balanced-environments

Once daily we need to execute craft gc/run to keep the system clean.

My question: is this something which needs to be done on each web-node serving craft or is it only necessary to run it once regardless of the amount of nodes behind the load-balancer.

Background:

  • If non-shared files are affected, it should run on all instances behind the LB
  • If only DB or Redis Caches are affected, we just run it once to avoid multiple executions

2 Answers 2

2

Assuming you’ve followed the knowledge base article and have centralised resources such as sessions, mutex, caches, the database, and logs, it should be safe to run garbage collection once on any single web server.

If anything that needs to be garbage collected is stored on each individual web server then you’re likely going to have to run it once per server. Alternatively, you could create a custom module that performs garbage collection only on specific items to avoid redundant gc calls.

1

Thanks Ben!

Here's an additional answer from Brad Bell (via Support), which I want to share with you as well:

Ben's answer is correct.

If everything is configured according to that article, all of Craft's native commands should just run on one node.

We have seen issues where people run a post-deploy console command that executes on every node, and that can actually cause some race conditions and subtle bugs depending on the command because the database is still a single point of resource contention.

So if you're in that post-deloy command scenario, you'll ideally want to ensure that post-deploy command only runs on one instance, as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.