简体   繁体   English

MySQL上的“ innodb_buffer_pool_size”,数据库大于RAM

[英]“innodb_buffer_pool_size” on MySQL with DB bigger than RAM

I had one Linux Server with MySQL working, with: 我有一台运行MySQL的Linux服务器,它具有:

-12 Gb RAM 
-4 x Intel(R) Xeon(R) CPU E6510  @ 1.73GHz
-CentOS release 6.3
-MySQL 5.1.61

Because of some technical problems, we have had to reduce the RAM memory of the server to 8 GB and for now, we are not able to have any memory. 由于某些技术问题,我们不得不将服务器的RAM内存减少到8 GB,目前,我们无法拥有任何内存。 And now, because of this we are having a lot of performance problems on our server. 现在,由于这个原因,我们在服务器上遇到了许多性能问题。 This is the size of our DB: 这是我们数据库的大小:

+--------+--------------------+---------+--------+--------+------------+---------+
| tables | table_schema       | rows    | data   | idx    | total_size | idxfrac |
+--------+--------------------+---------+--------+--------+------------+---------+
|     43 | XXXXXXXX           | 142.81M | 10.52G | 13.31G | 23.83G     |    1.27 |
|     44 | Test_XXXXXXXX      | 55.20M  | 3.57G  | 4.77G  | 8.33G      |    1.34 |
|     34 | XXXXXXXXXXXXXXXX   | 23.04M  | 1.39G  | 1.84G  | 3.24G      |    1.32 |
|     23 | mysql              | 0.00M   | 0.00G  | 0.00G  | 0.00G      |    0.16 |
|     28 | information_schema | NULL    | 0.00G  | 0.00G  | 0.00G      |    NULL |
+--------+--------------------+---------+--------+--------+------------+---------+

This is the content of /etc/my.cnf: 这是/etc/my.cnf的内容:

[mysqld]

max_allowed_packet = 1024M
sort_buffer_size = 512M
max_connections=500

query_cache_size = 512M
query_cache_limit = 512M
query-cache-type = 2

table_cache = 800

thread_cache_size=8
key_buffer_size = 512M
read_buffer_size=64M
read_rnd_buffer_size=64M
myisam_sort_buffer_size=64M

innodb_flush_log_at_trx_commit=2
innodb_buffer_pool_size=7000M
innodb_additional_mem_pool_size=100M

...

I don't know if I'm able to really identify the relation between the size and the RAM. 我不知道我是否能够真正确定大小与RAM之间的关系。 But the situation is that when I had 12GB RAM everything was working fine. 但是情况是,当我有12GB RAM时,一切工作正常。 The "innodb_buffer_pool_size" value was 10000M and the performance was really good. “ innodb_buffer_pool_size”值为10000M,性能非常好。 But now, takes making the same operation like 4 times more. 但是现在,进行相同的操作要多四倍。

Our app is basically one DB exporter and acceses mainly to only one table, and it has 72,314,541 registers. 我们的应用程序基本上是一个数据库导出器,并且主要访问仅一张表,并且它具有72,314,541个寄存器。

+--------+---------+--------+--------+------------+---------+
| tables | rows    | data   | idx    | total_size | idxfrac |
+--------+---------+--------+--------+------------+---------+
|      9 | 159.12M | 11.07G | 15.87G | 26.94G     |    1.43 |
+--------+---------+--------+--------+------------+---------+

For now we are making tests changing the values of the "innodb_buffer_pool_size", but looks like we are not going to get more performnace. 目前,我们正在进行更改“ innodb_buffer_pool_size”的值的测试,但是看起来我们不会获得更高的性能。 Now, the question is, what can we do to have more performance on our MySQL? 现在的问题是,我们要怎么做才能在MySQL上获得更高的性能?

-Put more RAM (obviously)
-Change more variables on /etc/my.cnf?
-MySQL Partitioning for Performance
-...

All the ideas and contributions will be welcome, 欢迎所有的想法和贡献,

Thanks in advance 提前致谢

Edit: Added all the info of the table and the query 编辑:添加了表和查询的所有信息

The structure of the DB is a system to receive information from some sensors and store it. DB的结构是一个从一些传感器接收信息并将其存储的系统。

Measurement table: The measurements that we receive from the sensors. 测量表:我们从传感器收到的测量值。

+--------------------+------------+------+-----+---------+----------------+
| Field              | Type       | Null | Key | Default | Extra          |
+--------------------+------------+------+-----+---------+----------------+
| id                 | bigint(20) | NO   | PRI | NULL    | auto_increment |
| version            | bigint(20) | NO   |     | NULL    |                |
| counter            | char(2)    | YES  |     | NULL    |                |
| datemeasurement_id | datetime   | NO   | MUL | NULL    |                |
| datereal_id        | datetime   | NO   | MUL | NULL    |                |
| delayed            | bit(1)     | NO   |     | NULL    |                |
| frequency          | tinyint(4) | YES  |     | NULL    |                |
| measuringentity_id | bigint(20) | NO   | MUL | NULL    |                |
| real               | bit(1)     | NO   |     | NULL    |                |
| tamper             | bit(1)     | NO   |     | NULL    |                |
| value              | float      | NO   |     | NULL    |                |
+--------------------+------------+------+-----+---------+----------------+

