I have some Drupal sites and the one common problem on them: very large cache with very slow processing and therefore the sites work very slow. I have enabled all caches and set them to long lifetime. But the sites are still slow. My server has 4GHz frequency and 4G RAM. DB queries log shows me that all queries takes 100-300ms summary.

When I perform profiling with xhprof I see that the largest part of wall time is used by serialize, unserialize and array_map functions. So i suppose it is because of large amount of serialized data stored in cache. So the data can be get from DB quickly but is processed by CPU very slowly.

So what should I do with the issue? How can I reduce cached data amout or store not serialized data in cache?

1 Answer 1


If a large part of your time is spent with serialize then that might point to some broken code; as in things keep getting serialized to be stored in the cache/db but it keeps on having a cache miss, otherwise you should only see unserialize with heavy cache usage.

The pattern you're pointing to sounds like you have some code that is abusing the variables table. Inside variable_initialize() it runs array_map with serialize, and variable_set() calls serialize. I would check the max_allowed_packet value inside of MySQL; my preference is to set it to 32M.

If you can provide more details, I can give you a better answer. I will say that using PHP7 should give you a big speedup if you haven't done so.

  • I have max_allowed packet set to 100M, is it excess? so should I reduce this parameter? I thought about php 7 (or simply 5.6), but now the server runs 5.3 because I need compatibility with some old Drupal 6 sites that are also on the site. Will PHP7 be compatible with php 7? Aug 23, 2016 at 4:29
  • 100m is good. This grep will show any php7 code issues twitter.com/mcarper/status/725899300828389378
    – mikeytown2
    Aug 23, 2016 at 5:14
  • I updated php to 7 and gote incredible performance advantage, 0.2-0.5s page generation time agains 2-5s, thanks! Aug 24, 2016 at 11:58

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.