Я пытался решить эту проблему в течение 2 месяцев. Я уже увеличил все лимиты, о которых слышал, и до сих пор ничего. Проблема в том, что mariadb (ранее то же самое происходило с mysql 5.5.x) ограничивает потоки примерно 4500-4900 потоками за один раз. Когда мое программное обеспечение пытается создать больше соединений и используются все потоки, я получаю эту ошибку:
SQLSTATE[HY000] [1135] Невозможно создать новый поток (ошибка 11 Ресурс временно недоступен);
Теперь вот конфиги и ограничения, которые у меня сейчас есть на сервере. Сервер Дебиан 9.
Число процессов Htop: см. изображение
Подключения Mysql: [OK] Максимальное использование доступных подключений: 59% (4890/8200)
root:~# cat /proc/sys/kernel/threads-max
944163
root# cat /proc/$( pgrep -o mysql )/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 472081 472081 processes
Max open files 16364 16364 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 472081 472081 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 472081
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 65536
cpu time (seconds, -t) unlimited
max user processes (-u) 472081
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
кошка /etc/mysql/mariadb.conf.d/50-server.cnf | grep -v #
[server]
[mysqld]
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
key_buffer_size = 1G
max_allowed_packet = 64M
thread_stack = 16M
thread_cache_size = 4096
myisam_recover_options = BACKUP
max_connections = 8200
max_connect_errors = 10000000
query_cache_limit = 1G
query_cache_size = 30G
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql/slow-query.log
log_queries_not_using_indexes
table_open_cache = 65536
open_files_limit = 65536
key_buffer_size = 512M
table_cache = 4096
max_heap_table_size = 512M
innodb_buffer_pool_size = 20G
innodb_log_file_size = 2G
innodb_log_buffer_size = 64M
read_rnd_buffer_size=1M
sort_buffer_size=1G
skip_name_resolve
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
[embedded]
[mariadb]
[mariadb-10.1]
кошка /etc/security/limits.conf
root soft nofile 65536
root hard nofile 65536
root soft stack 65536
root hard stack 65536
www-data soft nofile 65536
www-data hard nofile 65536
mysql soft nofile 65536
mysql hard nofile 65536
mysql soft nproc 65536
mysql hard nproc 65536
mysql soft stack 65536
mysql hard stack 65536
nobody soft nofile 65536
nobody hard nofile 65536
* soft nproc 40960
* hard nproc 40960
* soft nofile 40960
* hard nofile 40960
* soft stack 65536
* hard stack 65536
# End of file
кошка /etc/sysctl.conf
# Disable IPv6 autoconf
net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.eth2.autoconf = 0
net.ipv6.conf.all.accept_ra_defrtr = 0
net.ipv6.conf.default.accept_ra_defrtr = 0
net.ipv6.conf.eth2.accept_ra_defrtr = 0
net.ipv6.conf.all.accept_ra_pinfo = 0
net.ipv6.conf.default.accept_ra_pinfo = 0
net.ipv6.conf.eth2.accept_ra_pinfo = 0
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.eth2.accept_ra = 0
net.core.somaxconn=1024
#kernel.sched_migration_cost_ns = 5000000
# Number of times SYNACKs for passive TCP connection.
net.ipv4.tcp_synack_retries = 2
# Allowed local port range
net.ipv4.ip_local_port_range = 1024 65535
# Protect Against TCP Time-Wait
net.ipv4.tcp_rfc1337 = 1
# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 15
# Decrease the time default value for connections to keep alive
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15
### TUNING NETWORK PERFORMANCE ###
# Default Socket Receive Buffer
net.core.rmem_default = 31457280
# Maximum Socket Receive Buffer
net.core.rmem_max = 16777216
# Default Socket Send Buffer
net.core.wmem_default = 31457280
# Maximum Socket Send Buffer
net.core.wmem_max = 16777216
# Increase number of incoming connections
net.core.somaxconn = 4096
# Increase number of incoming connections backlog
net.core.netdev_max_backlog = 65536
# Increase the maximum amount of option memory buffers
net.core.optmem_max = 25165824
# Increase the maximum total buffer-space allocatable
# This is measured in units of pages (4096 bytes)
net.ipv4.tcp_mem = 65536 131072 262144
net.ipv4.udp_mem = 65536 131072 262144
# Increase the read-buffer space allocatable
net.ipv4.tcp_rmem = 8192 87380 16777216
net.ipv4.udp_rmem_min = 16384
# Increase the write-buffer-space allocatable
net.ipv4.tcp_wmem = 8192 65536 16777216
net.ipv4.udp_wmem_min = 16384
# Increase the tcp-time-wait buckets pool size to prevent simple DOS attacks
net.ipv4.tcp_max_tw_buckets = 1440000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
fs.file-max = 500000
net.ipv4.tcp_max_syn_backlog = 20480
Я нашел кое-что здесь:
root@baza:~# systemctl status mysql
● mariadb.service - MariaDB database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2017-10-26 17:02:27 CEST; 1 months 11 days ago
Process: 12508 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 12284 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Process: 12106 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment
_WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
Process: 12102 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 12099 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Main PID: 12244 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 4915 (limit: 4915)
CGroup: /system.slice/mariadb.service
└─12244 /usr/sbin/mysqld
paź 26 17:02:23 baza systemd[1]: Starting MariaDB database server...
paź 26 17:02:24 baza mysqld[12244]: 2017-10-26 17:02:24 140040257753664 [Note] /usr/sbin/mysqld (mysqld 10.1.26-MariaDB-0+deb9u1) starting as process 12244 ...
paź 26 17:02:24 baza mysqld[12244]: 2017-10-26 17:02:24 140040257753664 [Warning] Could not increase number of max_open_files to more than 16364 (request: 16403)
paź 26 17:02:27 baza systemd[1]: Started MariaDB database server.
Затем: systemctl show -all | Задачи grep DefaultTasksAccounting=yes DefaultTasksMax=4915
Решено
Решено добавлением следующего: (глупое ограничение по умолчанию в 4915 потоков) DefaultTasksMax=infinity в /etc/systemd/system.conf TasksMax=infinity в /etc/systemd/system/mysql.service< /сильный>
variable_name
LIKE '%thread%'; | Имя_переменной | Значение | | Threads_cached | 2221 | | Threads_connected | 2595 | | Threads_created | 4141324 | | Threads_running | 64 | ТАК ЭТО НЕ ПРОБЛЕМА ИЗ ПАМЯТИ :) и в этом весь смысл - person silverangel   schedule 07.12.2017