I was looking for the bottleneck of a web application and found out that INSERT queries run significant slower like this:
MariaDB [myforum]> insert into tag set tagtext='abc12345',dateline=unix_timestamp(),canonicaltagid=1234;
Query OK, 1 row affected (0.24 sec)
This was done by installing the mysql-client
in the application container for testing purpose. 240ms seems very long for such a simple query. I assumed some dns/network problems. But I see similar results when running the query directly in the MariaDB container, where the connection was made using -h 127.0.0.1
:
MariaDB [myforum]> insert into tag set tagtext='abc123',dateline=unix_timestamp(),canonicaltagid=1234;
Query OK, 1 row affected (0.251 sec)
Only INSERT queries are effected. SELECTs were pretty fast as expected. Strangely, this seems to have something to do with the MariaDB Docker installation: I have the same Database on a local XAMPP installation, where same query is fast:
MariaDB [myforum]> insert into tag set tagtext='abc123',dateline=unix_timestamp(),canonicaltagid=123;
Query OK, 1 row affected (0.00 sec)
I can only do limited changes on the tables itself since these are from vBulletin (old, proprietary forum CMS).
I'm wondering why those simple queries are so extremly slow?
Already tried
- Changed the I/O Scheduler for both discs at runtime and also in Grub with reboot
- Setting barrier=0 in fstab
- Set
slice_idle
andgroup_idle
to zero (default value was 8) - Optimized all tables
Structure of the test table (seems also affecting other tables)
CREATE TABLE `tag` (
`tagid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`tagtext` VARCHAR(100) NOT NULL DEFAULT '',
`dateline` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`canonicaltagid` INT(10) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`tagid`),
UNIQUE INDEX `tagtext` (`tagtext`),
INDEX `canonicaltagid` (`canonicaltagid`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=4112
;
Docker Compose file
version: '2'
volumes:
mysql-data:
services:
# Here is another service that access the db using dns name 'mariadb'
mariadb:
container_name: mariadb
image: mariadb:10.3
mem_limit: 3GB
restart: always
env_file:
- mariadb.env
volumes:
- ../dump.sql:/docker-entrypoint-initdb.d/dump.sql
- mysql-data:/var/lib/mysql
System information about the underlying Docker host server
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
# docker --version
Docker version 19.03.1, build 74b1e89
# docker-compose --version
docker-compose version 1.24.1, build 4667896b
The server has a software raid 1 with two enterprise hdds, enough CPU power and memory (32GB). And it's currently not used for any other application, nor there is any load from users. So I can exclude that its a load issue.
insert tag(tagtext,dateline,canonicaltagid) values('a123',unix_timestamp(),123);
the query took also 295ms, so it's similar slow. – Hodinnodb_buffer_pool_size
? – Conjugatedinnodb_buffer_pool_size = 268435456
. I kept the entire SQL configuration to the defaults of MariaDB. – Hod