开发者

Using a MySQL database is slow

开发者 https://www.devze.com 2023-02-05 23:21 出处:网络
We have a dedicated MySQL server, with about 2000 small databases on it. (It\'s a Drupal multi-si开发者_Python百科te install - each database is one site).

We have a dedicated MySQL server, with about 2000 small databases on it. (It's a Drupal multi-si开发者_Python百科te install - each database is one site).

When you load each site for the first time in a while, it can take up to 30s to return the first page. After that, the pages return at an acceptable speed. I've traced this through the stack to MySQL. Also, when you connect with the command line mysql client, connection is fast, then "use dbname" is slow, and then queries are fast.

My hunch is that this is due to the server not being configured correctly, and the unused dbs falling out of a cache, or something like that, but I'm not sure which cache or setting applies in this case.

One thing I have tried is the innodb_buffer_pool size. This was set to the default 8M. I tried raising it to 512MB (The machine has ~ 2GB of RAM, and the additional RAM was available) as the reading I did indicated that more should give better performance, but this made the system run slower, so it's back at 8MB now.

Thanks for reading.


With 2000 databases you should adjust the table cache setting. You certainly have a lot of cache miss in this cache.

Try using mysqltunner and/or tunning_primer.sh to get other informations on potential issues with your settings.

Now drupal makes Database intensive work, check you Drupal installations, you are maybe generating a lot (too much) of requests.

About the innodb_buffer_pool_size, you certainly have a lot of pagination cache miss with a little buffer (8Mb). The ideal size is when all your data and indexes size can fit in this buffer, and with 2000 databases... well it is quite certainly a very little size but it will be hard for you to grow. Tunning a MySQL server is hard, if MySQL takes too much RAM your apache won't get enough RAM.

Solutions are:

  • check that you do not make the connexion with DNS names but with IP
    (in case of)
  • buy more RAM
  • set MySQL on a separate server
  • adjust your settings

For Drupal, try to set the session not in the database but in memcache (you'll need RAM for that but it will be better for MySQL), modules for that are available. If you have Drupal 7 you can even try to set some of the cache tables in memcache instead of MySQL (do not do that with big cache tables).

edit: last thing, I hope you have not modified Drupal to use persistent database connexions, some modules allows that (or having an old drupal 5 which try to do it automatically). With 2000 database you would kill your server. Try to check mysql error log for "too many connections" errors.


Hello Rupertj as I read you are using tables type innodb, right?

innodb table is a bit slower than myisam tables, but I don't think it is a major problem, as you told, you are using drupal system, is that a kind of mult-sites, like a word-press system?

If yes, sorry about but this kind of systems, each time you install a plugin or something else, it grow your database in tables and of course in datas.. and it can change into something very very much slow. I have experiencied by myself not using Drupal but using Word-press blog system, and it was a nightmare to me and my friends..

Since then, I have abandoned the project... and my only advice to you is, don't install a lot of plugins in your drupal system.

I hope this advice help you, because it help me a lot in word-press.


This sounds like a caching issue in Drupal, not MYSQL. It seems there are a few very heavy queries, or many, many small ones, or both, that hammer the database-server. Once that is done, Drupal caches that in several caching layers. After which only one (or very few) queries are all that is needed to build up a page. Slow in the beginning, fast after that.


You will have to profile it to determine what the cause is, but the table cache seems like a likely suspect.

However, you should also be mindful of persistent connections - which should absolutely definitely, always be turned off (yes, for everyone, not just you). Apache / PHP persistent connections are a pessimisation that you and everyone else can generally do without.

0

精彩评论

暂无评论...
验证码 换一张
取 消