title: INSERT SQL query very slow in MariaDB Docker container compared to XAMPP
body: <p>I was looking for the bottleneck of a web application and found out that INSERT queries run significant slower like this: </p>
  
  <pre><code>MariaDB [myforum]&gt; insert into tag set tagtext='abc12345',dateline=unix_timestamp(),canonicaltagid=1234;
  Query OK, 1 row affected (0.24 sec)
  </code></pre>
  
  <p>This was done by installing the <code>mysql-client</code> 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 <code>-h 127.0.0.1</code>:</p>
  
  <pre><code>MariaDB [myforum]&gt; insert into tag set tagtext='abc123',dateline=unix_timestamp(),canonicaltagid=1234;
  Query OK, 1 row affected (0.251 sec)
  </code></pre>
  
  <p>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: </p>
  
  <pre><code>MariaDB [myforum]&gt; insert into tag set tagtext='abc123',dateline=unix_timestamp(),canonicaltagid=123;
  Query OK, 1 row affected (0.00 sec) 
  </code></pre>
  
  <p>I can only do limited changes on the tables itself since these are from vBulletin (old, proprietary forum CMS). </p>
  
  <p>I'm wondering why those simple queries are so extremly slow? </p>
  
  <h2>Already tried</h2>
  
  <ul>
  <li><a href="https://blog.codeship.com/linux-io-scheduler-tuning/" rel="noreferrer">Changed the I/O Scheduler</a> for both discs at runtime and also <a href="https://askubuntu.com/a/82452/650986">in Grub with reboot</a></li>
  <li><a href="http://phpforus.com/how-to-make-mysql-run-fast-with-ext4-on-ubuntu/" rel="noreferrer">Setting barrier=0 in fstab</a></li>
  <li><a href="https://github.com/docker/for-linux/issues/247#issuecomment-389900952" rel="noreferrer">Set <code>slice_idle</code> and <code>group_idle</code> to zero (default value was 8)</a></li>
  <li><a href="https://forums.docker.com/t/mysql-slow-performance-in-docker/37179/16" rel="noreferrer">Optimized all tables</a></li>
  </ul>
  
  <h2>Structure of the test table (seems also affecting other tables)</h2>
  
  <pre><code>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
  ;
  </code></pre>
  
  <h2>Docker Compose file</h2>
  
  <pre><code>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
  </code></pre>
  
  <h2>System information about the underlying Docker host server</h2>
  
  <pre><code># 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
  </code></pre>
  
  <p>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.</p>