Cron runs seem to take longer and longer every day for this Drupal 8 site. Pretty much all of the installed modules with cron hooks seem to behave (runs rarely take longer than a couple of seconds). Except for system_cron() which seems to burn most of the time with garbage collection of the cache bins:
foreach (Cache::getBins() as $ cache_backend) { $ cache_backend->garbageCollection(); }
For a couple of days now the runs take long enough (30 mins?) to be stalled. That is, the run never completes. Writing to the cache does not work until the lock is timed out. There are no error messages except from other requests that get cache lock time outs during the long run.
What can be the cause of the cache bin garbage collection to be that slow.
Side note #1:
The cron run only takes less than a minute if I clear the cache right before the run. So this could be a workaround for now (1. clear cache (e.g. via drush), 2. run cron), but I would rather like to understand what is going on here and have a less hacky solution.
Side note #2:
The cron on this site has been kind of slow from the very beginning, when the site was set up (fall of ’17). Each run (every 30 mins) would take at least 20 seconds and block all access during that time, because of the cache locks. That’s why we only run cron at 3am, because there would be no users who are blocked. But with cron running only once a day, the run would not take 20 seconds, but rather many minutes. That time increased like every day until now, when it never finishes.