MySQL my.cnf性能调优需要一些建议

时间:2015-05-10 23:28:51

标签: mysql performance

我们的架构如下:



Memory     : 132GB
CPUs       : 12
OS & Mysql : 64-bit
Disk Space : 2.0 TB
DB Engine  : MyISAM




我只有1个表innodb(约400mb) 其余的都是myISAM(大约2dg)

我的服务器负载已经开始通过屋顶,并且它下降到我的网站从其用户获得的API点击(当我转向api时如果向下)

我的sql .conf如下



[mysqld]
innodb_file_per_table=1
bind-address=127.0.0.1


####### Performance Tweaks #######
##thread_cache_size       = 64    # Default 0
##table_open_cache        = 1024  # Default 64
##table_definition_cache  = 512 # Default 256
##max_heap_table_size     = 96M  # Default 16M
##tmp_table_size          = 96M  # Default 16M (can't be bigger than max_heap_table_size)

##key_buffer_size         = 96M   # Default 8M
##sort_buffer_size        = 256K  # Default 2M
##join_buffer_size        = 256K  # Default 128K
##read_buffer_size        = 256K  # Default 128K.
### read_rnd_buffer_size    = 512K  # Default 256K.
##concurrent_insert       = 2     # Deafult 1

##query_cache_limit       = 512K  # Default 1
##query_cache_size        = 96M  # Default 0

######### End Performance Tweaks ##########


#### ADDDED ALL BEWLO LINES ON JUNE,06,2014
# Memory usage
skip-external-locking
max_connections = 1000
max_user_connections = 3056
max_connect_errors = 999999
innodb_file_per_table = ON
innodb_buffer_pool_size = 8G
key_buffer = 1024M
#key_buffer_size = 512M
key_buffer_size = 8G
max_allowed_packet=268435456
group_concat_max_len = 12192
table_open_cache=2048
tmp_table_size = 512M
max_heap_table_size = 512M
sort_buffer_size = 32M
read_buffer_size = 32M
read_rnd_buffer_size = 20M
bulk_insert_buffer_size = 24M
myisam_sort_buffer_size = 200M
query_prealloc_size = 262144
query_alloc_block_size = 65535
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
max_write_lock_count = 8
query_cache_limit = 5M
thread_cache_size = 382
query_cache_size= 256M
# Try number of CPU's*2 for thread_concurrency (eHound has 4 CPU's)
thread_concurrency = 24

# Disable Federated by default
skip-federated

open_files_limit=10000
default-storage-engine=MyISAM
[mysqld_safe]
how variablesog-error="/var/log/mysqld.log"
pid-file="/var/run/mysqld/mysqld.pid"

[mysqldump]
quick
max_allowed_packet = 64M

[mysql]
no-auto-rehash

[isamchk]
#key_buffer = 512M
key_buffer = 4G
sort_buffer_size = 512M
read_buffer = 256M
write_buffer = 256M

[myisamchk]
#key_buffer = 512M
key_buffer = 4G
sort_buffer = 512M
max_allowed_packet = 14M
read_buffer = 8256M
write_buffer = 256M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_stack = 192K

[mysqlhotcopy]
interactive-timeout




有什么建议吗?谢谢大家。

评论后做了这些修改



[mysqld]
innodb_file_per_table=1
bind-address=127.0.0.1


####### Performance Tweaks #######
##thread_cache_size       = 64    # Default 0
##table_open_cache        = 1024  # Default 64
##table_definition_cache  = 512 # Default 256
##max_heap_table_size     = 96M  # Default 16M
##tmp_table_size          = 96M  # Default 16M (can't be bigger than max_heap_table_size)

##key_buffer_size         = 96M   # Default 8M
##sort_buffer_size        = 256K  # Default 2M
##join_buffer_size        = 256K  # Default 128K
##read_buffer_size        = 256K  # Default 128K.
### read_rnd_buffer_size    = 512K  # Default 256K.
##concurrent_insert       = 2     # Deafult 1

##query_cache_limit       = 512K  # Default 1
##query_cache_size        = 96M  # Default 0

######### End Performance Tweaks ##########


#### ADDDED ALL BEWLO LINES ON JUNE,06,2014
# Memory usage
skip-external-locking
max_connections = 1000
max_user_connections = 3056
max_connect_errors = 999999
innodb_file_per_table = ON
innodb_buffer_pool_size = 2G
#key_buffer = 1024M
#key_buffer_size = 512M
key_buffer_size = 45G
max_allowed_packet=268435456
group_concat_max_len = 12192
table_open_cache=2048
tmp_table_size = 512M
max_heap_table_size = 512M
sort_buffer_size = 32M
read_buffer_size = 32M
read_rnd_buffer_size = 20M
bulk_insert_buffer_size = 24M
myisam_sort_buffer_size = 200M
query_prealloc_size = 262144
query_alloc_block_size = 65535
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
max_write_lock_count = 8
query_cache_limit = 5M
thread_cache_size = 382
query_cache_size= 256M
# Try number of CPU's*2 for thread_concurrency (eHound has 4 CPU's)
thread_concurrency = 24

# Disable Federated by default
skip-federated

open_files_limit=10000
default-storage-engine=MyISAM
[mysqld_safe]
how variablesog-error="/var/log/mysqld.log"
pid-file="/var/run/mysqld/mysqld.pid"

[mysqldump]
quick
max_allowed_packet = 64M

[mysql]
no-auto-rehash

[isamchk]
#key_buffer = 512M
key_buffer = 4G
sort_buffer_size = 512M
read_buffer = 256M
write_buffer = 256M

[myisamchk]
#key_buffer = 512M
key_buffer = 4G
sort_buffer = 512M
max_allowed_packet = 14M
read_buffer = 8256M
write_buffer = 256M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_stack = 192K

[mysqlhotcopy]
interactive-timeout




再次感谢

我启用了我的sql日志,我每秒都会收到这些内容,我可以看到我的用户是否使用了我的API



# Thread_id: 4273  Schema: DB_name  QC_hit: No
# Query_time: 0.402709  Lock_time: 0.000058  Rows_sent: 1  Rows_examined: 141611
SET timestamp=1431343679;
select users.*, userroles.apirequests, userroles.downloadrequests, NOW() as now from users inner join userroles on userroles.ID = users.role where users.rsstoken = 'APIKEYHERE';




0 个答案:

没有答案