简体   繁体   English

Drupal 数据库性能调整 - 从 MyISAM 切换特定表到 InnoDB

[英]Drupal database performance tuning - switching particular tables to InnoDB from MyISAM

I've got a drupal site that gets low traffic, but has tons of new content being added by a custom feed importer module.我有一个 drupal 网站,它的流量很低,但自定义提要导入器模块添加了大量新内容。 This module creates nodes and associated taxonomies for imported articles.该模块为导入的文章创建节点和关联的分类法。

Currently, I believe ALL our drupal tables are MyISAM.目前,我相信我们所有的 drupal 表都是 MyISAM。 I was considering switching the heavy write tables:我正在考虑切换繁重的写表:

  1. node节点
  2. watchdog看门狗
  3. sessions会话
  4. accesslog访问日志
  5. What other tables would you consider?您还会考虑哪些其他表?

To InnoDB.到 InnoDB。

Do you think this is a good idea?你认为这是个好主意吗? Am I likely to see a performance gain?我可能会看到性能提升吗? The reason I'm looking at this as part of my overall solution is that, on import, mysqld is running out of memory often and taking the entire system down.我将其视为整体解决方案的一部分的原因是,在导入时,mysqld 经常用完 memory 并使整个系统停机。 It ONLY happens on import.它仅在导入时发生。

I'll end up seeing things like this:我最终会看到这样的事情:

xml import at [01/Jun/2011:13:26:38 -0400] "GET /import/xml_import HTTP/1.1" 200
....
14:02:38 [ERROR] /usr/libexec/mysqld: Out of memory (Needed 1049152 bytes)

The box is x32 so we are limited to the amount of memory we can allocate to mySql.盒子是 x32,所以我们仅限于 memory 的数量,我们可以分配给 mySql。 We also have PHP, JAVA, SVN and more running on this box... it's taxed as is.我们还有 PHP、JAVA、SVN 和更多运行在这个盒子上......它按原样征税。 heh.呵呵。

So, any input on performance tuning the db in general would be appreciated, I'm doing the research now.因此,一般来说,任何关于性能调整数据库的输入都会受到赞赏,我现在正在做研究。

TIA. TIA。

EDIT: (I've included my current my.cnf):编辑:(我已经包含了我当前的 my.cnf):


[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
tmpdir=/var/lib/mysql/tmp
#old_passwords=1
skip-locking
key_buffer = 2048M #doubled from 1024
max_allowed_packet = 16M
table_cache = 5000
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 64 #doubled from 32
thread_concurrency = 8
query_cache_size = 1024M #doubled from 512
tmp_table_size=1024M
max_heap_table_size=1024M
back_log = 100
max_connect_errors = 10000
join_buffer_size=1M
open-files = 20000

interactive_timeout = 600
wait_timeout = 600

ft_min_word_len=3
ft_stopword_file=''
max_connections=1000

#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
#innodb_log_file_size = 100M

#innodb_buffer_pool_size = 384M
#innodb_additional_mem_pool_size = 20M


#log-slow-queries=/var/lib/mysqllogs/slow-log
#long_query_time=2   
#log-queries-not-using-indexes

#log-bin=/var/lib/mysqllogs/bin-log
#log-slave-updates
#expire_logs_days = 14
server-id       = 1 

[mysql.server]
user=mysql
#basedir=/var/lib  

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
open_files_limit=65536

If you know for a certainty that the website will be low trafficked, by all means remain in MyISAM. 如果您确定该网站的访问量较低,请务必保留在 MyISAM 中。

However , should that pattern ever change and you become high traffic again, you could configure everything into InnoDB for two major reasons但是,如果这种模式发生变化并且您再次成为高流量, 您可以将所有内容配置到 InnoDB 中,主要有两个原因

REASON #1 : InnoDB does row level locking.原因 #1 :InnoDB 执行行级锁定。 As for MyISAM, any INSERT, UPDATE, or DELETE query executed will cause a full table lock.对于 MyISAM,任何执行的 INSERT、UPDATE 或 DELETE 查询都会导致全表锁定。 Even in a low trafficked website, the possiblility exists of two or more DB Connections Locking the Same Table.即使在低流量网站中,也可能存在两个或多个数据库连接锁定同一个表。 With InnoDB, that possibility is totally eliminated.使用 InnoDB,完全消除了这种可能性。

REASON #2 : InnoDB Caches Data and Indexes.原因 #2InnoDB 缓存数据和索引。 MyISAM only caches Index Pages. MyISAM 只缓存索引页。

The key cache (sized by key_buffer_size) hold index pages for MyISAM tables.键缓存(大小由 key_buffer_size 决定)保存 MyISAM 表的索引页。 There is always disk I/O to read data from a MyISAM.总是有磁盘 I/O 来从 MyISAM 读取数据。 A record read for the first time will cache the Index Pages used to find the row in to key cache.第一次读取的记录会将用于查找行的索引页缓存到键缓存中。 Subsequent lookups will find the key needed in the key cache, but there will always be mandatory disk I/O to get the data.随后的查找将在密钥缓存中找到所需的密钥,但总会有强制性的磁盘 I/O 来获取数据。 With InnoDB, both Data and Index Pages Reside in the InnoDB Buffer Pool (size by innodb_buffer_pool_size).对于 InnoDB,数据和索引页面都驻留在 InnoDB 缓冲池中(大小为 innodb_buffer_pool_size)。 Disk I/O is dramatically reduced with everything cached in the Buffer Pool.缓冲池中缓存的所有内容都大大减少了磁盘 I/O。

I have always recommended Drupal databases using InnoDB instead of MyISAM.我一直推荐使用 InnoDB 而不是 MyISAM 的 Drupal 数据库。 It is actually easy to convert using straight MySQL . 使用直接 MySQL 实际上很容易转换

Until then, MyISAM is all the firepower you need, especially on servers with modest RAM .在那之前,MyISAM 是您所需要的全部火力, 尤其是在 RAM 适中的服务器上

Generally speaking, InnoDB is slower than MyISAM as InnoDB is atomic while MyISAM is not.一般来说,InnoDB 比 MyISAM 慢,因为 InnoDB 是原子的,而 MyISAM 不是。 With the tradeoff of performance you gain data reliability.通过权衡性能,您可以获得数据可靠性。

If you can, disable indexes before import, you will see a performance gain.如果可以,请在导入前禁用索引,您将看到性能提升。 Its more efficient to rebuild the indexes all at once rather than for every single insert.一次重建所有索引而不是每次插入都更有效。

You do not want to configure mysql to exceed available memory.您不想将 mysql 配置为超过可用的 memory。 The memory settings are spread across several settings. memory 设置分布在多个设置中。 You can use something like this http://mysqltuner.pl/mysqltuner.pl to determine how well your mysql install is tuned.您可以使用类似这样的 http://mysqltuner.pl/mysqltuner.pl来确定您的 mysql 安装的调整程度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM