Use MARIADB_USAGE for MariaDB memory budget
This commit is contained in:
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
MARIADB_MEMORY_PERCENT=25
|
MARIADB_USAGE="${MARIADB_USAGE:-25}"
|
||||||
MIN_BUFFER_POOL_MB=256
|
MIN_BUFFER_POOL_MB=256
|
||||||
MAX_CONNECTIONS_MIN=80
|
MAX_CONNECTIONS_MIN=80
|
||||||
MAX_CONNECTIONS_MAX=300
|
MAX_CONNECTIONS_MAX=300
|
||||||
@@ -12,7 +12,7 @@ Usage:
|
|||||||
my-cnf-gen.sh [--output PATH]
|
my-cnf-gen.sh [--output PATH]
|
||||||
|
|
||||||
Generates a conservative MariaDB 10.6 my.cnf for DirectAdmin servers.
|
Generates a conservative MariaDB 10.6 my.cnf for DirectAdmin servers.
|
||||||
The InnoDB buffer pool is sized to about 25% RAM so other DA services
|
The InnoDB buffer pool is sized from MARIADB_USAGE percent of RAM so other DA services
|
||||||
such as web, exim, dovecot, redis and spam filtering keep enough memory.
|
such as web, exim, dovecot, redis and spam filtering keep enough memory.
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ calc_buffer_pool_mb() {
|
|||||||
local mem_mb="$1"
|
local mem_mb="$1"
|
||||||
local pool_mb
|
local pool_mb
|
||||||
|
|
||||||
pool_mb=$((mem_mb * MARIADB_MEMORY_PERCENT / 100))
|
pool_mb=$((mem_mb * MARIADB_USAGE / 100))
|
||||||
if (( pool_mb < MIN_BUFFER_POOL_MB )); then
|
if (( pool_mb < MIN_BUFFER_POOL_MB )); then
|
||||||
pool_mb="$MIN_BUFFER_POOL_MB"
|
pool_mb="$MIN_BUFFER_POOL_MB"
|
||||||
fi
|
fi
|
||||||
@@ -152,7 +152,7 @@ generate_config() {
|
|||||||
# Generated by my-cnf-gen.sh for MariaDB 10.6 and DirectAdmin stack hosts.
|
# Generated by my-cnf-gen.sh for MariaDB 10.6 and DirectAdmin stack hosts.
|
||||||
# Detected RAM: ${mem_mb}M
|
# Detected RAM: ${mem_mb}M
|
||||||
# Detected CPU cores: ${cores}
|
# Detected CPU cores: ${cores}
|
||||||
# MariaDB memory budget: ${MARIADB_MEMORY_PERCENT}% RAM
|
# MariaDB memory budget: ${MARIADB_USAGE}% RAM
|
||||||
|
|
||||||
[client]
|
[client]
|
||||||
port=3306
|
port=3306
|
||||||
|
|||||||
@@ -203,7 +203,8 @@ assert_file_contains "$ROOT_DIR/my.cnf" 'query_cache_size=0'
|
|||||||
assert_file_not_contains "$ROOT_DIR/my.cnf" 'query-cache-type'
|
assert_file_not_contains "$ROOT_DIR/my.cnf" 'query-cache-type'
|
||||||
assert_file_not_contains "$ROOT_DIR/my.cnf" 'query-cache-size'
|
assert_file_not_contains "$ROOT_DIR/my.cnf" 'query-cache-size'
|
||||||
assert_file_not_contains "$ROOT_DIR/my.cnf" 'innodb_file_format'
|
assert_file_not_contains "$ROOT_DIR/my.cnf" 'innodb_file_format'
|
||||||
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MARIADB_MEMORY_PERCENT=25'
|
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MARIADB_USAGE="\$\{MARIADB_USAGE:-25\}"'
|
||||||
|
assert_file_not_contains "$ROOT_DIR/my-cnf-gen.sh" 'MARIADB_MEMORY_PERCENT'
|
||||||
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MYSQL_GEN_MEM_MB'
|
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MYSQL_GEN_MEM_MB'
|
||||||
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MYSQL_GEN_CPU_CORES'
|
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MYSQL_GEN_CPU_CORES'
|
||||||
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" '/proc/meminfo'
|
assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" '/proc/meminfo'
|
||||||
@@ -231,6 +232,8 @@ MYSQL_GEN_MEM_MB=8192 MYSQL_GEN_CPU_CORES=4 "$ROOT_DIR/my-cnf-gen.sh" --output "
|
|||||||
grep -qx 'innodb_buffer_pool_size=2G' "$generated_my_cnf" || fail "generated my.cnf should allocate 25% of 8G to InnoDB"
|
grep -qx 'innodb_buffer_pool_size=2G' "$generated_my_cnf" || fail "generated my.cnf should allocate 25% of 8G to InnoDB"
|
||||||
grep -qx 'max_connections=80' "$generated_my_cnf" || fail "generated my.cnf should keep low-RAM max_connections conservative"
|
grep -qx 'max_connections=80' "$generated_my_cnf" || fail "generated my.cnf should keep low-RAM max_connections conservative"
|
||||||
grep -qx 'query_cache_size=0' "$generated_my_cnf" || fail "generated my.cnf should disable query cache"
|
grep -qx 'query_cache_size=0' "$generated_my_cnf" || fail "generated my.cnf should disable query cache"
|
||||||
|
MARIADB_USAGE=50 MYSQL_GEN_MEM_MB=8192 MYSQL_GEN_CPU_CORES=4 "$ROOT_DIR/my-cnf-gen.sh" --output "$generated_my_cnf"
|
||||||
|
grep -qx 'innodb_buffer_pool_size=4G' "$generated_my_cnf" || fail "MARIADB_USAGE override should change InnoDB allocation"
|
||||||
|
|
||||||
kv_file="$tmp_dir/example.conf"
|
kv_file="$tmp_dir/example.conf"
|
||||||
printf 'ns1=old.example\nother=value\n' > "$kv_file"
|
printf 'ns1=old.example\nother=value\n' > "$kv_file"
|
||||||
|
|||||||
Reference in New Issue
Block a user