Why Drupal doesn't use special Memory Limit (ini_set) in Cache Clearing Script?

Events happening in the community are now at Drupal community events on www.drupal.org.
4lvin's picture

In Drupal 7, i have found that CLEAR CACHE (on the Web Panel) is using extreme high Memory resource. Giant projects like mine, needs over 350MB to that process.

  • Then i set 400MB inside php.ini

So as far as i have investigated, i have found that having high memory limit (Globally) is totally the damage to the overall Performance because every single script is using that limit in memory.

  • Then i found, we can use separate/runtime setting as
    ini_set('memory_limit',____)

    only for the specific scripts.

So my question here is:

  • Why Drupal by default is NOT HAVING this ini_set('memory_limit',____) separately in Cache Clearing Script (as hardcoded or in Panel Setting, etc) ?

Comments

Just a slight clarification

dalin's picture

Just a slight clarification on what memory_limit is and how it works. It does not mean that every execution of every PHP script uses that much memory. It is a limit where the process is killed if it uses more memory than memory_limit. This can however have an effect on future requests, depending on how you've setup your webserver (ex. With the standard Apache + prefork MPM + mod_php if a script uses a lot of memory then that Apache child thread will keep the memory allocated until it gets killed as per MaxRequestsPerChild).

That said, yes a cache clear can consume a lot of memory. All those data structures need to be rebuilt. Drupal could issue an ini_set() statement to increase memory_limit, but what would you set it to? Your site that needs 400MB is an unusual case. On some servers letting PHP run up to 400MB would take down the server. By the sounds of things you've got a badly behaving contrib or custom module. In theory rebuilding a data structure from scratch shouldn't use more memory than just pulling it from the cache, so there could be a bug in there somewhere (though in reality sometimes using more memory is necessary).

It should also be noted that you pretty much never want to do a full cache clear on a production site. Only clear what you need to (ex. if you are deploying a CSS or JS change then just clear the cache_page and cache bins)

From Drupal's perspective it's better to fix the root issue than to attempt to cover it up (and possibly make things worse) by using ini_set(). If however that method works for you on this particular site, go for it.

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

From Drupal's perspective

Garrett Albright's picture

From Drupal's perspective it's better to fix the root issue than to attempt to cover it up (and possibly make things worse)

THIS THIS THIS THIS THIS THIS THIS THIS. If only every developer and site admin understood this… Or every client, for that matter.

Clear your caches with drush

skwashd's picture

I support what @dalin said.

One simple way to clear the cache without allocating excessive amounts of memory to Apache is to use drush to clear your cache. Most Linux distros these days configure php-cli to be unallocated unlimited memory. This way you can clear cache/s with all the memory you need, but not have a negative impact on the web front end.

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: