Very slow writes on MySQL 8 - waiting for handler commit - mysql

I have MySQL 8 docker installation installed on an edge device which has the following two tables to write to
video_paths | CREATE TABLE `video_paths` (
`entry` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` bigint(20) NOT NULL,
`duration` int(11) NOT NULL,
`path` varchar(255) NOT NULL,
`motion` int(11) NOT NULL DEFAULT '0',
`cam_id` varchar(255) NOT NULL DEFAULT '',
`hd` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`entry`),
KEY `cam_id` (`cam_id`),
KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB AUTO_INCREMENT=7342309 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
AND
CREATE TABLE `tracker` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`table_name` varchar(255) NOT NULL,
`primary_key_name` varchar(255) NOT NULL,
`pointer` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `table_name` (`table_name`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
The following queries are run every few secs for up to 32 cameras and are taking a lot of time as indicated by the slow query log.
UPDATE tracker SET pointer = 7342046 WHERE table_name = 'video_paths'
INSERT INTO video_paths (timestamp,duration,path,cam_id,hd) VALUES (1597548365000,5000,'/s/ss/x-0/v/2020-08-16/3/1.ts','x-1',1)
Most of the time is spent in the waiting for handler commit state
The total size of my data (tables + index) is ~1GB and I have the following settings enabled to optimise for write
skip-log-bin - Disabled the bin log because I don't have a replica and therefore no use for it
innodb_flush_log_at_trx_commit =2 - I am Optimising for performance rather than consistency here.
range_optimizer_max_mem_size =0 As mention in this question, I have allowed max memory to range optimiser.
inndo_buffer_pool_size= 512Mb - This should be enough for my data?.
innodb_log_file_size= 96Mb *2 files
I am seeing queries that are taking up to 90-100 secs sometimes.
SET timestamp=1597549337;
INSERT INTO video_paths (timestamp,duration,path,cam_id,hd) VALUES (1597548365000,5000,'/s/ss/x-0/v/2020-08-16/3/1.ts','x-1',1);
# Time: 2020-08-16T03:42:24.533408Z
# Query_time: 96.712976 Lock_time: 0.000033 Rows_sent: 0 Rows_examined: 0
---UPDATE---
Here's the complete my.cnf file
my.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
skip-log-bin
innodb_buffer_pool_size=536870912
innodb_log_file_size=100663296
# Custom config should go here
!includedir /etc/mysql/conf.d/
conf.d/docker.cnf
[mysqld]
skip-host-cache
skip-name-resolve
The docker container is using the host mode so complete 15GB memory is available to the container.
--- UPDATE 2 ---
After increasing the innodb_buffer_poo_size to 2GB as suggested by #fyrye, the statements have now started getting stuck on STATE = UPDATE instead of waiting for handler commit.
---- UPDATE 3 ---
Looks like the CPU is causing the bottleneck
** ---- UPDATE 4 ---- **
Additional info
Ram Size
total used free shared buff/cache available
Mem: 15909 1711 9385 2491 4813 11600
Swap: 0 0 0
No SSD/NVMe devices attached
SHOW GLOBAL STATUS - https://pastebin.com/vtWi0PUq
SHOW GLOBAL VARIABLES - https://pastebin.com/MUZeG959
SHOW FULL PROCESSLIST - https://pastebin.com/eebEcYk7
htop - htop here is for the edge system which has 4 other containers running which include the main app, ffmpeg, mqtt, etc.
ulimit -a:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 62576
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 62576
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
opstat -xm 5 4
Linux 4.15.0-106-generic (xxxx) 08/18/2020 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
26.97 0.00 22.36 22.53 0.00 28.14
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
loop0 0.00 0.00 0.00 0.00 0.00 0.00 3.20 0.00 2.40 2.40 0.00 0.00 0.00
sda 13.78 9.89 32.24 11.44 0.37 4.10 209.51 47.52 1079.07 44.07 3994.87 22.39 97.81
avg-cpu: %user %nice %system %iowait %steal %idle
19.71 0.00 27.85 40.87 0.00 11.57
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
loop0 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
sda 0.00 0.00 1.40 4.60 0.03 2.71 934.93 142.66 24221.33 666.29 31390.26 166.67 100.00
avg-cpu: %user %nice %system %iowait %steal %idle
20.16 0.00 26.77 28.30 0.00 24.77
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
loop0 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
sda 0.00 0.00 8.80 5.60 0.03 3.45 496.11 141.28 12507.78 194.00 31858.00 69.44 100.00
mpstat -P ALL 5 3
Linux 4.15.0-106-generic (sn-1f0ce8) 08/18/2020 _x86_64_ (4 CPU)
02:15:47 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
02:15:52 PM all 21.48 0.00 20.40 29.01 0.00 7.94 0.00 0.00 0.00 21.17
02:15:52 PM 0 24.95 0.00 20.86 5.32 0.00 0.61 0.00 0.00 0.00 48.26
02:15:52 PM 1 17.59 0.00 18.81 57.67 0.00 5.93 0.00 0.00 0.00 0.00
02:15:52 PM 2 21.28 0.00 17.36 0.21 0.00 24.79 0.00 0.00 0.00 36.36
02:15:52 PM 3 22.34 0.00 24.59 52.46 0.00 0.61 0.00 0.00 0.00 0.00
02:15:52 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
02:15:57 PM all 20.56 0.00 20.00 28.26 0.00 7.08 0.00 0.00 0.00 24.10
02:15:57 PM 0 24.44 0.00 18.89 12.32 0.00 0.21 0.00 0.00 0.00 44.15
02:15:57 PM 1 17.73 0.00 15.46 33.20 0.00 4.95 0.00 0.00 0.00 28.66
02:15:57 PM 2 18.93 0.00 22.22 12.35 0.00 22.84 0.00 0.00 0.00 23.66
02:15:57 PM 3 21.06 0.00 23.31 55.21 0.00 0.41 0.00 0.00 0.00 0.00
02:15:57 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
02:16:02 PM all 21.81 0.00 18.32 26.42 0.00 7.03 0.00 0.00 0.00 26.42
02:16:02 PM 0 26.43 0.00 19.67 0.20 0.00 0.41 0.00 0.00 0.00 53.28
02:16:02 PM 1 20.57 0.00 17.11 45.21 0.00 5.30 0.00 0.00 0.00 11.81
02:16:02 PM 2 19.67 0.00 16.74 0.21 0.00 21.97 0.00 0.00 0.00 41.42
02:16:02 PM 3 20.45 0.00 19.84 58.91 0.00 0.81 0.00 0.00 0.00 0.00
Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
Average: all 21.28 0.00 19.57 27.90 0.00 7.35 0.00 0.00 0.00 23.90
Average: 0 25.27 0.00 19.81 5.94 0.00 0.41 0.00 0.00 0.00 48.57
Average: 1 18.63 0.00 17.13 45.39 0.00 5.39 0.00 0.00 0.00 13.45
Average: 2 19.96 0.00 18.78 4.28 0.00 23.20 0.00 0.00 0.00 33.77
Average: 3 21.28 0.00 22.57 55.54 0.00 0.61 0.00 0.00 0.00 0.00

Suggestions to consider for your my.cnf [mysqld] section
log_error=/var/lib/mysql/sn-1f0ce8-error.log # from stderr to have a visible error log
innodb_lru_scan_depth=100 # from 1024 to conserve 90% CPU cycles used for function
innodb_io_capacity=1900 # from 200 to allow more IOPSecond to your storage device
innodb_flush_neighbors=2 # from 0 to expedite writing to current extent
innodb_max_dirty_pages_pct_lwm=1 # from 10 percent to expedite writes
innodb_max_dirty_pages_pct=1 # from 90 percent to reduce innodb_buffer_pool_pages_dirty count
innodb_change_buffer_max_size=50 # from 25 percent to expedite your high volume activity
You will find these suggestions will reduce CPU busy and expedite query completion.
For additional suggestions view profile, Network profile for contact information and free downloadable Utility Scripts to assist with performance improvements.

Related

Why am I getting this error in MariaDB Galera Clutser?

I am using Galera Cluster, and recently encountered the following error while restarting MariaDB.
It consists of a total of 3 nodes.
When only the first node is running, DB access is possible, but when the second node is executed, the following error message is displayed and the cluster is not formed.
Why?
MariaDB Version: 10.4.20
mariadb | =====================================
mariadb | 2022-08-11 12:00:11 0x7f37339cf700 INNODB MONITOR OUTPUT
mariadb | =====================================
mariadb | Per second averages calculated from the last 60 seconds
mariadb | -----------------
mariadb | BACKGROUND THREAD
mariadb | -----------------
mariadb | srv_master_thread loops: 3 srv_active, 0 srv_shutdown, 74 srv_idle
mariadb | srv_master_thread log flush and writes: 76
mariadb | ----------
mariadb | SEMAPHORES
mariadb | ----------
mariadb | OS WAIT ARRAY INFO: reservation count 20
mariadb | --Thread 139884474328832 has waited at dict0dict.cc line 880 for 232.00 seconds the semaphore:
mariadb | Mutex at 0x556c68691100, Mutex DICT_SYS created dict0dict.cc:824, lock var 2
mariadb |
mariadb | --Thread 139874768164608 has waited at srv0srv.cc line 2011 for 242.00 seconds the semaphore:
mariadb | X-lock on RW-latch at 0x556c68691130 created in file dict0dict.cc line 833
mariadb | a writer (thread id 139875057460992) has reserved it in mode exclusive
mariadb | number of readers 0, waiters flag 1, lock_word: 0
mariadb | Last time write locked in file dict0stats.cc line 2486
mariadb | OS WAIT ARRAY INFO: signal count 13
mariadb | RW-shared spins 19, rounds 487, OS waits 13
mariadb | RW-excl spins 17, rounds 103, OS waits 2
mariadb | RW-sx spins 0, rounds 0, OS waits 0
mariadb | Spin rounds per wait: 25.63 RW-shared, 6.06 RW-excl, 0.00 RW-sx
mariadb | ------------
mariadb | TRANSACTIONS
mariadb | ------------
mariadb | Trx id counter 2908999983
mariadb | Purge done for trx's n:o < 2908999981 undo n:o < 0 state: running but idle
mariadb | History list length 4
mariadb | LIST OF TRANSACTIONS FOR EACH SESSION:
mariadb | ---TRANSACTION 421359460385048, COMMITTED IN MEMORY flushing log
mariadb | 0 lock struct(s), heap size 1128, 0 row lock(s), undo log entries 2
mariadb | ---TRANSACTION 421359460380824, not started
mariadb | 0 lock struct(s), heap size 1128, 0 row lock(s)
mariadb | --------
mariadb | FILE I/O
mariadb | --------
mariadb | I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
mariadb | I/O thread 1 state: waiting for completed aio requests (log thread)
mariadb | I/O thread 2 state: waiting for completed aio requests (read thread)
mariadb | I/O thread 3 state: waiting for completed aio requests (read thread)
mariadb | I/O thread 4 state: waiting for completed aio requests (read thread)
mariadb | I/O thread 5 state: waiting for completed aio requests (read thread)
mariadb | I/O thread 6 state: waiting for completed aio requests (write thread)
mariadb | I/O thread 7 state: waiting for completed aio requests (write thread)
mariadb | I/O thread 8 state: waiting for completed aio requests (write thread)
mariadb | I/O thread 9 state: waiting for completed aio requests (write thread)
mariadb | Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
mariadb | ibuf aio reads:, log i/o's:, sync i/o's:
mariadb | Pending flushes (fsync) log: 0; buffer pool: 0
mariadb | 129125 OS file reads, 323 OS file writes, 57 OS fsyncs
mariadb | 0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
mariadb | -------------------------------------
mariadb | INSERT BUFFER AND ADAPTIVE HASH INDEX
mariadb | -------------------------------------
mariadb | Ibuf: size 1, free list len 4026, seg size 4028, 0 merges
mariadb | merged operations:
mariadb | insert 0, delete mark 0, delete 0
mariadb | discarded operations:
mariadb | insert 0, delete mark 0, delete 0
mariadb | Hash table size 2212699, node heap has 0 buffer(s)
mariadb | Hash table size 2212699, node heap has 0 buffer(s)
mariadb | Hash table size 2212699, node heap has 0 buffer(s)
mariadb | Hash table size 2212699, node heap has 0 buffer(s)
mariadb | Hash table size 2212699, node heap has 2 buffer(s)
mariadb | Hash table size 2212699, node heap has 2 buffer(s)
mariadb | Hash table size 2212699, node heap has 2 buffer(s)
mariadb | Hash table size 2212699, node heap has 3 buffer(s)
mariadb | 0.00 hash searches/s, 0.00 non-hash searches/s
mariadb | ---
mariadb | LOG
mariadb | ---
mariadb | Log sequence number 1202450201026
mariadb | Log flushed up to 1202450200636
mariadb | Pages flushed up to 1202450196728
mariadb | Last checkpoint at 1202450196719
mariadb | 1 pending log flushes, 0 pending chkp writes
mariadb | 35 log i/o's done, 0.00 log i/o's/second
mariadb | ----------------------
mariadb | BUFFER POOL AND MEMORY
mariadb | ----------------------
mariadb | Total large memory allocated 8606711808
mariadb | Dictionary memory allocated 407480
mariadb | Buffer pool size 513728
mariadb | Free buffers 384737
mariadb | Database pages 128982
mariadb | Old database pages 47768
mariadb | Modified db pages 136
mariadb | Percent of dirty pages(LRU & free pages): 0.026
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 20, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 128851, created 131, written 282
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 128982, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ----------------------
mariadb | INDIVIDUAL BUFFER POOL INFO
mariadb | ----------------------
mariadb | ---BUFFER POOL 0
mariadb | Buffer pool size 64216
mariadb | Free buffers 48110
mariadb | Database pages 16104
mariadb | Old database pages 5964
mariadb | Modified db pages 20
mariadb | Percent of dirty pages(LRU & free pages): 0.031
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 20, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16100, created 4, written 31
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16104, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ---BUFFER POOL 1
mariadb | Buffer pool size 64216
mariadb | Free buffers 48038
mariadb | Database pages 16177
mariadb | Old database pages 5991
mariadb | Modified db pages 5
mariadb | Percent of dirty pages(LRU & free pages): 0.008
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 0, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16177, created 0, written 8
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16177, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ---BUFFER POOL 2
mariadb | Buffer pool size 64216
mariadb | Free buffers 48125
mariadb | Database pages 16089
mariadb | Old database pages 5959
mariadb | Modified db pages 0
mariadb | Percent of dirty pages(LRU & free pages): 0.000
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 0, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16089, created 0, written 0
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16089, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ---BUFFER POOL 3
mariadb | Buffer pool size 64216
mariadb | Free buffers 48078
mariadb | Database pages 16137
mariadb | Old database pages 5976
mariadb | Modified db pages 64
mariadb | Percent of dirty pages(LRU & free pages): 0.100
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 0, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16137, created 0, written 65
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16137, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ---BUFFER POOL 4
mariadb | Buffer pool size 64216
mariadb | Free buffers 48092
mariadb | Database pages 16124
mariadb | Old database pages 5972
mariadb | Modified db pages 46
mariadb | Percent of dirty pages(LRU & free pages): 0.072
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 0, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16124, created 0, written 46
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16124, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ---BUFFER POOL 5
mariadb | Buffer pool size 64216
mariadb | Free buffers 48143
mariadb | Database pages 16071
mariadb | Old database pages 5952
mariadb | Modified db pages 1
mariadb | Percent of dirty pages(LRU & free pages): 0.002
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 0, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16071, created 0, written 1
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16071, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ---BUFFER POOL 6
mariadb | Buffer pool size 64216
mariadb | Free buffers 48087
mariadb | Database pages 16129
mariadb | Old database pages 5973
mariadb | Modified db pages 0
mariadb | Percent of dirty pages(LRU & free pages): 0.000
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 0, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16066, created 63, written 63
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16129, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | ---BUFFER POOL 7
mariadb | Buffer pool size 64216
mariadb | Free buffers 48064
mariadb | Database pages 16151
mariadb | Old database pages 5981
mariadb | Modified db pages 0
mariadb | Percent of dirty pages(LRU & free pages): 0.000
mariadb | Max dirty pages percent: 75.000
mariadb | Pending reads 0
mariadb | Pending writes: LRU 0, flush list 0, single page 0
mariadb | Pages made young 0, not young 0
mariadb | 0.00 youngs/s, 0.00 non-youngs/s
mariadb | Pages read 16087, created 64, written 68
mariadb | 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
mariadb | No buffer pool page gets since the last printout
mariadb | Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
mariadb | LRU len: 16151, unzip_LRU len: 0
mariadb | I/O sum[0]:cur[0], unzip sum[0]:cur[0]
mariadb | --------------
mariadb | ROW OPERATIONS
mariadb | --------------
mariadb | 0 queries inside InnoDB, 0 queries in queue
mariadb | 0 read views open inside InnoDB
mariadb | Process ID=1, Main thread ID=139874768164608, state: enforcing dict cache limit
mariadb | Number of rows inserted 0, updated 0, deleted 0, read 200
mariadb | 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
mariadb | Number of system rows inserted 5, updated 0, deleted 4, read 9
mariadb | 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
mariadb | ----------------------------
mariadb | END OF INNODB MONITOR OUTPUT
mariadb | ============================
Well, unfortunately, you did not include an error. Or that's what it looks like. The output that you have included is nothing out of ordinary - this is a result of a SHOW ENGINE INNODB STATUS; command, which exposes some of the internals. Based on this, it shows that you have a fairly unused server with very limited traffic. There were two transactions running, one of them got locked on some of the rows. You still have free memory in the InnoDB buffer pool. Nothing that would point towards any issues.
In general, the problem with the Galera cluster could be that the second node did not join the cluster properly. Unless all nodes are in "Primary" state, as shown in the output of SHOW STATUS LIKE 'wsrep_cluster_status'; If the node is not in the primary state, you won't be able to run queries against that node (unless you have set wsrep_dirty_reads, then you can run SELECTs, but that's another story). This is intended to ensure that you won't be getting stale reads (dataset on the non-Primary node is outdated as it is not part of the cluster).

MySQL I/O wait time suddenly increasing

The I/O wait time is increasing for one of my servers. I haven't seen any long running queries in the process list. Can someone help me identify the cause?
The server is running Cent OS Linux 7.7, 4 core CPU , MySQL version 5.6.42
iotop output
Actual DISK READ: 57.85 M/s | Actual DISK WRITE: 74.90 K/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
31529 be/4 mysql 58.08 M/s 0.00 B/s 0.00 % 84.45 % mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib~p.geolearning.com.pid --socket=/var/lib/mysql/mysql.sock --port=3306
12331 be/4 mysql 7.68 K/s 61.46 K/s 0.00 % 0.66 % mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib~p.geolearning.com.pid --socket=/var/lib/mysql/mysql.sock --port=3306
6819 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.02 % [kworker/2:16]
1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 22
2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd]
4 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0H]
6 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0]
7 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0]
8 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_bh]
9 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_sched]
10 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [lru-add-drain]
Processlist:
+---------+----------------+------------------+---------+---------+------+--------------+------------------------------------------------------------------------------------------------------+-----------+---------------+
| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined |
+---------+----------------+------------------+---------+---------+------+--------------+------------------------------------------------------------------------------------------------------+-----------+---------------+
| 2128874 | lpaauser | 10.7.40.7:64197 | prodsup | Query | 0 | Sending data | REPLACE INTO course_auto_assignments_compute8 (domain_id,lms_user_id,filter_set_id)
S | 0 | 0 |
| 2129350 | mveeranki | localhost | | Query | 0 | init | show processlist | 0 | 0 |
+---------+----------------+------------------+---------+---------+------+--------------+------------------------------------------------------------------------------------------------------+-----

mysql 5.6 order first then group by

I am using MySQL 5.6, and creating a view. It seems MySQL 5.6 view does not support subquery inside a view. I have two tables like the following:
table 1
account balance date time in out
408 100.00 2018-03-09 11:36:47 100.00 0.00
408 86.00 2018-03-09 11:54:48 0.00 14.00
408 74.00 2018-03-09 11:54:48 0.00 12.00
408 21.00 2018-03-09 11:54:48 0.00 13.00
408 11.00 2018-03-09 11:54:48 0.00 10.00
408 0.00 2018-03-09 11:54:48 0.00 11.00
408 13000000.00 2018-03-09 19:15:04 13000000.00 0.00
408 12999880.00 2018-03-10 00:51:37 0.00 120.00
408 12999640.00 2018-03-10 00:51:48 0.00 240.00
table2
account name
999 bank1
408 bank2
The view is created like this:
create view test
select table1.account, table2.name, table1.balance, table1.date from (table1 join table2) where table1.account=table2.account group by table1.account, table1.date
The problem is that the view picked out the first time, showed the first balance. But I want the max time on that day. For example, the view results are like:
408 bank1 100 2018-03-09
408 bank1 12999880.00 2018-03-10
The MySQL 5.6 does not allow me to use a subquery. So is there another way to show the correct balance like this:
408 bank1 13000000.00 2018-03-09
408 bank1 12999640.00 2018-03-10
which shows the lastest balance of the last record on that day.

Cumulative Adding in SQL SERVER 2008

This is what i have got in my SQL SERVER database table, where I am trying to calculate Balance Leave of an employee.
My actual data is:
EmpId EmpName EvalDate OpeningEL EnjoyedEL BalanceEL
12 CHANDRA 2014-04-01 18:30:00.000 0.95 0.00 0.95
12 CHANDRA 2014-05-01 18:30:00.000 1.30 0.00 1.30
12 CHANDRA 2014-06-01 18:30:00.000 1.20 1.00 1.20
12 CHANDRA 2014-07-01 18:30:00.000 1.25 0.00 1.25
12 CHANDRA 2014-08-01 18:30:00.000 1.25 1.00 1.25
But i need the data in below way
EmpId EmpName EvalDate OpeningEL EnjoyedEL BalanceEL
12 CHANDRA 2014-04-01 18:30:00.000 0.95 0.00 0.95
12 CHANDRA 2014-05-01 18:30:00.000 2.25 0.00 2.25
12 CHANDRA 2014-06-01 18:30:00.000 3.45 1.00 2.45
12 CHANDRA 2014-07-01 18:30:00.000 3.70 0.00 3.70
12 CHANDRA 2014-08-01 18:30:00.000 4.95 1.00 3.95
Previous BalanceELs are added with next OpeningELs.
So, how to achieve this....Please suggest something.
You can use CROSS APPLY and GROUP BY to achieve this
OpeningEL and BalanceEL from CROSS APPLY will get the sum of current and previous records for an employee.
SELECT
EL1.EmpId,
EL1.EmpName,
EL1.EvalDate,
Temp.OpeningEL,
EL1.EnjoyedEL,
Temp.BalanceEL
FROM EmployeeLeave EL1
CROSS APPLY
(
SELECT
SUM(OpeningEL) as OpeningEL,
SUM(BalanceEL) - SUM(EnjoyedEL) as BalanceEL
FROM EmployeeLeave EL2
WHERE EL2.EmpId = EL1.EmpId
AND EL2.EvalDate <= EL1.EvalDate
)Temp;

How to interpret iostat?

I track a lot of parameters on my Server and the only thing I can't realy put in perspective is the IOstat. It is a MySQL Server, is this a good result, or should I worry?
root:/var/lib/mysql# iostat -xc
Linux 2.6.28-11-server () 07/25/2009 _x86_64_ (8 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
3.66 0.19 0.45 1.04 0.00 94.69
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 2.55 871.36 1.46 27.67 392.40 7200.45 260.64 1.02 34.85 2.48 7.22
sda1 0.18 0.61 0.03 0.01 3.60 4.98 215.91 0.01 185.95 19.25 0.08
sda2 0.01 0.00 0.00 0.00 1.03 0.02 919.32 0.00 21.36 6.94 0.00
sda3 2.36 870.75 1.43 27.66 387.76 7195.46 260.68 1.01 34.65 2.48 7.21
sdb 2.37 871.36 1.63 27.67 392.69 7200.45 259.12 0.65 22.07 2.51 7.35
sdb1 0.17 0.61 0.04 0.01 3.59 4.98 187.33 0.01 110.67 12.54 0.06
sdb2 0.00 0.00 0.00 0.00 1.03 0.02 256.48 0.00 2.36 1.50 0.00
sdb3 2.19 870.75 1.60 27.66 388.06 7195.46 259.23 0.64 21.93 2.51 7.34
md0 0.00 0.00 0.38 0.62 3.06 4.96 8.00 0.00 0.00 0.00 0.00
md1 0.00 0.00 0.00 0.00 0.00 0.02 8.36 0.00 0.00 0.00 0.00
md2 0.00 0.00 2.01 898.28 62.49 7186.28 8.05 0.00 0.00 0.00 0.00
Also what war options for decreasing read / write activity?
delay_______key_______writes
memory based Tables
less indicies
The write load is quite high on the tables.
If anyone worrying about the disk IO bottlenecks, please have a check with the following command.
iostat
If this tool is not installed then,
apt-get install sysstat
on Debian based servers.
yum install sysstat
on Redhat/CentOS based servers.
Then,
iostat -x -d sda
-here "sda" denotes your HDD
Output:
root#forum.innovationframes.com:~# iostat -x -d sda
Linux 2.6.32-24-server (forum.innovationframes.com) 10/01/2011 _x86_64_ (1 CPU)
Dev: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm **%util**
sda 0.01 0.04 0.06 0.03 1.34 0.51 21.77 0.00 5.23 0.30 **0.00**
Note:
If Util shows more than 75-80% then you should keep an eye on your HDD.