0

I've installed Drupal (and CiviCRM within Drupal) on shared hosting my group's host assures me is adequate (though they refuse to enable PHP caching like APC on it). It's generally far slower than my installs on other servers or my home Mac. Even the simple, completely default Drupal front page (which just shows one promoted story, the only extra blocks being from the Devel module) loads slowly. Just now it took a minute, and the Devel block reported the following slow queries. Any help solving or at least diagnosing the problem very welcome!

ms | # | where | ops | query | target

41.05 | 21 | DrupalDatabaseCache::getMultiple | P A E | SELECT cid, data, created, expire, serialized FROM drupal_cache_menu WHERE cid IN (:cids_0) default

32.97 | 21 | DrupalDatabaseCache::getMultiple | P A E | SELECT cid, data, created, expire, serialized FROM drupal_cache_menu WHERE cid IN (:cids_0) default

28.13 | 21 | DrupalDatabaseCache::getMultiple | P A E | SELECT cid, data, created, expire, serialized FROM drupal_cache_menu WHERE cid IN (:cids_0) default

4
  • Could you please specify what version of Drupal you are using? Thanks. Dec 13, 2011 at 20:52
  • Drupal 7 - a completely fresh install
    – tog22
    Dec 13, 2011 at 22:37
  • To be honest, running Drupal 7 on a server without APC would be... extremely unwise. And the hosting provider looses nothing by enabling it, so that's just them being crappy. Dec 14, 2011 at 17:56
  • Didn't mention this in my answer, since it is so basic, but don't forget to enable caching on the performance page ;) Feb 8, 2012 at 16:55

3 Answers 3

1

Devel is telling you how slow the query is. From what you wrote on your question it does not appear however to be telling you what is executing that query. I would attempt to locate the source of that query first, since your doctor can't issue you a prescription, if he does not know your ailment first.

I tried searching my D7 codebase for the string "drupal_cache_menu" and did not find anything. So perhaps that is coming from a contrib module? Otherwise it would have shown up in my search. Regardless, you can see the pattern I used to locate the code responsible for that query:

  1. Select a unique string from the query (I tried using an individual word).
  2. Search your whole codebase for that string.
  3. See if the matches returned from your search could possibly relate to the slow query.

Once you locate the source of the query then you will (most likely) be able to determine if the slow query was caused by:

  1. An error.
  2. A view (in which case all you have to do to solve the problem is set the caching for that View).
  3. Legit custom code (without errors) that just needs optimization, in this case you could implement Drupal's Cache API (the cache_get() and cache_set() functions) and maybe static caching as well. The nice thing about the Cache API is that you can benefit from implementing it even when you don't have external persistent cache stores such as Memcached and APC installed. Lullabot's now classic Caching guide for beginners might well help you out as well.
  4. Legit contrib code (without errors) that just needs optimization. In this case you would probably be better off consulting the module mantainer.

As you see, the corrective actions are too many to list, and which one you will take will depend on the source of the query.

1
  • Thanks for the detailed suggestion - will try it out and come back when I do (would vote your answer up beforehand if I had enough rep)
    – tog22
    Dec 13, 2011 at 22:37
0

Given the total time of one minute, a query that takes 40ms is slow but really not that relevant. That's ~0,06% of the total request time.

Make sure that you don't trigger a known issue in Drupal 7: When you have modules enabled which are not found on the file system, this triggers a complete scan of the file system on every request, see http://timonweb.com/advice-may-help-you-if-your-drupal-7-has-started-run-slowly

0
0

The query causing that is in core drupal cache.inc, inside getMultiple().

2

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.