DB上的“innodb_buffer_pool_size”,DB大于RAM

时间:2012-11-14 15:09:53

标签: mysql innodb ram

我有一台运行MySQL的Linux服务器,其中包含:

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

由于一些技术问题,我们不得不将服务器的RAM内存减少到8 GB,而目前我们无法拥有任何内存。现在,正因为如此,我们的服务器上出现了很多性能问题。这是我们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 |
+--------+--------------------+---------+--------+--------+------------+---------+

这是/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

...

我不知道我是否能够真正确定大小和RAM之间的关系。但情况是,当我有12GB内存时,一切正常。 “innodb_buffer_pool_size”值为10000M,性能非常好。但现在,采取相同的操作,如4倍。

我们的应用程序基本上是一个数据库导出器,主要只接受一个表,它有72,314,541个寄存器。

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

现在我们正在测试更改“innodb_buffer_pool_size”的值,但看起来我们不会获得更多的表演。现在,问题是,我们可以做些什么来在我们的MySQL上获得更多性能?

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

欢迎所有的想法和贡献,

提前致谢

修改:添加了表格和查询的所有信息

DB的结构是一个从一些传感器接收信息并存储它的系统。

测量表:我们从传感器接收的测量结果。

+--------------------+------------+------+-----+---------+----------------+
| 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表:一个传感器可以测量多个物体(温度,湿度)。这些都是实体。

+--------------+------------+------+-----+---------+----------------+
| 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:一个传感器可以关联多个实体。

+--------------------+------------+------+-----+---------+-------+
| 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    |       |
+--------------------+------------+------+-----+---------+-------+

传感器表:传感器的信息,与上表中的测量实体相关。

+---------------------+-------------+------+-----+---------+----------------+
| 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    |                |
+---------------------+-------------+------+-----+---------+----------------+

位置表:放置传感器的位置。

+------------+------------+------+-----+---------+----------------+
| 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    |                |
+------------+------------+------+-----+---------+----------------+

这是查询(适用于所有房屋和所有传感器):

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:一切都是Grails应用程序的一部分。

1 个答案:

答案 0 :(得分:2)

您正在分配太多RAM并进行交换。交换比缩小设置要糟糕得多。

对于你的 8GB,建议进行这些更改

innodb_buffer_pool_size = 5000M query_cache_size = 50M

如果您说您使用的是MyISAM还是InnoDB,我会给您更多提示。