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

CHAPTER 23 OPTIMIZING DRUPAL

is, often data is retrieved via multiple queries that could be combined into a single query, or needless node loading is performed.

Tip Drupal has an internal caching mechanism (using a static variable) when a node is loaded more than once per request. For example, if node_load(1) was called, node number 1 is fully loaded and cached. When another call to node_load(1) is made during the same web request, Drupal will return the cached results for the previously loaded node having the same node ID.

Optimizing Tables

SQL slowness can result from poor implementation of SQL tables in contributed modules. For example, columns without indices may result in slow queries. A quick way to see how queries are executed by MySQL is to take one of the queries you’ve captured in your slow query log, prepend the word EXPLAIN to it, and issue the query to MySQL. The result will be a table showing which indices were used. Consult a good book on MySQL for details.

Caching Queries Manually

If you have very expensive queries that must be performed, perhaps the results can be manually cached by your module. See Chapter 16 for details on Drupal’s cache API.

Changing the Table Type from MyISAM to InnoDB

Two common choices for MySQL storage engines, often called table types, are MyISAM and InnoDB. Drupal uses InnoDB by default.

MyISAM uses table-level locking, while InnoDB uses row-level locking. Locking is important to preserve database integrity; it prevents two database processes from trying to update the same data at the same time. In practice, the difference in locking strategies means that access to an entire table is blocked during writes for MyISAM. Therefore, on a busy Drupal site when many comments are being added, all comment reads are blocked while a new comment is inserted. On InnoDB, this is less of a problem, since only the row(s) being written get locked, allowing other server threads to continue to operate on the remaining rows. However, with MyISAM, table reads are faster, and data maintenance and recovery tools are more mature. See http://dev.mysql.com/tech-resources/articles/storage- engine/part_1.html or http://dev.mysql.com/doc/refman/5.1/en/storage-engines.html for more information on MySQL’s table storage architectures.

To test whether table-locking issues are the cause of slow performance, you can analyze lock contention by checking the Table_locks_immediate and Table_locks_waited status variables within MySQL.

522

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