MariaDB使用所有可用的RAM

时间:2019-06-23 11:41:04

标签: ubuntu mariadb

在具有64G内存的计算机上,我有一个mariadb服务器,该服务器使用所有可用的ram,即使它(至少我认为)配置为使用更少的内存:

INNODB STATUS
Current InnoDB index space = 42.05 G
Current InnoDB data space = 48.17 G
Current InnoDB buffer pool free = 40 %
Current innodb_buffer_pool_size = 12.00 G
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 12.16 G
Configured Max Per-thread Buffers : 1.40 G
Configured Max Global Buffers : 12.04 G
Configured Max Memory Limit : 13.45 G
Physical Memory : 62.79 G
Max memory limit seem to be within acceptable norms

调整底漆的输出似乎也不错:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
26350 mysql     20   0   64.3g  55.3g  19300 S  29.9  88.0 354:20.10 /usr/sbin/mysqld

几个小时后,top的输出如下:

[3308788.693609] Out of memory: Kill process 30421 (mysqld) score 915 or sacrifice child
[3308788.693727] Killed process 30421 (mysqld) total-vm:78894468kB, anon-rss:64508740kB, file-rss:0kB, shmem-rss:0kB
[3308790.493095] oom_reaper: reaped process 30421 (mysqld), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

此oom_reaper之后不久将杀死mysql:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/newback"
        tools:context=".Main5Activity">

    <ImageView
            android:layout_width="104dp"
            android:layout_height="107dp" app:srcCompat="@drawable/pop"
            android:id="@+id/draggableImage" android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent" android:contentDescription="draggable"
            app:layout_constraintHorizontal_bias="0.845" app:layout_constraintVertical_bias="0.544"/>
    <ImageView
            android:layout_width="168dp"
            android:layout_height="149dp" app:srcCompat="@drawable/pop"
            android:id="@+id/draggableImage2" android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent" android:contentDescription="draggable"
            app:layout_constraintHorizontal_bias="0.349" app:layout_constraintVertical_bias="0.216"/>
    <ImageView
            android:src="@drawable/basketwaste"
            android:layout_width="72dp"
            android:layout_height="92dp"
            android:id="@+id/imageView2" android:layout_marginBottom="16dp"
            app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
            app:layout_constraintHorizontal_bias="0.0" android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.771"/>
</android.support.constraint.ConstraintLayout>

我在ubuntu 18.10上使用10.1.38-MariaDB-0ubuntu0.18.10.2

几乎所有表都是innodb,显示全局状态的结果在这里:https://pastebin.com/7ayJBpgC

新设置,在按照Rick James的建议更改了一些设置之后: https://pastebin.com/N55AzWFw

3 个答案:

答案 0 :(得分:1)

全局状态和变量分析。 las,没有任何东西可以清楚地指出为什么您遇到内存问题。

观察

  • 版本:10.1.38-MariaDB-0ubuntu0.18.10.2
  • 64 GB RAM
  • 正常运行时间= 10:28:11;某些GLOBAL STATUS值可能还没有意义。
  • 您未在Windows上运行。
  • 运行64位版本
  • 您似乎完全(或主要是)运行InnoDB。

更重要的问题:

thread_cache_size-增加到50。

long_query_time = 1并打开慢速日志。更多讨论:http://mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog有多种查询迹象可能需要改进-也许是更好的索引编制,也许是更好的表述。慢日志将帮助我们找到要关注的对象。

此服务器是Galera群集的一部分吗?根据答案,我可能还有其他问题或意见。

Max_used_connections已达到199。这相当高。希望解决缓慢的查询会降低这一点。

详细信息和其他观察结果:

( (key_buffer_size / 0.20 + innodb_buffer_pool_size / 0.70) / _ram ) = (32M / 0.20 + 12288M / 0.70) / 65536M = 27.0%-应该使大多数可用的ram都可用于缓存。 -http://mysql.rjweb.org/doc.php/memory

