Skip to main content

Possible MySQL memory leak issue

Comments

14 comments

  • GOT
    Something in that is not linking up. You said mysqltuner reports max possible memory usage as 950M but your innodb buffer pool is set to 5g. That does not line up. Definitely do not leave swap off that was not good advice.
    0
  • gvard
    Hello, You are right, the output was before CloudLinux's recommendations. Here is the correct output, I'm putting it on the 1st post too: [OK] Maximum reached memory usage: 5.6G (17.87% of installed RAM) [OK] Maximum possible memory usage: 5.8G (18.63% of installed RAM)
    0
  • InterServed
    Hello, Had same problems on quite a few servers, MariaDB or MySQL. What did the trick for me was to change the memory allocator library. Also based on the log you posted i would make sure you have increased the openfiles limit. If you want to give it a try, here's a little help ,use at own risk. echo "@mysql soft nofile 65697" >>/etc/security/limits.conf echo "@mysql hard nofile 65697" >>/etc/security/limits.conf yum install jemalloc -y cp -a /etc/sysconfig/mysql /etc/sysconfig/mysql.bkp echo -e "LD_PRELOAD=/usr/lib64/libjemalloc.so.1" > /etc/sysconfig/mysql /scripts/restartsrv_mysql
    Then verify with the next command if mysql processes are using the new jemalloc, if yes, then wait and see how the memory usage will be. pmap `pidof mysqld` | grep jemalloc
    It should return something like this: 00007f6455a20000 196K r-x-- libjemalloc.so.1 00007f6455a51000 2044K ----- libjemalloc.so.1 00007f6455c50000 8K r---- libjemalloc.so.1 00007f6455c52000 4K rw--- libjemalloc.so.1
    Maybe it's a good idea to also perform a server reboot to apply the openfiles limits in /etc/security/limits.conf Sharing also my view on how i would configure mysql based on your existing config: [mysqld] tmpdir="/dev/shm" sql_mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" max_connections=300 max_user_connections=50 log-error = /var/lib/mysql/host.eshoped.gr.err open_files_limit=50000 slow-query-log=1 long-query-time=5 performance_schema=0 wait_timeout=300 interactive_timeout=1800 innodb_strict_mode=0 innodb_file_per_table=1 innodb_buffer_pool_size=5G innodb_buffer_pool_instances=5 innodb_log_file_size=640M innodb_log_buffer_size=16M innodb_buffer_pool_dump_at_shutdown=0 innodb_buffer_pool_load_at_startup=0 innodb_flush_method = O_DIRECT tmp_table_size = 256M max_heap_table_size = 256M max_allowed_packet = 256M query_cache_type = 0 query_cache_size = 0 key_buffer_size = 128M join_buffer_size = 512K sort_buffer_size = 512K read_buffer_size = 256K read_rnd_buffer_size = 256K table_open_cache = 32000 table_definition_cache = 32000 default-storage-engine=MyISAM [mysqld_safe] open-files-limit = 50000
    Best regards
    0
  • cPanelLauren
    Hi @gvard Beyond what's been suggested here, if you continue to have these issues I'd suggest opening a ticket with us, which you can do using the link in my signature. If you do open a ticket please update this thread with the Ticket ID so that we can follow it and provide an update here when the issue is resolved.
    0
  • gvard
    Hi Lauren, A ticket to cPanel was opened prior opening this thread, however in the ticket I was asked to talk to a server administrator. A funny story, we opened the ticket because we are afraid that there is a possible memory leak which is relevant to MySQL binaries and not to something we can do to solve ourselves, since we can't install our own MySQL binaries to a CloudLinux server running cPanel. cPanel ticket was 13503483, feel free to take a look at what had been said there.
    0
  • cPanelLauren
    Hi @gvard Thanks for providing the ticket ID, I do see that a detailed investigation was done on the server, up to our Lvl 3 analysts, in fact the last response indicated some suggestions on configuration that might help you to move forward, I do not see that the Lvl 3 analyst deferred you to an administrator (though I do see it was suggested by another analyst) For reference here's the last response from the analyst: ======================================================================= Hello, Thank you for your patience. There are actually many kinds of memory leaks but they are rather rare in MySQL. Most suspected memory leaks end up being some run-away resource usage. Some memory leaks might happen per connection and they will be gone when the connection is closed. Yet others correspond to global memory allocation and will result in increased memory allocation until the server is restarted. I would suspect memory leak when you see memory usage growing which can"t be connected to any known resource use. For example, for global memory leaks, you would see memory usage continue to grow even after you close the connections and tables regularly. If memory is allocated and forgotten about, it should just be swapped out and swapped back in whenever it is needed again. This can be determined with swap space. If you see swap space being used gradually and growing and there are "swap outs" but a lot less "swap ins", chances are it is caused by a memory leak. Having swap disabled now makes that much more difficult to determine. However, starting with MySQL 5.7 there is now memory allocation checks within the performance_schema. Here's how that can be checked: mysql> SELECT event_name, current_alloc, high_alloc FROM sys.memory_global_by_current_bytes WHERE current_count > 0; +--------------------------------------------------------------------------------+---------------+-------------+ | event_name | current_alloc | high_alloc | +--------------------------------------------------------------------------------+---------------+-------------+ | memory/performance_schema/table_handles | 226.56 MiB | 226.56 MiB | | memory/performance_schema/file_instances | 82.50 MiB | 82.50 MiB | | memory/performance_schema/table_shares | 60.00 MiB | 60.00 MiB | | memory/performance_schema/rwlock_instances | 53.00 MiB | 53.00 MiB | | memory/performance_schema/table_io_waits_summary_by_index_usage | 41.25 MiB | 41.25 MiB | | memory/performance_schema/events_statements_history_long | 13.66 MiB | 13.66 MiB | | memory/performance_schema/events_statements_summary_by_digest.tokens | 9.77 MiB | 9.77 MiB | | memory/performance_schema/events_statements_history_long.tokens | 9.77 MiB | 9.77 MiB | | memory/performance_schema/events_statements_history_long.sqltext | 9.77 MiB | 9.77 MiB | | memory/performance_schema/events_statements_summary_by_user_by_event_name | 8.85 MiB | 8.85 MiB | | memory/performance_schema/events_statements_summary_by_account_by_event_name | 8.85 MiB | 8.85 MiB | | memory/performance_schema/events_statements_summary_by_thread_by_event_name | 8.85 MiB | 8.85 MiB | | memory/performance_schema/table_lock_waits_summary_by_table | 6.72 MiB | 6.72 MiB | | memory/performance_schema/mutex_instances | 6.12 MiB | 6.12 MiB | | memory/performance_schema/memory_summary_by_account_by_event_name | 5.62 MiB | 5.62 MiB | | memory/performance_schema/memory_summary_by_thread_by_event_name | 5.62 MiB | 5.62 MiB | | memory/performance_schema/memory_summary_by_user_by_event_name | 5.62 MiB | 5.62 MiB | | memory/performance_schema/events_statements_summary_by_digest | 4.88 MiB | 4.88 MiB | | memory/performance_schema/events_statements_summary_by_host_by_event_name | 4.42 MiB | 4.42 MiB | | memory/performance_schema/events_statements_current | 3.50 MiB | 3.50 MiB | | memory/performance_schema/events_statements_history | 3.50 MiB | 3.50 MiB | | memory/performance_schema/events_waits_summary_by_user_by_event_name | 3.39 MiB | 3.39 MiB | | memory/performance_schema/events_waits_summary_by_thread_by_event_name | 3.39 MiB | 3.39 MiB | | memory/performance_schema/events_waits_summary_by_account_by_event_name | 3.39 MiB | 3.39 MiB | | memory/performance_schema/events_transactions_history_long | 3.28 MiB | 3.28 MiB | | memory/performance_schema/memory_summary_by_host_by_event_name | 2.81 MiB | 2.81 MiB | | memory/performance_schema/events_statements_current.sqltext | 2.50 MiB | 2.50 MiB | | memory/performance_schema/events_statements_current.tokens | 2.50 MiB | 2.50 MiB | | memory/performance_schema/events_statements_history.sqltext | 2.50 MiB | 2.50 MiB | | memory/performance_schema/events_statements_history.tokens | 2.50 MiB | 2.50 MiB | | memory/performance_schema/events_waits_summary_by_host_by_event_name | 1.70 MiB | 1.70 MiB | | memory/performance_schema/events_waits_history_long | 1.68 MiB | 1.68 MiB | | memory/performance_schema/prepared_statements_instances | 1.62 MiB | 1.62 MiB | | memory/performance_schema/events_stages_summary_by_account_by_event_name | 1.17 MiB | 1.17 MiB | | memory/performance_schema/events_stages_summary_by_thread_by_event_name | 1.17 MiB | 1.17 MiB | | memory/performance_schema/events_stages_summary_by_user_by_event_name | 1.17 MiB | 1.17 MiB | | memory/performance_schema/events_stages_history_long | 1015.62 KiB | 1015.62 KiB | | memory/performance_schema/threads | 928.00 KiB | 928.00 KiB | | memory/performance_schema/events_transactions_history | 860.00 KiB | 860.00 KiB | | memory/performance_schema/events_stages_summary_by_host_by_event_name | 600.00 KiB | 600.00 KiB | | memory/performance_schema/events_statements_summary_by_program | 448.00 KiB | 448.00 KiB | | memory/performance_schema/events_waits_history | 440.00 KiB | 440.00 KiB | | memory/performance_schema/events_stages_history | 260.00 KiB | 260.00 KiB | | memory/performance_schema/file_handle | 256.00 KiB | 256.00 KiB | | memory/performance_schema/accounts | 176.00 KiB | 176.00 KiB | | memory/performance_schema/users | 160.00 KiB | 160.00 KiB | | memory/performance_schema/session_connect_attrs | 128.00 KiB | 128.00 KiB | | memory/performance_schema/socket_instances | 80.00 KiB | 80.00 KiB | | memory/performance_schema/hosts | 72.00 KiB | 72.00 KiB | | memory/performance_schema/memory_class | 60.00 KiB | 60.00 KiB | | memory/performance_schema/setup_objects | 56.00 KiB | 56.00 KiB | | memory/performance_schema/scalable_buffer | 54.22 KiB | 54.22 KiB | | memory/performance_schema/mutex_class | 52.50 KiB | 52.50 KiB | | memory/performance_schema/setup_actors | 40.00 KiB | 40.00 KiB | | memory/performance_schema/stage_class | 37.50 KiB | 37.50 KiB | | memory/performance_schema/statement_class | 36.94 KiB | 36.94 KiB | | memory/performance_schema/events_statements_summary_global_by_event_name | 35.40 KiB | 35.40 KiB | | memory/performance_schema/file_class | 25.00 KiB | 25.00 KiB | | memory/performance_schema/memory_summary_global_by_event_name | 22.50 KiB | 22.50 KiB | | memory/performance_schema/events_transactions_summary_by_account_by_event_name | 22.00 KiB | 22.00 KiB | | memory/performance_schema/events_transactions_summary_by_user_by_event_name | 22.00 KiB | 22.00 KiB | | memory/performance_schema/events_transactions_summary_by_thread_by_event_name | 22.00 KiB | 22.00 KiB | | memory/performance_schema/cond_class | 20.00 KiB | 20.00 KiB | | memory/performance_schema/cond_instances | 16.00 KiB | 16.00 KiB | | memory/performance_schema/rwlock_class | 12.50 KiB | 12.50 KiB | | memory/performance_schema/events_transactions_summary_by_host_by_event_name | 11.00 KiB | 11.00 KiB | | memory/performance_schema/thread_class | 9.38 KiB | 9.38 KiB | | memory/performance_schema/events_stages_summary_global_by_event_name | 4.69 KiB | 4.69 KiB | | memory/performance_schema/socket_class | 3.12 KiB | 3.12 KiB | +--------------------------------------------------------------------------------+---------------+-------------+ 69 rows in set (0.01 sec)
    The largest chunk of RAM is usually the buffer pool but I don't see memory/innodb/buf_buf_pool here, which means it may not have been enabled. You can do that with the following command: mysql> UPDATE performance_schema.setup_instruments SET ENABLED = 'YES' WHERE NAME LIKE 'memory/%';
    You'll then need to wait about 24 hours and run the above command again and see if it can help determine if there's a memory leak. The following post may also be beneficial to you:
    0
  • gvard
    We tried your suggestions with no results. You seem to imply that the problem is settings related, but if you did the math yourself you would see that this is not the case. Even with the default my.cnf that cpanel ships with the memory leak remains. MySQL will full up all available ram unless it gets restarted in time. We even added another 32GB or RAM on the server, and MSQL usage kept growing beyond 40GB, see munin graph: Screenshot The formula result is: 5.2GB mysqltuner reports almost the same number (5.8GB) And at the moment of this writing (with ~36h uptime) MySQL actually uses: ~40GB So, this is not an issue of bad configuration in my.cnf. Nor it is an issue with connections left open. The mysql threads (connections) are low as you can see here Screenshot And in SHOW PROCESSLIST there are no connections running for over a few seconds at a time. Also issuing a FLUSH TABLES; command to close all open tables did not change anything in memory usage. Regarding the swap, when we had it active, it would gradually fill up completely in a matter of few hours. Restaring mysql would empty the swap, until it became full again. Since swaping caused the server to become unresponsive we disabled it. CloudLinux support also suggested the same. But to answer your question, yes, it was almost only swap-outs. So, all evindence points to a memory leak, I would appreciate a little more help here.
    0
  • cPanelLauren
    I see you've reopened the ticket and our L3 analysts are continuing to work on this, investigating this issue up to the level you're suggesting isn't something that would be feasible in the forums, I am glad to see you are getting assistance and I'll follow along the ticket to update the thread here with the outcome.
    0
  • gvard
    Hello, We ended replacing MySQL 5.7 with MariaDB 10.3. On you can see on the red rectangular the memory allocation with MySQL 5.7 (which went to the roof even though we added 32GB more RAM) and then you can see memory allocation with MariaDB. It's been 2,5 days and MariaDB is under 10GB or RAM, as it's supposed to be. Unfortunately I don't know what rare condition caused this memory leak, but it was a memory leak.
    0
  • ghazanfar
    i'm experiencing issue on gmetrix while accessng the [Moderator Notice: This URL was removed. Please avoid including third-party links in the thread] An error occurred fetching the page: HTTPS error: SSL connect attempt failed error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error There may be a connectivity issue between your server and the GTmetrix test server. Please login to try testing from another test location or try again later. any suggestion?
    0
  • SamuelM
    Hello @ghazanfar, The issue you are reporting seems unrelated to the MySQL memory leak which was the original topic of this thread. I would encourage you to submit a new forum thread regarding the SSL error you receive when using the GTMetrix site, or submit a support ticket using the link in my signature. Best regards
    0
  • eimix
    Hello, We ended replacing MySQL 5.7 with MariaDB 10.3. On
    0
  • gvard
    Hello, For table_* variables, we have only set the following: table_open_cache = 32K table_definition_cache = 64K
    0
  • eimix
    Tried to move to MariaDB - memory usage came down, but not much as expected. Finaly found that both MySQL and MariaDB can use high levels of memory for stored procedures/functions and trigger, and could not find way to controll it. Created DB structrue test scripts, reported to MySQL - answer: "expected behaviour" MariaDB - still waiting. second script use UNKNOWN ammount of memory this DB uptime - decreases: 000webhost status ^^^^^^^^^^^^^ 2 rows above edited by moderators, could not show deployed DB :/
    0

Please sign in to leave a comment.