measuring_entity table: One sensor can measure more than one thing (Temperature, Humidity). measurement_entity表:一个传感器可以测量多个物体(温度,湿度)。 And these are the entitys. 这些是实体。

+--------------+------------+------+-----+---------+----------------+
| Field        | Type       | Null | Key | Default | Extra          |
+--------------+------------+------+-----+---------+----------------+
| id           | bigint(20) | NO   | PRI | NULL    | auto_increment |
| version      | bigint(20) | NO   |     | NULL    |                |
| household_id | varchar(4) | NO   | MUL | NULL    |                |
| operative    | bit(1)     | NO   |     | NULL    |                |
| type         | char(20)   | NO   |     | NULL    |                |
| unit         | char(3)    | NO   |     | NULL    |                |
| interval     | float      | YES  |     | NULL    |                |
+--------------+------------+------+-----+---------+----------------+

sensor_measuring_entity: One sensor can have more than one entity associated. sensor_measuring_entity:一个传感器可以关联多个实体。

+--------------------+------------+------+-----+---------+-------+
| Field              | Type       | Null | Key | Default | Extra |
+--------------------+------------+------+-----+---------+-------+
| sensor_id          | bigint(20) | NO   | PRI | NULL    |       |
| measuringentity_id | bigint(20) | NO   | PRI | NULL    |       |
| version            | bigint(20) | NO   |     | NULL    |       |
+--------------------+------------+------+-----+---------+-------+

Sensor table: The info of the sensor, related with the measuring entity in the previous table. 传感器表:传感器的信息,与上表中的测量实体有关。

+---------------------+-------------+------+-----+---------+----------------+
| Field               | Type        | Null | Key | Default | Extra          |
+---------------------+-------------+------+-----+---------+----------------+
| id                  | bigint(20)  | NO   | PRI | NULL    | auto_increment |
| version             | bigint(20)  | NO   |     | NULL    |                |
| battery             | bit(1)      | NO   |     | NULL    |                |
| identifier          | char(6)     | NO   |     | NULL    |                |
| installationdate_id | datetime    | NO   | MUL | NULL    |                |
| lastreceiveddate_id | datetime    | YES  | MUL | NULL    |                |
| location_id         | bigint(20)  | NO   | MUL | NULL    |                |
| operative           | bit(1)      | NO   |     | NULL    |                |
| tampererror         | smallint(6) | NO   |     | NULL    |                |
+---------------------+-------------+------+-----+---------+----------------+

Location table: Where is placed the sensor. 位置表:将传感器放置在何处。

+------------+------------+------+-----+---------+----------------+
| Field      | Type       | Null | Key | Default | Extra          |
+------------+------------+------+-----+---------+----------------+
| id         | bigint(20) | NO   | PRI | NULL    | auto_increment |
| version    | bigint(20) | NO   |     | NULL    |                |
| height     | tinyint(4) | YES  |     | NULL    |                |
| operative  | bit(1)     | NO   |     | NULL    |                |
| place      | char(15)   | NO   | MUL | NULL    |                |
| room       | char(15)   | NO   |     | NULL    |                |
| typesensor | char(15)   | NO   |     | NULL    |                |
| formaster  | bit(1)     | YES  |     | NULL    |                |
+------------+------------+------+-----+---------+----------------+

This is the query (for all houses, and all sensors): 这是查询(针对所有房屋和所有传感器):

for (int z = 0; z < allHouses.length; z++) {
for (int j = 0; j < sensorlist.length; j++) {

sql.eachRow ("SELECT m.datemeasurement_id, s.identifier, me.type, m.value"
+ " FROM measurement as m"
+ " JOIN measuring_entity as me ON m.measuringentity_id = me.id"
+ " JOIN sensor_measuring_entity as sme ON sme.measuringentity_id = me.id"
+ " JOIN sensor as s ON sme.sensor_id = s.id"
+ " WHERE me.id = $actualmeid"
+ " AND me.household_id = '$mHouse'"
+ " AND m.datemeasurement_id >= '$cons_startDate'"
+ " AND m.datemeasurement_id <= '$cons_endDate'"
+ " AND m.datemeasurement_id > '$startDate'"
+ " AND m.datemeasurement_id < '$endDate'"
+ " ORDER BY datemeasurement_id")
{
}}

PD: everything is part of one Grails app. PD:一切都是Grails应用程序的一部分。

You are allocating too much RAM and getting into swapping. 您分配的RAM过多,无法进行交换。 Swapping is much worse than shrinking the settings. 交换比缩小设置要糟糕得多。

For your 8GB, recommend these changes 为了您的 8GB,建议这些变化

innodb_buffer_pool_size = 5000M query_cache_size = 50M innodb_buffer_pool_size = 5000M query_cache_size = 50M

I'll give you more tips if you say whether you are using MyISAM or InnoDB. 如果您说使用的是MyISAM还是InnoDB,我将为您提供更多提示。

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

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