在具有130gb内存的服务器上更正innodb_buffer_pool_size的值?

时间:2016-06-17 19:14:48

标签: mysql linux innodb

我有一台130gb ram的大型服务器,我在这台机器上运行了一个大系统,可以通过多次查询同时连接到mysql。

我需要一些帮助来为innodb_buffer_pool_size设置正确的值,如果我需要设置更多的配置,我的'my.cnf'有这些配置:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

max_connect_errors=100
open-files=10000

interactive_timeout=30
wait_timeout=30

max_connections=700

max_allowed_packet=5M
tmp_table_size=50M
max_heap_table_size=56M

query_cache_type = 1
query_cache_size=10M
query_cache_limit = 10M

sort_buffer_size=15M
read_buffer_size=15M
read_rnd_buffer_size=16M
join_buffer_size=60M
key_buffer_size=10M
myisam_sort_buffer_size=20M

thread_cache_size = 40

key_buffer=20M
key_buffer_size =20M
open_files_limit=10000
default-storage-engine=MyISAM

innodb_file_per_table=1
innodb_buffer_pool_size=3500M
innodb_additional_mem_pool_size=500M

back_log=100
expire_logs_days        = 1
max_binlog_size         = 10M

tmpdir = /var/mysqltmpdir

long_query_time=1
log_slow_queries=/var/log/mysql_slow_queries.log

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
bind-address   =  *
port = 3306

1 个答案:

答案 0 :(得分:0)

这是一个计算已用内存的示例。如果您配置了服务器,您可以看到是否有空闲内存,或者您是否有使用mutch:

SHOW VARIABLES LIKE 'innodb_buffer_pool_size';
SHOW VARIABLES LIKE 'innodb_additional_mem_pool_size';
SHOW VARIABLES LIKE 'innodb_log_buffer_size';
SHOW VARIABLES LIKE 'thread_stack';
SET @kilo_bytes = 1024;
SET @mega_bytes = @kilo_bytes * 1024;
SET @giga_bytes = @mega_bytes * 1024;
SET @innodb_buffer_pool_size = 2 * @giga_bytes;
SET @innodb_additional_mem_pool_size = 16 * @mega_bytes;
SET @innodb_log_buffer_size = 8 * @mega_bytes;
SET @thread_stack = 192 * @kilo_bytes;
SELECT
( @@key_buffer_size + @@query_cache_size + @@tmp_table_size
+ @innodb_buffer_pool_size + @innodb_additional_mem_pool_size
+ @innodb_log_buffer_size
+ @@max_connections * (
@@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size
+ @@join_buffer_size + @@binlog_cache_size + @thread_stack
) ) / @giga_bytes AS MAX_MEMORY_GB;

示例小型服务器

MariaDB [(none)]> SHOW VARIABLES LIKE 'innodb_buffer_pool_size';
+-------------------------+-----------+
| Variable_name           | Value     |
+-------------------------+-----------+
| innodb_buffer_pool_size | 134217728 |
+-------------------------+-----------+
1 row in set (0.00 sec)

MariaDB [(none)]> SHOW VARIABLES LIKE 'innodb_additional_mem_pool_size';
+---------------------------------+---------+
| Variable_name                   | Value   |
+---------------------------------+---------+
| innodb_additional_mem_pool_size | 8388608 |
+---------------------------------+---------+
1 row in set (0.00 sec)

MariaDB [(none)]> SHOW VARIABLES LIKE 'innodb_log_buffer_size';
+------------------------+----------+
| Variable_name          | Value    |
+------------------------+----------+
| innodb_log_buffer_size | 16777216 |
+------------------------+----------+
1 row in set (0.00 sec)

MariaDB [(none)]> SHOW VARIABLES LIKE 'thread_stack';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| thread_stack  | 294912 |
+---------------+--------+
1 row in set (0.00 sec)

MariaDB [(none)]> SET @kilo_bytes = 1024;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SET @mega_bytes = @kilo_bytes * 1024;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SET @giga_bytes = @mega_bytes * 1024;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SET @innodb_buffer_pool_size = 2 * @giga_bytes;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SET @innodb_additional_mem_pool_size = 16 * @mega_bytes;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SET @innodb_log_buffer_size = 8 * @mega_bytes;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SET @thread_stack = 192 * @kilo_bytes;
Query OK, 0 rows affected (0.00 sec)

现在查询

MariaDB [(none)]> SELECT
    -> ( @@key_buffer_size + @@query_cache_size + @@tmp_table_size
    -> + @innodb_buffer_pool_size + @innodb_additional_mem_pool_size
    -> + @innodb_log_buffer_size
    -> + @@max_connections * (
    -> @@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size
    -> + @@join_buffer_size + @@binlog_cache_size + @thread_stack
    -> ) ) / @giga_bytes AS MAX_MEMORY_GB;
+---------------+
| MAX_MEMORY_GB |
+---------------+
|        2.3091 |
+---------------+
1 row in set (0.00 sec)

MariaDB [(none)]>