【问题标题】:MariaDB PerformanceMariaDB 性能
【发布时间】:2016-09-25 18:59:25
【问题描述】:

我正在使用 centos 7 和 10.1.8-MariaDB。有时我感觉系统速度很慢。今天检查慢速查询时,我发现更新查询非常细或通常比在某些阶段花费超过 3 或 4 秒的时间要快。

数据库在专用服务器上运行,只安装了 mariadb。它有 4GB 内存。

这是记忆:

 cat /proc/meminfo
 MemTotal:        3883016 kB
 MemFree:          156380 kB
 MemAvailable:     293708 kB
 Buffers:               0 kB
 Cached:           288140 kB
 SwapCached:       171352 kB
 Active:          2546636 kB
 Inactive:        1023020 kB
 Active(anon):    2391628 kB
 Inactive(anon):   905344 kB
 Active(file):     155008 kB
 Inactive(file):   117676 kB
 Unevictable:           0 kB
 Mlocked:               0 kB
 SwapTotal:       2113532 kB
 SwapFree:        1334248 kB
 Dirty:                 0 kB
 Writeback:             0 kB
 AnonPages:       3241692 kB
 Mapped:            20172 kB
 Shmem:             15456 kB
 Slab:              87216 kB
 SReclaimable:      67176 kB
 SUnreclaim:        20040 kB
 KernelStack:        3200 kB
 PageTables:        12088 kB
 NFS_Unstable:          0 kB
 Bounce:                0 kB
 WritebackTmp:          0 kB
 CommitLimit:     4055040 kB
 Committed_AS:    4645884 kB
 VmallocTotal:   34359738367 kB
 VmallocUsed:      160244 kB
 VmallocChunk:   34359568380 kB
 HardwareCorrupted:     0 kB
 AnonHugePages:   2045952 kB
 HugePages_Total:       0
 HugePages_Free:        0
 HugePages_Rsvd:        0
 HugePages_Surp:        0
 Hugepagesize:       2048 kB
 DirectMap4k:       59328 kB
 DirectMap2M:     4134912 kB

这是我的.cnf

 my.cnf
 #
 # This group is read both both by the client and the server
 # use it for options that affect everything
 #
 [mysqld]
 bind-address = 0.0.0.0

 #tmp per carregar:
 wait_timeout=108000
 max_allowed_packet=40960M

 [client-server]
 #
 # include all files from the config directory
 #
 !includedir /etc/my.cnf.d

 [mysqld]
 # 20151031
 # charset
 # init_connect=.SET collation_connection = utf8_unicode_ci.
 # init_connect=.SET NAMES utf8.
 character-set-server=utf8
 collation-server=utf8_unicode_ci

 open_files_limit = 8192
 max_connections = 200

 slow-query-log = 1
 slow-query-log-file = /var/log/mariadb/mysql-slow.log
 long_query_time = 1

 #performance
 # innodb_buffer_pool_size default: 134217728 (128MB) - 60 o 70% memoria
 # 2048MB - 70% = 6012954214 (5734MB)
 innodb_buffer_pool_size=3GB
 innodb_buffer_pool_instances=3

 thread_cache_size=200

 #query_cache_size
 query_cache_type = 1
 query_cache_limit = 1M
 query_cache_min_res_unit = 2k
 query_cache_size = 80M

 #LOGS
 #log-error
 log_warnings = 3
 log-error = /var/log/mariadb/mariadb.log

