Marco Zimmerman
Marco Zimmerman

Reputation: 251

"innodb_buffer_pool_size" on MySQL with DB bigger than RAM

I had one Linux Server with MySQL working, with:

-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. 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:

[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. But the situation is that when I had 12GB RAM everything was working fine. The "innodb_buffer_pool_size" value was 10000M and the performance was really good. 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.

+--------+---------+--------+--------+------------+---------+
| 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. Now, the question is, what can we do to have more performance on our 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.

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). 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.

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

Upvotes: 5

Views: 6793

Answers (1)

Rick James
Rick James

Reputation: 142208

You are allocating too much RAM and getting into swapping. Swapping is much worse than shrinking the settings.

For your 8GB, recommend these changes

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.

Upvotes: 2

Related Questions