0

I have devel query log / page execution time enabled on my site and most of the queries which are slowing down my site are related to DrupalDatebaseCache.

DrupalDatabaseCache::set

Sample Query :

UPDATE cache SET serialized=:db_update_placeholder_0, created=:db_update_placeholder_1, expire=:db_update_placeholder_2, data=:db_update_placeholder_3 WHERE ( (cid = :db_condition_placeholder_0) )

INSERT INTO cache_menu (cid, serialized, created, expire, data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4)

Any clue what drupal is doing with caching and how to minimize it . thanks

####Update####

I installed Memcache but still DrupalDatabaseCache calls are being made which is making the site slow .

enter image description here enter image description here

13
  • 2
    How to minimize caching? That's not a good idea. The less you cache, the more resources will be used to prepare page content. The simple answer is get your site on better hardware, and/or configure the application servers correctly for your app
    – Clive
    Apr 22, 2014 at 10:31
  • thanks. Okay what if i move the site to a better hardware and result are not satisfactory. can you please suggest a way where i can benchmark my site before upgrading hardware.
    – brainHax
    Apr 23, 2014 at 8:24
  • 1
    XHProf is the easiest way to profile a PHP app in my experience, there's also a Drupal integration module. But you'll need to know how to interpret the results, not something we can teach you here I'm afraid. If it helps I'm running a 2.3 core i7 with 16gb ram and every site absolutely flies. Your mileage will vary depending on your exact situation of course, but basically get yourself the best computer you can afford.
    – Clive
    Apr 23, 2014 at 8:28
  • 1
    @brainHax I think you have a fundamental misunderstanding of what caching is/ how it works - changing the storage method couldn't possibly reduce the number of cache queries, that was never the aim of advising you to do that. The point of an in-memory cache is that it provides quicker storage/retrieval than the same thing coming from a database. You cannot reduce the number of cache queries without changing core code, simple as that. And if you do, your app will be slower because you're not caching any more. If your memory access is as slow as your disk access, you need a new computer!
    – Clive
    Apr 24, 2014 at 8:15
  • 1
    That line says to Drupal "when you're looking for the cache_form bin, get it from the database, not from the default which is set as memcache". You can try removing that line so cache_form is stored in memory, but the form cache is slightly different than the other bins, and general advice is to keep it in the database, or user's form submission experiences might be volatile. You can probably get away with it in memory on a dev site, but definitely don't do it on prod
    – Clive
    Apr 24, 2014 at 8:48

2 Answers 2

3

If you concerned with performance then you want to maximise caching, not minimise it!

Caching is used to store data once expensive (time consuming) processes have been used to prepare it. Then future page requests simply return the cached data and don't have to do the slow processing again.

By default Drupal stores it's cache in the database but as you've spotted this isn't always that fast. Using a module like APC or memcache allows you to store the cache in the servers memory, as opposed to having to write it to the DB so this is much faster.

To make the most of Druapl's caching functions I would also recommend taking a read of lullabot's excellent article: A Beginner's Guide to Caching Data in Drupal 7

6
  • 1
    Redis is also a very good option
    – Clive
    Apr 22, 2014 at 10:37
  • actually my site is still in dev. and the caching Queires are making the development slower day by day . (i keep on adding modules every once a while when needed ) . and devel reported that most of the time caching queries were taking. reset of the modules were doing fine . On a clean install of drupal the caching queries are not that much. (dev has couple of nodes only for testing)
    – brainHax
    Apr 22, 2014 at 13:00
  • I have already installed memcache, configured and dedicated 1.5 GB memory. Still drupal is executing queries mentioned in question in large numbers.
    – brainHax
    Apr 22, 2014 at 14:30
  • Hmm, you must have not set up memcache correctly then. I'm using it and with query logging enabled and I have no "INSERT INTO cache" queries at all. Have you altered settings.php to set your cache_backends, cache_default_class and cache_class_cache_form?
    – Felix Eve
    Apr 22, 2014 at 14:35
  • As an example I have these lines in my settings.php.
    – Felix Eve
    Apr 22, 2014 at 14:37
2

Getting memcache working correctly is the right answer. I'm leaving a link here for people who don't have the option of installing memcache and are looking for a solution: Fixes for MySQL Deadlocks in D7

Your Answer

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

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