DB optimization - mariadb

I have problems with my DB proceses
I runn an website developed using angular, typescript and laravel
Script demo: https://codecanyon.net/item/mtdb-ultimate-movietv-database/6447206
Script documentation: https://support.vebto.com/help-center/categories/35/mtdb-ultimate-movieandtv-database
Server:
Processor: Intel 2x Xeon Silver 4214 - 24 c / 48 t - 2.2 GHz / 3.2 GHz
Memory: 96GB DDR4 ECC 2400MHz
Storage: 2x960GB SSD NVMe Soft RAID 1
PHP 7.3 fcgi
mysql - MariaBD 10.3:
[mysqld]
log-error=/var/lib/mysql/server188.com.err
performance-schema=0
innodb_file_per_table=1
local-infile=0
key_buffer_size = 256M
max_allowed_packet = 268435456
innodb_buffer_pool_size=134217728
max_connections = 1000
max_user_connections = 500
wait_timeout = 28800
connect_timeout = 10
table_open_cache=4000
join_buffer_size = 1M
open_files_limit=10000
tmp_table_size = 64M
max_heap_table_size = 64M
read_buffer_size = 64M
concurrent_insert = 2
max_connect_errors = 10
net_buffer_length = 16384
myisam_sort_buffer_size = 64M
bulk_insert_buffer_size = 8M
thread_cache_size = 384
query_cache_limit = 7M
query_cache_size = 64M
query_cache_type = 1
query_prealloc_size = 262144
query_alloc_block_size = 65536
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
max_write_lock_count = 16
#skip-networking
innodb_buffer_pool_size=4G
innodb_thread_concurrency=16
performance-schema=0
default-storage-engine=MyISAM
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M
The strangest thing is that when I get an cpu load of 16 - 17, my site stop loading, but others websites on the same server runn very well.
Also, the load NEVER pass of 17 cpu, but the server can handle 48
I think there is some limit somewhere.
Can someone make a suggestion?

Related

mariadb cluster synced but one node shows size=0

I use mariadb 10.5 with galera 4. I have a 3 node cluster which worked perfectly for the past 6 months. Lately I have been having problems with very cpu intensive query and had to kill that process. One of the nodes (n1) went out of sync so I recreated it. Everything synced perfectly but since that day n1 shows wsrep_cluster_size=0 and the rest of them show wsrep_cluster_size=3.
After a couple of days I decided to stop n2 and n3 to recreate it from n1. Again everything went smoothly but now n3 shows wsrep_cluster_size=0 and n1,n2 show wsrep_cluster_size=3.
I have no idea what's going on. I've checked all the logs and manually checked all the tables and everything seems ok. Data is synced and database is working just fine.
Heres is my configuration
[mysqld]
binlog_format = ROW
bind-address = 0.0.0.0
# Galera Provider Configuration
wsrep_on = ON
wsrep_provider = /usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name = cluser
wsrep_cluster_address = gcomm://10.0.0.2,10.0.0.3,10.0.0.4
wsrep_node_address = 10.0.0.2
wsrep_node_name = n1
# Galera Synchronization Configuration
wsrep_sst_method = rsync
log_error = /var/lib/mysql/node.log
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
innodb_locks_unsafe_for_binlog = 1
innodb_file_per_table = 1
#innodb_thread_concurrency = 0
innodb_buffer_pool_size = 10G
#innodb_log_buffer_size = 64M
innodb_flush_method = O_DIRECT
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
wsrep_slave_threads = 5
innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode = 2
skip-name-resolve
lc-messages-dir = /usr/share/mysql
skip-external-locking
key_buffer_size = 16M
max_connections = 300
wait_timeout = 20
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
expire_logs_days = 10
max_binlog_size = 100M
Here is my SHOW STATUS LIKE 'wsrep%' for 3 nodes
https://pastebin.com/GXj0c38R
And logs
https://pastebin.com/YxJBcguK
This is definitely a bug. Please report it on MariaDB JIRA.
In addition to the wsrep_cluster_size=0 on n3, wsrep_cluster_conf_id is uninitialised (and not the 23 like other nodes) and wsrep_cluster_state_uuid is blank.
For a synced node I'd expect these to have consistent values on all nodes.

