1

i'm working with centos 7 and 10.1.8-MariaDB. Some times i'm feeling than the system is slow. Today checking slow querys I've seen update queries really thin or usually fast than take in some stages more than 3 or 4 seconds.

The database is runing on a dedicated server, only installed mariadb. It has 4GB Ram.

Here is memory:

 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

This is my.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

The slow query 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());

The tables definition:

   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;

This is explain

 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

This is 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        

Can anyone help me with this slow querys ?

Thanks a lot !

UPDATED:

This is slow query form today

 # 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

and this is mariadb.log from yesterday (nothing today):

 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)
Oscar Jofre
  • 153
  • 3
  • 17
  • concurrency issues / locks? – Drew Sep 25 '16 at 19:06
  • Hi Drew, it is lots of updates every minute it could be concurrency .. probably on this tables 100 queries per minute.. how to improve this ? Locks: I'm not locking tables ... as far as I know... – Oscar Jofre Sep 25 '16 at 19:12
  • Are you familiar with the query `SHOW PROCESSLIST;`? Examining *what else* is happening while the server is sluggish is often quite enlightening. – Michael - sqlbot Sep 26 '16 at 09:59
  • Hi Michael, not really, the problem is how to align SHOW PROCESSLIST; while is bussie ... i've run the command and this is the result now: # 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, Query, 0, init, SHOW PROCESSLIST, 0.000 23309842, swb, 192.168.50.65:55629, swb, Sleep, 0, , , 0.000 – Oscar Jofre Sep 26 '16 at 12:36
  • You need more ram maybe...also you can install `mysqltuner` http://idroot.net/tutorials/how-to-install-mysqltuner-on-centos/ – Hackerman Sep 26 '16 at 13:33
  • If you're still facing this problem: check why there is an index range scan when you specify a unique key in "WHERE tRouterSerial = '558104B41762'". Is there a discrepancy between the index and the column size? I sey "key_len" 153, and "`tRouterSerial` varchar(50)". I hope I didn't wake you. – Gerard H. Pille Feb 01 '18 at 19:38

2 Answers2

1

Possibly the sluggishness is due to swapping. Several settings risked overflowing the available RAM. In any case...

3GB for innodb_buffer_pool_size won't fit in a 4GB server. Recommend changing the following:

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
Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Hi Rickm why change innodb_buffer_pool_size to 1500M this is a dedicated server with Centos and mariadb i've read that in this case buffer_pool_size can be 70% of RAM.... I did increase this parametres due to mysqltuner (6 months ago while testing environment) – Oscar Jofre Sep 29 '16 at 07:08
  • The 70% is fine for servers bigger than 4GB. The 3G/4G you had, plus other things that chewed up RAM, were probably combining to cause swapping, which is terrible for MySQL performance. My suggested 1.5G may be lower than required, but it should solve the immediate problem. – Rick James Sep 29 '16 at 15:27
0

How big is your database? 4G mem for database server sounds very small. Have you checked your error log? You should also see vmstat or similar to see what else is going on when you queries are slow. Provided examples should not be slow if nothing else is going on.

  • Hi Jan, I did update with today’s mariadb.log and slowquery ... mariadb logs seems not to show any error, maybe I have to increase some kind of log level to show more information ? Anyone knows how to do it ? – Oscar Jofre Sep 27 '16 at 20:18