Skip to content

Commit

Permalink
Merge pull request #913 from uselagoon/fix-mysqltuner
Browse files Browse the repository at this point in the history
Improve MariaDB performance monitoring settings
  • Loading branch information
tobybellwood authored Jan 23, 2024
2 parents 60a55d1 + 29b0c9c commit ff45cb8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 3 deletions.
12 changes: 12 additions & 0 deletions helpers/TESTING_service_images_dockercompose.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ docker-compose exec -T mariadb-10-6 sh -c "mysql -V" | grep "10.6"
# mariadb-10-6 should be version 10.6 server
docker-compose exec -T mariadb-10-6 sh -c "mysql -e \'SHOW variables;\'" | grep "version" | grep "10.6"

# mariadb-10-6 should have performance schema and slow logging disabled
docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "performance_schema" | grep "OFF"
docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "slow_query_log" | grep "OFF"
docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "long_query_time" | grep "10"
docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "log_slow_rate_limit" | grep "1"

# mariadb-10-6 should use default credentials
docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW databases;\'" | grep lagoon

Expand All @@ -176,6 +182,12 @@ docker-compose exec -T mariadb-10-11 sh -c "mysql -V" | grep "10.11"
# mariadb-10-11 should be version 10.11 server
docker-compose exec -T mariadb-10-11 sh -c "mysql -e \'SHOW variables;\'" | grep "version" | grep "10.11"

# mariadb-10-11 should have performance schema and slow logging enabled
docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "performance_schema" | grep "ON"
docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "slow_query_log" | grep "ON"
docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "long_query_time" | grep "30"
docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "log_slow_rate_limit" | grep "5"

# mariadb-10-11 should use default credentials
docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW databases;\'" | grep lagoon

Expand Down
5 changes: 5 additions & 0 deletions helpers/services-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ services:
image: uselagoon/mariadb-10.11:latest
ports:
- "3306"
environment:
- MARIADB_PERFORMANCE_SCHEMA=true
- MARIADB_LOG_SLOW=true
- MARIADB_LONG_QUERY_TIME=30
- MARIADB_LOG_SLOW_RATE_LIMIT=5
<< : *default-user # uses the defined user from top

mongo-4:
Expand Down
1 change: 1 addition & 0 deletions images/mariadb/10.11.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RUN apk update \
mariadb=~10.11 \
mariadb-connector-c \
net-tools \
perl-doc \
pwgen \
rsync \
tar \
Expand Down
1 change: 1 addition & 0 deletions images/mariadb/10.4.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RUN apk update \
mariadb=~10.4 \
mariadb-connector-c \
net-tools \
perl-doc \
pwgen \
rsync \
tar \
Expand Down
1 change: 1 addition & 0 deletions images/mariadb/10.5.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RUN apk update \
mariadb=~10.5 \
mariadb-connector-c \
net-tools \
perl-doc \
pwgen \
rsync \
tar \
Expand Down
1 change: 1 addition & 0 deletions images/mariadb/10.6.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RUN apk update \
mariadb=~10.6 \
mariadb-connector-c \
net-tools \
perl-doc \
pwgen \
rsync \
tar \
Expand Down
7 changes: 5 additions & 2 deletions images/mariadb/entrypoints/100-mariadb-logging.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
set -eo pipefail

if [ -n "$MARIADB_LOG_SLOW" ]; then
echo "MARIADB_LOG_SLOW set, logging to /etc/mysql/conf.d/log-slow.cnf"
echo "MARIADB_LOG_SLOW set, logging to /var/log/mariadb-slow.log"
cat <<EOF > /etc/mysql/conf.d/log-slow.cnf
[mysqld]
log-output=file
slow_query_log = 1
slow_query_log_file = /var/log/mariadb-slow.log
long_query_time = ${MARIADB_LONG_QUERY_TIME:-10}
log_slow_rate_limit = ${MARIADB_LOG_SLOW_RATE_LIMIT:-1}
EOF
fi


if [ -n "$MARIADB_LOG_QUERIES" ]; then
echo "MARIADB_LOG_QUERIES set, logging to /etc/mysql/conf.d/log-queries.cnf"
echo "MARIADB_LOG_QUERIES set, logging to /var/log/mariadb-queries.log"
cat <<EOF > /etc/mysql/conf.d/log-queries.cnf
[mysqld]
Expand Down
15 changes: 14 additions & 1 deletion images/mariadb/entrypoints/150-mariadb-performance.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@ if [ "$LAGOON_ENVIRONMENT_TYPE" == "production" ]; then
if [ -z ${MARIADB_INNODB_LOG_FILE_SIZE+x} ]; then
export MARIADB_INNODB_LOG_FILE_SIZE=256M
fi
fi
fi

if [ -n "$MARIADB_PERFORMANCE_SCHEMA" ]; then
echo "Enabling performance schema"
cat <<EOF > /etc/mysql/conf.d/performance-schema.cnf
[mysqld]
performance_schema=ON
performance-schema-instrument='stage/%=ON'
performance-schema-consumer-events-stages-current=ON
performance-schema-consumer-events-stages-history=ON
performance-schema-consumer-events-stages-history-long=ON
EOF

fi

0 comments on commit ff45cb8

Please sign in to comment.