Slow Query in Big Database

I have slow queries with a mysql request. But the request is not difficult:
SELECT * FROM emailarchiv WHERE typ='MAIL' AND benutzer = '542' ORDER BY datum DESC LIMIT 0,50;
# User#Host: XXX[XXX] # localhost []
# Thread_id: 13245239 Schema: usr_XXX_1 QC_hit: No
# Query_time: 20.919740 Lock_time: 0.000066 Rows_sent: 50 Rows_examined: 79212
Ok, in the database are 79212 entrys...but 20seconds???
My System: Centos7 MariaDB 5.5, 10GB RAM, 10 CPUs
Here my my.conf:
[mysqld]
local-infile = 0
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
user = mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
# Forced OLD_PASSWORD format is turned OFF by Plesk
#old_passwords = 1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links = 0
max_connections = 100
#port = 3306 #Port nicht aendern
key_buffer_size = 512M
max_allowed_packet = 256M
table_open_cache = 4096
sort_buffer_size = 64M
net_buffer_length = 128K
read_buffer_size = 1512K
read_rnd_buffer_size = 4096K
myisam_sort_buffer_size = 64M
max_heap_table_size = 512M
tmp_table_size = 1024M
key_cache_block_size = 4096
query_cache_size = 512M
query_cache_limit = 512M
thread_cache_size = 20
table_cache = 16384
#open_files_limit = 9212 #nicht aktivieren!! Verursacht Probleme...
#wait_timeout = 10 #nicht aktivieren !!
join_buffer_size = 32M
#bind-address = 127.0.0.1
#Aenderungen ab 23.07.2021
innodb_buffer_pool_size = 512M
max_heap_table_size= 1024M
skip-name-resolve
slow-query-log = 1
slow-query-log-file = /srv/slow-query.log
long_query_time = 5
ssl-ca=/etc/mysql-ssl/ca-cert.pem
ssl-cert=/etc/mysql-ssl/server-cert.pem
ssl-key=/etc/mysql-ssl/server-key.pem
[mysqld_safe]
#log-error = /var/log/mysqld.log
What goes here wrong?
I solved the problem by myself ;-)
I don't use indexes for the rows "typ" and "benutzer" that was the problem. Now the Query_time is 2 seconds 👍

Thoug max_allow_packet is 1 G , "ERROR 2006 (HY000): MySQL server has gone away" appear

I installed Mariadb 10.5.12-1.el7 on Centos 7.9
Sometimes when I run some query like "SHOW VARIABLES LIKE 'max_join_size';" , this message appear :
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 3515012
Current database: *** NONE ***
I setup a cluster Packemaker/drbd/mariadb
And these are the conf:
max_allow_packet = 1G
bind-address = 0.0.0.0
datadir= /db/mysql/
socket=/db/mysql/mysql.sock
log_error=/var/log/mariadb/error.log
skip-external-locking
innodb_buffer_pool_size = 75G
innodb_log_file_size = 18G
innodb_buffer_pool_instances = 75
max_allowed_packet = 1G
thread_stack = 256K
thread_cache_size = 2000
max_connections = 2000
query_cache_limit = 256K
table_open_cache = 2000
table_definition_cache = 1400
expire_logs_days = 10
max_binlog_size = 100M
default_storage_engine = innodb
innodb_file_per_table = 1
interactive_timeout = 30
wait_timeout = 30
query_cache_type = 1
query_cache_size = 36M
query_cache_min_res_unit = 2K
What is the cause of this issue ?
Thanks

MariaDB 10.1 using too much RAM on Debian 9.12