慢查询日志:

 # User@Host: swb[swb] @  [192.168.50.65]
 # Thread_id: 23002274  Schema: swb  QC_hit: No
 # Query_time: 2.000710  Lock_time: 0.000209  Rows_sent: 0  Rows_examined: 1
 # Rows_affected: 1
 SET timestamp=1474793382;
 UPDATE instalaciones
                 SET
                    fSincro = now(),
                    tHotspot='ACTIVO'
                 WHERE tRouterSerial = '558104409B1B';



 # User@Host: swb[swb] @  [192.168.50.65]
 # Thread_id: 22499243  Schema: swb  QC_hit: No
 # Query_time: 1.909591  Lock_time: 0.000041  Rows_sent: 0  Rows_examined: 0
 # Rows_affected: 1
 SET timestamp=1474636304;
 INSERT INTO redirect(tRedirect,fFecha) VALUES ('ff0005a8c8f2c409a1a5a58fab6d16b455d09258',now());

表格定义:

   CREATE TABLE `instalaciones` (
   `idInstalacion` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `idCliente` int(10) unsigned DEFAULT NULL,
   `tRouterSerial` varchar(50) DEFAULT NULL,
   `tFacebookPage` varchar(256) DEFAULT NULL,
   `tidFacebook` varchar(64) DEFAULT NULL,
   `tNombre` varchar(128) DEFAULT NULL,
   `tMensaje` varchar(128) DEFAULT NULL,
   `tWebPage` varchar(128) DEFAULT NULL,
   `tDireccion` varchar(128) DEFAULT NULL,
   `tPoblacion` varchar(128) DEFAULT NULL,
   `tProvincia` varchar(64) DEFAULT NULL,
   `tCodigoPosta` varchar(8) DEFAULT NULL,
   `tLatitud` decimal(15,12) DEFAULT NULL,
   `tLongitud` decimal(15,12) DEFAULT NULL,
   `tSSID1` varchar(40) DEFAULT NULL,
   `tSSID2` varchar(40) DEFAULT NULL,
   `tSSID2_Pass` varchar(40) DEFAULT NULL,
   `fSincro` datetime DEFAULT NULL,
   `tEstado` varchar(10) DEFAULT NULL,
   `tHotspot` varchar(10) DEFAULT NULL,
   `fAlta` datetime DEFAULT NULL,
   PRIMARY KEY (`idInstalacion`),
   UNIQUE KEY `tRouterSerial` (`tRouterSerial`),
   KEY `idInstalacion` (`idInstalacion`),
   KEY `idCliente` (`idCliente`)
 ) ENGINE=InnoDB AUTO_INCREMENT=1611 DEFAULT CHARSET=utf8;

 CREATE TABLE `redirect` (
   `tRedirect` varchar(80) DEFAULT NULL,
   `fFecha` datetime DEFAULT NULL,
   KEY `itRedirect` (`tRedirect`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

这是解释

 id select_type table   type    possible_keys   key key_len ref rows    Extra
 1  SIMPLE  instalaciones   range   tRouterSerial   tRouterSerial   153 NULL    1   "Using where"


 id select_type table   type    possible_keys   key key_len ref rows    Extra
 1  INSERT  redirect    ALL NULL    NULL    NULL    NULL    NULL    NULL

这是 SHOW TABLE STATUS LIKE

 Name,Engine,Version,Row_format,Rows,Avg_row_length,Data_length,Max_data_length,Index_length,Data_free,Auto_increment,Create_time,Update_time,Check_time,Collation,Checksum,Create_options,Comment

 instalaciones,InnoDB,10,Compact,1401,339,475136,0,131072,0,1611,"2016-06-28 22:20:45",NULL,NULL,utf8_general_ci,NULL,,

 Name   Engine  Version Row_format  Rows    Avg_row_length  Data_length Max_data_length Index_length    Data_free   Auto_increment  Create_time Update_time Check_time  Collation   Checksum    Create_options  Comment
 redirect   InnoDB  10  Compact 30766   102 3162112 0   3162112 13631488    NULL    "2016-02-22 09:57:20"   NULL    NULL    utf8_general_ci NULL        

谁能帮我解决这个缓慢的查询?

非常感谢!

更新:

这是今天的慢查询表单

 # User@Host: swb[swb] @  [192.168.50.65]
 # Thread_id: 23552588  Schema: swb  QC_hit: No
 # Query_time: 1.279738  Lock_time: 0.000115  Rows_sent: 0  Rows_examined: 1
 # Rows_affected: 1
 SET timestamp=1474975258;
 UPDATE instalaciones
                 SET
                    fSincro = now(),
                    tHotspot='ACTIVO'
                 WHERE tRouterSerial = '558104B41762';
 # Time: 160927 18:40:30

这是昨天的 mariadb.log(今天没有):

 2016-09-26 12:53:49 140053608847104 [Warning] Aborted connection 23132533 to db: 'unconnected' user: 'SWB_BDA' host: '192.168.50.65' (Unknown error)
 2016-09-26 12:53:49 140053608249088 [Warning] Aborted connection 23132521 to db: 'swb' user: 'SWB_BDA' host: '192.168.50.65' (Unknown error)

【问题讨论】:

  • 并发问题/锁?
  • 嗨 Drew,每分钟都有很多更新,它可能是并发的.. 可能在这个表上每分钟 100 个查询.. 如何改进这个?锁:我没有锁表……据我所知……
  • 你熟悉查询SHOW PROCESSLIST;吗?在服务器运行缓慢时检查其他情况通常是很有启发性的。
  • 嗨迈克尔,不是真的,问题是如何对齐 SHOW PROCESSLIST; while is bussie ...我已经运行了命令,现在是结果:# Id, User, Host, db, Command, Time, State, Info, Progress 23309682, SWB_BDA, 192.168.50.65:55390, swb, Sleep , 1, , , 0.000 23309687, SWB_BDA, 192.168.50.65:55396, swb, 查询, 0, init, SHOW PROCESSLIST, 0.000 23309842, swb, 192.168.50.65:55629, swb, 睡眠, 0, , , , >
  • 你可能需要更多的内存......你也可以安装mysqltuneridroot.net/tutorials/how-to-install-mysqltuner-on-centos

标签: mysql sql mariadb mysql-slow-query-log


【解决方案1】:

迟缓可能是由于交换。一些设置有溢出可用 RAM 的风险。无论如何...

innodb_buffer_pool_size 的 3GB 不适合 4GB 的服务器。建议更改以下内容:

max_allowed_packet=40960M       --> 50M
innodb_buffer_pool_size=3GB     --> 1500M
innodb_buffer_pool_instances=3  --> 1
thread_cache_size=200           --> 10
query_cache_size = 80M          --> 40M

【讨论】:

  • 嗨 Rickm 为什么将 innodb_buffer_pool_size 更改为 1500M 这是一个带有 Centos 和 mariadb 的专用服务器,我读过在这种情况下 buffer_pool_size 可以是 RAM 的 70%....我确实增加了这个参数,因为mysqltuner(6个月前测试环境)
  • 对于大于 4GB 的服务器来说,70% 就可以了。您拥有的 3G/4G 以及其他占用 RAM 的东西可能会结合起来导致交换,这对 MySQL 性能来说是很糟糕的。我建议的 1.5G 可能低于要求,但应该可以解决眼前的问题。
【解决方案2】:

您的数据库有多大?用于数据库服务器的 4G mem 听起来很小。你检查过你的错误日志吗?您还应该查看 vmstat 或类似内容,以了解当您的查询速度很慢时还会发生什么。如果没有其他事情发生,提供的示例不应该很慢。

【讨论】:

  • 嗨 Jan,我确实更新了今天的 mariadb.log 和 slowquery ... mariadb 日志似乎没有显示任何错误,也许我必须增加某种日志级别以显示更多信息?有人知道怎么做吗?
猜你喜欢
  • 2019-12-16
  • 2013-09-12
  • 2015-10-11
  • 2018-05-12
  • 2021-09-27
  • 2020-09-09
  • 1970-01-01
  • 1970-01-01
  • 2021-04-16
相关资源
最近更新 更多