From 8f1056face52a5e37d71028acbc5750c777bde82 Mon Sep 17 00:00:00 2001
From: Quentin Duchemin <quentinduchemin@tuta.io>
Date: Thu, 30 Apr 2020 21:53:46 +0200
Subject: [PATCH] [EtherpadDB] Try to optimize performance of index cache

---
 pica-etherpad-db/CHANGELOG.md           | 7 +++++++
 pica-etherpad-db/Dockerfile             | 1 +
 pica-etherpad-db/config/myisam_perf.cnf | 9 +++++++++
 pica-etherpad-db/docker-compose.yml     | 2 +-
 4 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 pica-etherpad-db/config/myisam_perf.cnf

diff --git a/pica-etherpad-db/CHANGELOG.md b/pica-etherpad-db/CHANGELOG.md
index 23095d7e..c3cfa816 100644
--- a/pica-etherpad-db/CHANGELOG.md
+++ b/pica-etherpad-db/CHANGELOG.md
@@ -1,3 +1,10 @@
+## mysql8.picapatch2
+
+Try to improve performance of MySQL
+
+* Increase [key_buffer_size](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_key_buffer_size) given that the index file is way too big for the default value
+* Also increase `read_buffer_size` to a [recommended value](https://dba.stackexchange.com/a/136409) of 256K
+* More precise base image tag
 
 ## mysql8.picapatch1
 
diff --git a/pica-etherpad-db/Dockerfile b/pica-etherpad-db/Dockerfile
index 6d216052..40f99a97 100644
--- a/pica-etherpad-db/Dockerfile
+++ b/pica-etherpad-db/Dockerfile
@@ -1,6 +1,7 @@
 FROM mysql:8
 
 COPY config/binary_log.cnf /etc/mysql/conf.d/binary_log.cnf
+COPY config/myisam_perf.cnf /etc/mysql/conf.d/myisam_perf.cnf
 
 # By default, COPY uses permissions `-rw-rw-rw-` for the file inside
 # the container. But mysql refuses to use config files that are world-
diff --git a/pica-etherpad-db/config/myisam_perf.cnf b/pica-etherpad-db/config/myisam_perf.cnf
new file mode 100644
index 00000000..11a134a2
--- /dev/null
+++ b/pica-etherpad-db/config/myisam_perf.cnf
@@ -0,0 +1,9 @@
+[mysqld]
+# The default value is 8Mo.
+# Given this documentation : https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_key_buffer_size,
+# we see that the  Key_reads/Key_read_requests ratio should normally be less than 0.01.
+# At the moment (04/2020), the ratio is more than 0.05, which indicates that the index is far larger than
+# the cache. The index is 300M. Right now with this setting, we will "waste" 700M of RAM,
+# which we can afford, and foresee further increase.
+key_buffer_size=1G
+read_buffer_size=256K
diff --git a/pica-etherpad-db/docker-compose.yml b/pica-etherpad-db/docker-compose.yml
index cf4775d9..9f5a107c 100644
--- a/pica-etherpad-db/docker-compose.yml
+++ b/pica-etherpad-db/docker-compose.yml
@@ -4,4 +4,4 @@ version : "2.4"
 
 services:
   etherpad-db:
-    image: registry.picasoft.net/pica-etherpad-db:mysql8.picapatch1
+    image: registry.picasoft.net/pica-etherpad-db:mysql8.picapatch2
-- 
GitLab