I am administrating a server with MariaDB and it often uses a lot of RAM - often so much that it crashes because it can't allocate more RAM, and even when it doesn't it can be pretty slow because it swaps. Even when it is running smoothly, I can see with htop that among the processes using the most RAM there are two dozen of /usr/sbin/mysqld processes. Of course I googled it but I barely understand what the settings in my.cnf do, so nothing I changed appeared to have an effect.
The server has:
2 GB of RAM
Debian GNU/Linux 9.12 (stretch)
mysql --version returns: Ver 15.1 Distrib 10.1.44-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Here is the content of /etc/mysql/my.cnf:
# This file has been automatically moved from your previous
# /etc/mysql/my.cnf, with just this comment added at the top, to maintain MySQL
# operation using your previously customised configuration.
# To switch to the new packaging configuration for automated management of
# /etc/mysql/my.cnf across multiple variants:
#
# 1. Move your customisations from this file to /etc/mysql/conf.d/ and
# to /etc/mysql/<variant>.conf.d/ as appropriate.
# 2. Run "update-alternatives --remove my.cnf /etc/mysql/my.cnf.migrated"
# 3. Remove the file /etc/mysql/my.cnf.migrated
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
bind-address = ***.***.***.***
#
# * Fine Tuning
#
key_buffer = 8M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 8M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
slow_query_log_file = /var/log/mysql/mysql-slow.log
# slow_query_log = 1
long_query_time = 1
#log_queries_no_using_indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
character_set_server=utf8mb4
skip_character_set_client_handshake
skip-name-resolve
tmp_table_size= 32M # 128
max_heap_table_size=128M
wait_timeout=60 #120
max_connections=25 # 40
thread_stack=128K
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
Is something wrong in my my.cnf? Would updating MariaDB help?

Memory leaks with nginx + php-fpm

I need some help with a server running a single website. The memory is increasing really fast, about 1GB per day.
Restarting php-fpm and nginx is not freeing any memory.
I need to reboot the whole server every 15 days, I can't figure out the problem since 4 months now.
Here is the status and conf files, I hope you can help ;)
Using
Nginx/1.4.5 PHP 5.5.3-1ubuntu2.3
APCu Version 4.0.1
Memcached and php memcache
Memcache status :
Free: 46.3 MBytes (72.4%)
Used: 17.7 MBytes (27.6%)
Hits: 30985436 (60.3%)
Misses: 20412444 (39.7%)
Used Cache Size 17.7 MBytes
Total Cache Size 64.0 MBytes
APCu status
Free: 1023.4 MBytes (99.9%)
Used: 637.7 KBytes (0.1%)
Hits: 40594423 (100.0%)
Misses: 428 (0.0%)
Request Rate (hits, misses) 73.83 cache requests/second
Hit Rate 73.83 cache requests/second
Nginx status :
Active connections: 146
server accepts handled requests
8792651 8792651 17113216
Reading: 0 Writing: 11 Waiting: 135
php fpm status :
pool: www
process manager: static
start time: 05/Jun/2014:09:44:04 +0200
start since: 549019
accepted conn: 62499
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 33
active processes: 27
total processes: 60
max active processes: 61
max children reached: 0
slow requests: 14236
top command :
top - 18:13:51 up 6 days, 8:29, 1 user, load average: 0,56, 0,57, 0,66
Tasks: 193 total, 2 running, 191 sleeping, 0 stopped, 0 zombie
%Cpu(s): 13,6 us, 1,0 sy, 0,0 ni, 85,1 id, 0,0 wa, 0,0 hi, 0,3 si, 0,0 st
KiB Mem: 32840792 total, 9399012 used, 23441780 free, 465028 buffers
KiB Swap: 1046520 total, 0 used, 1046520 free, 1931844 cached
File : php-fpm.conf
[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php/php5-fpm.log
log_level = notice
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 20s
include=/etc/php5/fpm/pool.d/*.conf
File : pool.d/www.conf
[www]
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.backlog = 65536
pm = static
pm.max_children = 60
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 5000
pm.status_path = /php-status
ping.path = /php-ping
slowlog = /var/log/php/$pool.log.slow
request_slowlog_timeout = 30s
request_terminate_timeout = 120s
rlimit_files = 131072
rlimit_core = unlimited
chdir = /
catch_workers_output = yes
security.limit_extensions = .php .php3 .php4 .php5 .jpg
File : sysctl.conf
net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.eth0.autoconf = 0
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.eth0.accept_ra = 0
net.core.somaxconn=65535
fs.file-max = 100000
kernel.pid_max = 1048576
net.core.wmem_max = 1048576
net.core.optmem_max = 1048576
vm.max_map_count = 262144
net.core.rmem_max = 1048576
Thank you !
regards,
Anthony

Resources