MySQL 8 and MySQL 5.7 Memory Consumption on Small Devices
source link: https://www.tuicool.com/articles/vuQz2aU
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
While we often run MySQL on larger scale systems in Production for Test and Dev, sometimes we want to run MySQL on the tiniest cloud instances possible or just run it on our laptops. In these cases, MySQL 8 and MySQL 5.7 memory consumption is quite important.
In comparing MySQL 8 vs MySQL 5.7, you should know that MySQL 8 uses more memory. Basic tests on a 1GB VM with MySQL 8 and MySQL 5.7 (actually they’re Percona Server versions) running the same light 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 some 200MB more swap and also uses less OS cache, signaling more memory being allocated and at least “committed.” If we look at the “top” output we see:
MySQL 5.7
MySQL 8.0
This also shows more Resident memory and virtual memory used by MySQL8. Virtual Memory, in particular, is “scary” as it is well in excess of the 1GB of physical memory available on these VMs. Of course, Virtual Memory usage (VSZ) is a poor indicator of actual memory needs for modern applications, but it does corroborate the higher memory needs story.
In reality, though, as we know from the “vmstat” output, neither MySQL 8 nor MySQL 5.7 is swapping with this light load, even though there isn’t much “room” left. If you have more than a handful of connections or wish to run some applications on the same VM, you would get swapping (orOOM killer if you have not enabled swap).
It would be an interesting project to see how low I can drive MySQL 5.7 and MySQL 8 memory consumption, but I will leave it to another project. Here are the settings 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 moving to MySQL 8 in a development environment, keep in mind it will require more memory than MySQL 5.7 with the same settings.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK