Technology Sharing | Analysis of Memory Consumption of MySQL 8 and MySQL 5.7 in Small Devices

Author: Peter Zaitsev
Translator: Guan Changlong

Although we often run MySQL on larger systems, we often run MySQL on the smallest cloud instance or only on our laptop. In these cases, the memory consumption of MySQL 8 and MySQL 5.7 is very important.
When comparing MySQL 8 with MySQL 5.7, you should know that MySQL 8 uses more memory. Basic tests were performed on 1GB VM running MySQL 8 and MySQL 5.7 (which are actually versions of Percona Server) with the same lightweight workload.

I see the following vmstat output:
MySQL 5.7 vmstat output

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
4  0  65280  71608  58352 245108    0    0  2582  3611 1798 8918 18  9 11 33 30
4  0  65280  68288  58500 247512    0    0  2094  2662 1769 8508 19  9 13 30 29
3  1  65280  67780  58636 249656    0    0  2562  3924 1883 9323 20  9  7 37 27
4  1  65280  66196  58720 251072    0    0  1936  3949 1587 7731 15  7 11 36 31

MySQL 8.0 vmstat output

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa st
9  1 275356  62280  60832 204736    0    0  2197  5245 2638 13453 24 13  2 34 27
3  0 275356  60548  60996 206340    0    0  1031  3449 2446 12895 25 11 10 28 26
7  1 275356  78188  59564 190632    0    1  2448  5082 2677 13661 26 13  6 30 25
4  1 275356  76516  59708 192096    0    0  2247  3750 2401 12210 22 12  4 38 24

As you can see, MySQL 8 uses about 200 MB of swap partitions, uses fewer system caches, and is allocated more memory.

If we look at the output of the "top" command, we will see:
MySQL 5.7

MySQL 8.0

This also shows that MySQL8 uses more resident and virtual memory. Especially "terrible" virtual memory, because it is far more than the 1GB physical memory available on these VM s. Of course, virtual memory usage (VSZ) is a poor indicator of the actual memory requirements of modern applications, but it does confirm the higher memory requirements.

In fact, as we know from the "vmstat" output, MySQL 8 and MySQL 5.7 will not use swap partitions under low loads even if there is not much "space". If you have multiple connections or want to run some applications on the same VM, you can use swap (which can lead to OOM if swap is not enabled).

This is an interesting experiment to see how much memory I can drive MySQL 5.7 and MySQL 8.
The following is the configuration I used for this test:

[mysqld]
innodb_buffer_pool_size=256M
innodb_buffer_pool_instances=1
innodb_log_file_size=1G
innodb_flush_method=O_DIRECT
innodb_numa_interleave=1
innodb_flush_neighbors=0
log_bin
server_id=1
expire_logs_days=1
log_output=file
slow_query_log=ON
long_query_time=0
log_slow_rate_limit=1
log_slow_rate_type=query
log_slow_verbosity=full
log_slow_admin_statements=ON
log_slow_slave_statements=ON
slow_query_log_always_write_time=1
slow_query_log_use_global_control=all
innodb_monitor_enable=all
userstat=1

summary
When migrating to MySQL 8 in a development environment, remember that using the same settings requires more memory than configuring MySQL 5.7.

Keywords: Database MySQL

Added by 00king00 on Thu, 22 Aug 2019 09:25:42 +0300