( table_open_cache ) = 4,000-要缓存的表描述符的数量 -700可能适合您的情况(Open_tables = 535

( innodb_lru_scan_depth ) = 1,024 -可以通过降低lru_scan_depth来解决“ InnoDB:page_cleaner:花了1000毫秒的预期循环时间……”

( Innodb_os_log_written ) = 8,213,856,256 / 37691 = 217926 /sec-这表明InnoDB有多忙。 -非常繁忙的InnoDB。

( Innodb_rows_deleted / Innodb_rows_inserted ) = 1,085,550 / 1658210 = 0.655-流失 -“不要排队,就去做。” (如果将MySQL用作队列。)

( Innodb_row_lock_waits ) = 9,462 / 37691 = 0.25 /sec-获取行锁的延迟时间。 -可能是由于可以优化的复杂查询所致。

( innodb_flush_neighbors ) = 1-将块写入磁盘时的次要优化。 -SSD驱动器使用0; 1个用于HDD。

( sync_binlog ) = 0-使用1来增加安全性,但I / O = 1的代价可能会导致很多“查询结束”; = 0可能会导致“ binlog在不可能的位置”并在崩溃时丢失交易,但速度更快。

( innodb_thread_concurrency ) = 0-0 =让InnoDB为concurrency_tickets确定最佳方案。 -设置为0或64。这可能会减少CPU使用率。

( innodb_print_all_deadlocks ) = innodb_print_all_deadlocks = OFF-是否记录所有死锁。 -如果您遇到死锁困扰,请将其打开。警告:如果您有很多死锁,则可能会在磁盘上写入很多内容。

( local_infile ) = local_infile = ON -local_infile = ON是潜在的安全问题

( Created_tmp_disk_tables ) = 100,172 / 37691 = 2.7 /sec-创建 disk “ temp”表作为复杂SELECT的一部分的频率 -增加tmp_table_size和max_heap_table_size。 在使用MEMORY代替MyISAM时检查临时表的规则。较小的架构或查询更改也许可以避免使用MyISAM。 更好的索引和重新编制查询更有可能会有所帮助。

( Select_full_join ) = 228,142 / 37691 = 6.1 /sec-不带索引的联接 -向JOIN中使用的表添加合适的索引。

( Select_scan ) = 451,720 / 37691 = 12 /sec-全表扫描 -添加索引/优化查询(除非它们是很小的表)

( Select_scan / Com_select ) = 451,720 / 4944883 = 9.1%-执行全表扫描的选择的百分比。 (可能会被存储例程欺骗。) -添加索引/优化查询

( Sort_merge_passes ) = 7,711 / 37691 = 0.2 /sec-健康分类 -增加sort_buffer_size和/或优化复杂的查询。

( Com_insert + Com_delete + Com_delete_multi + Com_replace + Com_update + Com_update_multi ) = (2323860 + 36898 + 0 + 0 + 2307510 + 3) / 37691 = 123 /sec-写入/秒 -50次写入/秒+日志刷新可能会最大化普通驱动器的I / O写入容量

( binlog_format ) = binlog_format = STATEMENT-STATEMENT / ROW / MIXED。 ROW是首选;它可能会成为默认值。

( wsrep_on ) = wsrep_on = OFF-Galera:打开复制 -为什么关闭?

( innodb_autoinc_lock_mode ) = 1-加莱拉:欲望2-2 =“交错”; 1 =“连续”是典型的; 0 =“传统”。

( wsrep_log_conflicts ) = wsrep_log_conflicts = OFF-如果在COMMIT期间遇到死锁冲突,则此标志可能会有所帮助。

( slow_query_log ) = slow_query_log = OFF-是否记录慢查询。 (5.1.12)

( long_query_time ) = 10-截止(秒),用于定义“慢速”查询。 -建议2

( Connections ) = 619,511 / 37691 = 16 /sec-连接 -增加wait_timeout;使用池?

( Threads_created / Connections ) = 17,071 / 619511 = 2.8%-流程创建的速度 ( thread_cache_size / max_connections ) = 8 / 512 = 1.6% -增加thread_cache_size(非Windows)

异常小:

Acl_database_grants = 3
Acl_users = 5
Aria_pagecache_blocks_unused = 13,617
Innodb_background_log_sync = 36,995
Innodb_log_writes / Innodb_log_write_requests = 0.20%
Innodb_master_thread_idle_loops = 512
Memory_used = 179.5MB

异常大:

Aria_pagecache_write_requests = 682 /sec
Aria_pagecache_writes = 270 /sec
Aria_transaction_log_syncs = 1,238
Com_show_binlogs = 12 /HR
Com_show_engine_status = 83 /HR
Com_show_plugins = 83 /HR
Feature_locale = 3.1 /HR
Handler_delete = 74 /sec
Handler_discover = 5 /HR
Handler_icp_attempts = 60233 /sec
Handler_icp_match = 59945 /sec
Handler_tmp_update = 5583 /sec
Handler_tmp_write = 11043 /sec
Innodb_buffer_pool_bytes_data = 296959 /sec
Innodb_buffer_pool_pages_dirty = 61,297
Innodb_buffer_pool_write_requests = 5262 /sec
Innodb_ibuf_merged_deletes = 0.32 /sec
Innodb_rows_updated = 358 /sec
Rows_tmp_read = 7844 /sec
Select_range = 59 /sec
Select_range / Com_select = 44.7%
Sort_rows = 9375 /sec
Tc_log_page_size = 4,096
Update_scan = 123,123
innodb_read_io_threads = 64
max_relay_log_size = 100MB

异常字符串:

innodb_default_row_format = compact
innodb_fast_shutdown = 1
myisam_stats_method = NULLS_UNEQUAL

OP所做的更改

innodb_flush_neighbors  1     | innodb_flush_neighbors  0
long_query_time 10.000000     | long_query_time 1.000000
open_files_limit    8551      | open_files_limit    2565
pseudo_thread_id    16370     | pseudo_thread_id    32010
rand_seed1  357956615         | rand_seed1  386239716
rand_seed2  975103936         | rand_seed2  465882405
slow_query_log  OFF           | slow_query_log  ON  
slow_query_log_file prod4-slo | slow_query_log_file /var/
table_open_cache    4000      | table_open_cache    700
thread_cache_size   8         | thread_cache_size   50
timestamp   1561288673.757972 | timestamp   1561333380.04

答案 1 :(得分:1)

在Rick James建议某些默认设置很奇怪之后,我决定升级到正式版本(1:10.2.25 + maria〜cosmic),而不是ubuntu分布式软件包,并且内存问题似乎已经消失,而无需对配置进行任何更改。

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                                                                                                                                                                 
 2736 mysql     20   0   27.4g  15.0g  22624 S 141.7  23.9 384:24.58 /usr/sbin/mysqld   

当前变量:https://pastebin.com/7C96E6J4

当前状态:https://pastebin.com/G55ydpJy

Wilson Hauck要求的其他数据:

我们在i7-6700K的RAID 1中使用了2个三星SSD 850 EVO 500GB

iostat -xm 5 3:

Linux 4.18.0-20-generic (prod4)     07/04/2019  _x86_64_    (8 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           7.10    0.08    1.43    1.53    0.00   89.86

Device            r/s     w/s     rMB/s     wMB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
sdb              6.35  205.97      0.41      4.21     1.79    63.35  21.94  23.52    0.33    1.85   0.67    66.31    20.92   1.19  25.22
sda             14.63  205.95      0.70      4.17     2.58    62.76  14.98  23.36    0.19    1.43   0.58    48.67    20.73   1.06  23.46
md0              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     3.47   489.75   0.00   0.00
md2             19.86  232.03      0.84      4.23     0.00     0.00   0.00   0.00    0.00    0.00   0.00    43.43    18.65   0.00   0.00
md1              1.33    2.51      0.01      0.01     0.00     0.00   0.00   0.00    0.00    0.00   0.00     4.00     4.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.38    0.00    1.61    2.18    0.00   86.83

Device            r/s     w/s     rMB/s     wMB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
sdb              0.00  352.80      0.00      6.88     0.00    57.60   0.00  14.04    0.00    0.26   0.40     0.00    19.97   0.88  31.12
sda              0.00  353.00      0.00      6.88     0.00    57.40   0.00  13.99    0.00    0.26   0.39     0.00    19.96   0.86  30.48
md0              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
md2              0.00  370.80      0.00      6.87     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00    18.98   0.00   0.00
md1              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           8.00    0.00    1.69    2.16    0.00   88.14

Device            r/s     w/s     rMB/s     wMB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
sdb              0.00  387.60      0.00      7.49     0.00    76.20   0.00  16.43    0.00    0.24   0.42     0.00    19.78   0.83  32.16
sda              0.00  387.60      0.00      7.49     0.00    76.20   0.00  16.43    0.00    0.31   0.42     0.00    19.78   0.82  31.60
md0              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
md2              0.00  422.20      0.00      7.48     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00    18.15   0.00   0.00
md1              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00

答案 2 :(得分:0)

每秒速率= RPS-有关my.cnf [mysqld]部分的建议

thread_cache_size=256  # from 50 per 10.n.nn MaridDB refman minimum
innodb_io_capacity=1900  # from 400 to enable higher SSD IOPS
innodb_lru_scan_depth=100  # from 1024 to conserve 90% of CPU cycles used for function
innodb_buffer_pool_size=24G  # from 12G to reduce innodb_buffer_pool_reads RPS of 14
innodb_flushing_avg_loops=5  # from 30 to reduce innodb_buffer_pool_pages_dirty of 61,297

免责声明:我是个人资料(网络个人资料)中提到的网站的内容作者,我们拥有免费的实用程序脚本来提高性能和其他建议。