Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
54
Добавлен:
14.03.2016
Размер:
12.64 Mб
Скачать

CHAPTER 23 OPTIMIZING DRUPAL

The first obvious suggestion is “don’t do that”: don’t make frequent call-outs to an external web service you have no control over, and instead use some other strategy, such as a background process that periodically pulls the external content and caches it locally. But if you insist, then at least use PHP’s stream_set_timeout() or decrease the default_socket_timeout in php.ini so that unresponsive connections are dropped within three seconds.

Decreasing Server Timeouts

There are a variety of timeout settings in each layer of a LAMP server stack. The importance of lowering timeout settings is that it prevents a slow or unresponsive service from causing a process load pile-up on your web server. It is advisable to decrease all timeout settings as low as you can tolerate.

For example, Apache’s mod_fcgid has a setting called BusyTimeout, which by default waits for 5 minutes before terminating a long-running PHP process, which you may decrease down to 30 seconds, considering that any page taking longer than 30 seconds to deliver ought to just fail rather than tie up your web server for another 4 minutes.

Other key timeouts to consider decreasing include Apache’s Timeout setting, PHP’s max_execution_time, PHP’s default_socket_timeout, Nginx proxy_read_timeout, as well as a variety of Linux kernel TCP settings.

One notable PHP process in Drupal that may be allowed to run longer than five minutes is cron.php, which invokes all calls to Drupal’s hook_cron(). It is advisable to delegate only fast, simple tasks to hook_cron() and heavier tasks to crontab shell scripts.

Database Optimization

Drupal does a lot of work in the database, especially for authenticated users and custom modules. It is common for the database to be the cause of the bottleneck. Here are some basic strategies for optimizing Drupal’s use of the database.

Enabling MySQL’s Query Cache

MySQL is the most common database used with Drupal. MySQL has the ability to cache frequent queries in RAM so that the next time a given query is issued, MySQL will return it instantly from the cache. However, in most MySQL installations, this feature is disabled by default. To enable it, add the following lines to your MySQL option file; the file is named my.cnf and specifies the variables and behavior for your MySQL server (see http://dev.mysql.com/doc/refman/5.1/en/option-files.html). In this case, we’re setting the query cache to 64MB:

# The MySQL server [mysqld] query_cache_size=64M

512

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]