Mysql is using system file cache, not RAM directly - mysql

I have an Ubuntu 64-bit system and running Mysql version 5.5.32-0ubuntu0.12.04.1-log. The machine has 64 GB ram.
I have a pretty huge database which almost has 90 GB of data and one table with 250.000.000 rows.
My problem is, that the mysqld process does not take much memory. Just between 2-5 GB. But the memory of the system is fully used for the file cache.
I restarted the server, there were 63 GB memory free. Once I started to execute larger queries, the amount of free memory decreases, while the amount of file cached increases.
So mysql is not loading the data in its RAM, but it uses the file cache.
Queries are very slow. When I query the big table, which - according to explain - uses an index and only has 500.000 rows to consider, it takes minutes.
Do you have any explanation for this phenomen?
Here is my my.cnf. (This is actually the config of my slave, but it shows exactly the same behaviour) My tables are all InnoDB:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[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
bind-address = 127.0.0.1
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error = /var/log/mysql/error.log
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
[innodb]
innodb_buffer_pool_size = 55G
innodb_log_file_size = 256M
innodb_log_buffer_size = 4M
innodb_flush_log_at_trx_commit=2
innodb_thread_concurrency=0
innodb_file_per_table = 1 # (this is not respected as I changed it after the first database was created). So my ibdata1 file is over 80GB in size
max_connections = 1000 # wenn gleichzeitig viele User zugreifen
table_cache = 10000 # abgeleitet von max_connections, könnte sogar höher sein
tmp_table_size = 5000M # wichtig wg. JOINs, zu kleiner Wert macht die extrem langsam
max_heap_table_size = 5000M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M
!includedir /etc/mysql/conf.d/

Increase the key_buffer size to 128M and max_allowed_packet to 128M, as this will speed up the execution of queries

I finally figured out was the problem was. The
innodb_buffer_pool_size = 55G
does not belong in the [innodb] section, but in the [mysqld] section.
All the innodb configs needed to be placed in the mysqld section.

Related

The problem with the load of RAM in the virtual machine where it is installed MySQL

Schedule for Hour
Daily Schedule
There is a virtual machine installed on the PROXMOX, MySQL is installed there.
For this VM allocated 30GB of RAM and 20 cores because it receives a lot of data.
The problem is that the load on the VM gradually increases, and I do not understand why.
After a reboot MySQL server, the data is processed very quickly, while the load on the RAM in the region of 3-4 GB.
After the server has been running for more than 24 hours, the data starts to be processed for a very long time, while the data arrive in the same amount.
The load on the RAM rises to 25GB.
What's wrong?
I attach a screenshot and my.cnf.
I'm sorry for my bad English.
Thanks for answers.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
skip-name-resolve
event_scheduler = on
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
language = /usr/share/mysql/english
skip-external-locking
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 512K
thread_cache_size = 8
myisam-recover = BACKUP
max_connections = 700
#table_cache = 64
#thread_concurrency = 12
query_cache_limit = 1M
query_cache_size = 50M
innodb_buffer_pool_size = 16G
innodb_buffer_pool_instances = 16
innodb_additional_mem_pool_size=400M
innodb_log_buffer_size=80M
innodb_flush_log_at_trx_commit = 0
innodb_log_file_size = 128M
innodb_flush_method=O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_thread_concurrency = 12
sort_buffer=512M
thread_concurrency=32
#record_buffer=128M
query_cache_type=2
tmp_table_size=1G
general_log_file = /var/log/mysql/mysql.log
general_log = 0
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 10 = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
[mysql]
[isamchk]
key_buffer = 16M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[isamchk]
key_buffer = 16M
Rate Per Second=RPS - Suggestions to consider for your my.cnf [mysqld] section
key_cache_age_threshold=7200 # from 300 seconds to reduce key_reads RPS of 240123
thread_cache_size=100 # from 8 to reduce threads_created in 1 day
innodb_buffer_pool_size=20G # from 16G to reduce innodb_buffer_pool_reads RPS of 20
innodb_read_io_threads=64 # from 1 for improved read performance
innodb_write_io_threads=64 # from 1 for improved write performance
Please get in touch, there are many more opportunities available to improve your instance response time.

Setting Up my.cnf and Apache.conf on a Wordpress site with 40K monthly visitors

Since we are rookies on this, we are having a hard time trying to setup a Wordpress server to support around 200K monthly visiting users. We have two boxes (details below).
The issue here is when the users start accessing the server, MySQL CPU goes to 149%. Here is a copy of the apache2.conf and the mysql.cnf files. Our MySQL database is InnoDB. Any suggestions on how to fix it?
1. Apache Server
Configuration
8 GB Memory / 25 GB Disk + 200 GB / Ubuntu 16.04
apache.conf excerpt
Timeout 40
KeepAlive On
MaxKeepAliveRequests 500
KeepAliveTimeout 2
2. MySQL Server
Configuration
8 GB Memory / 25 GB Disk + 50 GB / Ubuntu 16.04
my.cnf file
root#mundo-mysql01-c-2-4gib-nyc3-01:/etc/mysql# cat my.cnf
#
# 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
#
# * 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/
!includedir /etc/mysql/mysql.conf.d/
[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
general_log_file = /var/log/mysql/mysql.log
general_log = 0
# CACHES AND LIMITS #
open_files_limit = 65535
table_definition_cache = 1024
table_open_cache = 2048
# MyISAM Settings
max_connections = 300
key_buffer_size = 256M
myisam_sort_buffer_size = 32M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 16M
thread_cache_size = 32
wait_timeout = 300
connect_timeout = 300
tmp_table_size = 32M
max_heap_table_size = 128M
max_allowed_packet = 128M
max_connect_errors = 10000
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
query_cache_limit = 4M
query_cache_size = 128M
query_cache_type = 1
query_prealloc_size = 65536
query_alloc_block_size = 131072
low_priority_updates = 1
max_write_lock_count = 1
# * InnoDB
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 256M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 2048M

How to fix high memory usage of MariaDB?

I am using MariaDB(10.1.21) with following storage engines:
InnoDB
TokuDB
Spider Engine
System Configuration is :
3GB RAM
Dual Core Processor
I have tried pt-mysql-summary tool to identify the memory usage and it shows 90% of innodb buffer pool size is filled,when no process is running on server.
I have also tried restarting the MariaDB server and this reduces memory for about 1-2 hours only and after that it eats up memory.
Any clue why it is consuming too much memory?
Sharing my configurations below:
My.cnf
[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]
#performance_schema=ON
tmp_table_size=16M
max_heap_table_size=16M
skip-log-bin
#table_open_cache =16384
#table_definition_cache =16384
#
# * 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
lc_messages = en_US
skip-external-locking
#bind-address = 127.0.0.1
#skip-networking
# SAFETY #
max_allowed_packet= 16M
max-connect-errors = 1000000
skip-name-resolve
#sql-mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
# LOGGING #
log_warnings = 2
slow_query_log =1
log-output = TABLE
long_query_time = 5
log_slow_verbosity = query_plan
log-error =/var/log/mysql/system_error.err
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 128M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 1720M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completion
[isamchk]
key_buffer = 16M
TokuDB.cnf
plugin-load-add=ha_tokudb.so
tokudb_data_dir=/var/lib/mysql/toku_db_data
tokudb_read_block_size=64k
tokudb_row_format=tokudb_zlib
tokudb_directio=on
Spider.cnf
[mariadb]
#spider_internal_limit =1
spider_direct_order_limit =1
spider_skip_default_condition =1
spider_casual_read =1
spider_bgs_mode =2
spider_direct_dup_insert =1
spider_auto_increment_mode =2
#optimizer_switch='engine_condition_pushdown=on'
#optimizer_switch='mrr=on,mrr_sort_keys=off'
innodb-buffer-pool-size = 1720M is much too large for a 3GB machine, especially if TokuDB and Spider are also in use.
The real question is, "is there any swapping"? If there is no swapping, then there is no problem. If there is swapping, then the first defense is to lower that setting. I suggest 500M. Swapping is very bad for performance of MySQL.
It is normal to see 90%. 92% is the median value for (Innodb_buffer_pool_bytes_data / innodb_buffer_pool_size) a sampling of machines. Since the buffer_pool is a cache, it is normal to be "full" most of the time. (It rarely gets over 98% full -- probably leaving some space for quick reuse.) If it is below, say, 50% full after running for several hours, I would say the innodb_buffer_pool_size is too big for the dataset in question.
Suggest lowering to long_query_time = 2 in order to catch faster, but frequent, queries, too.

performance tuning of my sql in 12 GB ram with 21 Intel(R) Xeon(R) CPU E5-2620 0 # 2.00GHz

Hi are trying to optimize MySQL for a huge traffic web server, we are using Apache 2.4 , and MySQL 5.6 version.
We have put these parameters in MySQL configuration file
cat /etc/my.cnf
[mysqld]
skip-external-locking
key_buffer = 500M
max_allowed_packet=64M
max_connections = 2000
max_user_connections = 50000
wait_timeout=180
connect_timeout=120
table_open_cache=4096
table_definition_cache=4096
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_size = 190M
query_cache_limit = 3M
open_files_limit=10000
log_error = /var/log/mysql/error.log
default-storage-engine=MyISAM
[mysqld]
log-bin=mysql-bin
binlog-do-db=******
server-id=1
[mysql]
no-auto-rehash
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
replicate-do-db=*****
auto_increment_increment = 2
auto_increment_offset = 1
replicate-same-server-id = 0
slave-skip-errors=all
[mysqld]
slave-skip-errors=1062
skip-slave-start
query_cache_type=1
[mysqld]
innodb_lock_wait_timeout=120
slave_compressed_protocol=1
query_cache_size = 190M
The QC is inefficient when it is big; limit to about 50M.
slave-skip-errors=1062
This is a flavor of "sweeping bugs under the rug".
default-storage-engine=MyISAM
passé.
key_buffer = 500M
If you do stick with MyISAM, and this server is running just MySQL, then use 1000M.
server-id=1
Make sure each server has a different value.
But that is only configuration. If you have slow queries, let's see them and try to improve them.

mysqld intermittent restarts under load

To start with, I'm relatively new to web development.
Under reasonable load (500-700 Q/s) the server is restarting frequently (sometimes every hour), and I get the follow in my syslog each time it happens. I don't get any output to mysql.err or mysql/error.log
This is my first real mysql setup, so I'm sure there is lots that could be improved, but I'm surprised that the server is actually going down so often. The machine has 4GB of ram. Thanks for any suggestions or help!
Ubuntu 10.04, mysql is from the lucid packages.
Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (x86_64) using readline 6.1
Oct 10 01:45:33 host init: mysql main process (1199) terminated with status 1
Oct 10 01:45:33 host init: mysql main process ended, respawning
Oct 10 01:45:42 host /etc/mysql/debian-start[1644]: Upgrading MySQL tables if necessary.
Oct 10 01:45:42 host /etc/mysql/debian-start[1648]: /usr/bin/mysql_upgrade: the '--basedir' option is always ignored
Oct 10 01:45:42 host /etc/mysql/debian-start[1648]: Looking for 'mysql' as: /usr/bin/mysql
Oct 10 01:45:42 host /etc/mysql/debian-start[1648]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
Oct 10 01:45:42 host /etc/mysql/debian-start[1648]: This installation of MySQL is already upgraded to 5.1.41, use --force if you still need to run mysql_upgrade
Oct 10 01:45:42 host /etc/mysql/debian-start[1656]: Checking for insecure root accounts.
Oct 10 01:45:43 host /etc/mysql/debian-start[1672]: Triggering myisam-recover for all MyISAM tables
Here's my my.cnf:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld]
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
bind-address = host
back_log = 50
max_connections = 100
max_connect_errors = 10
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = innodb
default-character-set = utf8
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 32M
log-bin=trent-bin
binlog_format=mixed
slow_query_log
long_query_time = 2
server-id = 1
key_buffer_size = 32M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2800M
innodb_data_file_path = ibdata1:100M:autoextend
innodb_file_per_table
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 4M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_flush_method=O_DIRECT
innodb_lock_wait_timeout = 50
ssl-ca=/etc/mysql/cacert.pem
ssl-cert=/etc/mysql/server-cert.pem
ssl-key=/etc/mysql/server-key.pem
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
I have seen mysql behave this way a few times, there are many potential causes.. : to investigatem I would check
1) are there any custom functions that you have written that might be memory leaks? I once saw a median function, custom written on mysql 5, lead to restarts if it was run by two simultaneous queries...
2) if you optimize the tables, does this reduce the restart frequency?
3) are therea ny corrupt tables in the db ?