到日志文件,但并不马上调用fsync来刷新IO缓存,而是每秒只做一次磁盘IO缓存刷新操作(性能和数据安全性都在中间)
12.设置log file size,控制检查点:
a.可以通过一些方法计算innodb每小时产生的日志量并估计合适的innodb_log_file_size值
13.调整innodb_log_buffer_size:
a.可以通过增大innodb_log_buffer_size来减少日志写磁盘操作,从而提高事务处理的性能
14.调整max_connections,提高并发连接:
a.max_connections控制允许连接到mysql数据库的最大数量,默认值是151
15.调整back_log:
a.如果需要数据库在较短时间内处理大量连接请求,可适当增大back_log的值
16.调整table_open_cache:
a.在未执行flush tables命令的情况下,如果mysql状态变量opened_tables的值较大,就说明table_open_cache设置的太小,应适当增大
17.调整thread_cache_size:
a.可以通过计算cache的失败率threads_created/connections来衡量thread_cached_size的值是否合适。此值越接近1,说明线程cache命中率越低,应考虑适当增加thread_cache_size的值
18.innodb_lock_wait_timeout的设置:
a.innodb_lock_wait_timeout可以控制innodb事务等待行锁的时间,默认值是50ms.
b.对于需要快速反馈的交互式OLTP应用,可以将行锁等待超时时间调小,以避免事务长时间挂起
c.对于后台运行的批处理操作,可以将行锁等待超时时间调大,以避免发生大的回滚操作
二、实践:
?
mysql> use sakila;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show engine innodb status \G;
*************************** 1. row ***************************
Type: InnoDB
Name:
Status:
=====================================
151102 7:13:01 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 15 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 113 1_second, 113 sleeps, 7 10_second, 47 background, 47 flush
srv_master_thread log flush and writes: 113
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 18, signal count 18
Mutex spin waits 8, rounds 240, OS waits 7
RW-shared spins 11, rounds 330, OS waits 11
RW-excl spins 0, rounds 0, OS waits 0
Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 0.00 RW-excl
------------
TRANSACTIONS
------------
Trx id counter B0A
Purge done for trx's n:o < 920 undo n:o < 0
History list length 103
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 28, OS thread handle 0x7f5dbdfe6700, query id 568 localhost root
show engine innodb status
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (read thread)
I/O thread 4 state: waiting for i/o request (read thread)
I/O thread 5 state: waiting for i/o request (read thread)
I/O thread 6 state: waiting for i/o request (write thread)
I/O thread 7 state: waiting for i/o request (write thread)
I/O thread 8 state: waiting for i/o request (write thread)
I/O thread 9 state: waiting for i/o request (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
586 OS file reads, 55 OS file writes, 48 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 553229, node heap has 1 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 13476957
Log flushed up to 13476957
Last checkpoint at 13476957
0 pending log writes, 0 pending chkp writes
32 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 274726912; in additional pool allocated 0
Dictionary memory allocated 182244
Buffer pool size 16383
Free buffers 15829
Database pages 553
Old database pages 224
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 553, created 0, written 27
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 553, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 62305, id 140040552920832, state: waiting for server activity
Number of rows inserted 5, updated 0, deleted 0, read 12
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> set global hot_cache.key_buffer_size = 128* 1024;
Query OK, 0 rows affected (0.00 sec)
mysql> set global hot_cache.key_buffer_size = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'key_buffer_size';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| key_buffer_size | 33554432 |
+-----------------+----------+
1 row in set (0.00 sec)
mysql> set global key_buffer_size = 0;
ERROR 1438 (HY000): Cannot drop default keycache
mysql> show warnings;
+-------+------+------------------------------+
| Level | Code | Message |
+-------+------+------------------------------+
| Error | 1438 | Cannot drop default keycache |
+-------+------+------------------------------+
1 row in set (0.00 sec)
mysql> cache index sales,sales2 in hot_cache;
+---------------+--------------------+----------+-------------------------------------+
| Table | Op | Msg_type | Msg_text |
+---------------+--------------------+----------+-------------------------------------+
| sakila.sales | assign_to_keycache | Error | Table 'sakila.sales' doesn't exist |
| sakila.sales | assign_to_keycache | status | Operation failed |
| sakila.sales2 | assign_to_keycache | Error | Table 'sakila.sales2' doesn't exist |
| sakila.sales2 | assign_to_keycache | status | Operation failed |
+---------------+--------------------+----------+--------------------------