背景:
我们有很大的平面文件跨度约60 We,并正在插入数据库。在插入过程中,我们正在经历增量性能降级。
问题表
CREATE TABLE `entity_briefs` (
`entity_brief_id` bigint(11) NOT NULL auto_increment,
`entity_id` bigint(11) default NULL,
`entity_table_prefix` char(2) default NULL,
`string_1` varchar(255) default NULL,
`string_2` varchar(255) default NULL,
`zip` varchar(25) default NULL,
`phone` bigint(11) default NULL,
PRIMARY KEY (`entity_brief_id`),
KEY `idx_entity_id` (`entity_id`),
KEY `idx_entity_table_prefix` (`entity_table_prefix`),
KEY `idx_zip` (`zip`),
KEY `idx_string_1` (`string_1`),
KEY `idx_string_2` (`string_2`),
KEY `idx_phone` (`phone`)
);mysqltuner.pl输出:
>> MySQLTuner 1.1.1 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: xxxxx
Please enter your MySQL administrative password:xxxxx
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.85-community
[OK] Operating on 32-bit architecture with less than 2GB RAM
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 101M (Tables: 1344)
[!!] InnoDB is enabled but isn't being used
[!!] Total fragmented tables: 1
-------- Security Recommendations -------------------------------------------
ERROR 1142 (42000) at line 1: SELECT command denied to user 'xxxx'@'localhost' for table 'user'
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[--] Up for: 5d 15h 53m 55s (2M q [4.395 qps], 9K conn, TX: 1B, RX: 425M)
[--] Reads / Writes: 51% / 49%
[--] Total buffers: 34.0M global + 2.7M per thread (500 max threads)
[OK] Maximum possible memory usage: 1.3G (67% of installed RAM)
[OK] Slow queries: 0% (9/2M)
[OK] Highest usage of available connections: 1% (5/500)
[!!] Key buffer size / total MyISAM indexes: 8.0M/105.3M
[!!] Key buffer hit rate: 94.1% (72M cached / 4M reads)
[!!] Query cache is disabled
[OK] Temporary tables created on disk: 7% (101 on disk / 1K total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (64 open / 277K opened)
[OK] Open file limit used: 0% (127/18K)
[OK] Table locks acquired immediately: 99% (2M immediate / 2M locks)
[!!] Connections aborted: 38%
-------- Recommendations -----------------------------------------------------
General recommendations:
Add skip-innodb to MySQL configuration to disable InnoDB
Run OPTIMIZE TABLE to defragment tables for better performance
Enable the slow query log to troubleshoot bad queries
Set thread_cache_size to 4 as a starting value
Increase table_cache gradually to avoid file descriptor limits
Your applications are not closing MySQL connections properly
Variables to adjust:
key_buffer_size (> 105.3M)
query_cache_size (>= 8M)
thread_cache_size (start at 4)
table_cache (> 64)Requirement:为了加快插入速度,可以采用什么样的优化策略?
发布于 2010-02-05 03:45:32
一些一般性的建议,因为我对你没有灵丹妙药:
我不认为随着表大小的增长,插入的速度就不会减慢。数据库插入时间通常会随着数据库大小而变大,诀窍是在这种期望的情况下,设法使总体性能可以接受。
如果事情正在放缓,并且CPU没有固定,那么您很可能在数据库访问上受到I/O的限制。如果发现是这种情况,您可能希望尝试更快的驱动器、Raid 0、更快的驱动器控制器等。您甚至可以考虑在固态驱动器上构建数据库,然后在创建后将其复制到传统的硬盘驱动器中。对于mysql在文件系统上的随机访问行为,这些应该要快得多,尽管我知道随着时间的推移,它们将“耗尽”。尽管如此,你仍然可以得到一兆字节的固态存储低于10,000美元。
还可以很好地了解如何优化插入过程。正如您提到的那样,在插入过程中禁用索引,虽然它不会停止逐步减速,但应该会显着地加快整个过程。从您的描述中可以看出,您有某种类型的insert脚本逻辑,可以选择和插入,而不是简单加载平面文件。您正在每次插入中执行三次不同的查询,可能在客户端和数据库之间多次往返数据。特别是查看范围select,并确保该查询本身在表大小上没有不良的性能特征。
另一种可能是在这个问题上抛出更多的RAM,并将其用作磁盘缓存。如果正在运行这些范围选择的“其他表”在插入过程中没有被修改,那么也许您可以在内存中减少驱动器查找时的“其他表”,如果您确定搜索时间确实是这里的性能限制。
https://stackoverflow.com/questions/2204728
复制相似问题