Home > Back-end >  How should my my.cnf settings be? Now is very slow
How should my my.cnf settings be? Now is very slow

Time:12-29

I use VestaCP with apache, nginx and Mariadb 10.3 on Debian 10 with 2core CPU and 3GB RAM. main purpose: store on opencart with ~10k products (about 150 tables in SQL). Right now I got very long pauses on searches in the catalog and some marketing queries in db (product sales in perion, etc).

Current My.cnf:

[client]
port=3306
socket=/var/run/mysqld/mysqld.sock

[mysqld_safe]
socket=/var/run/mysqld/mysqld.sock

[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
log_error=/var/log/mysql/error.log

symbolic-links=0
  
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
sort_buffer_size = 2M
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 1M
myisam_sort_buffer_size = 8M

query_cache_type = 1
query_cache_size = 64M
query_cache_limit = 128M
join_buffer_size = 8M
tmp_table_size = 256M
max_heap_table_size = 256M
table_open_cache = 2048
thread_cache_size = 4
innodb_buffer_pool_instances = 1
skip-name-resolve
skip-networking

performance_schema = ON

#innodb_use_native_aio = 0
innodb_file_per_table

max_connections=120
max_user_connections=100
wait_timeout=60
interactive_timeout=50
long_query_time=5

slow_query_log          = /var/log/mysql/mysql-slow.log
long_query_time         = 1


!includedir /etc/mysql/conf.d/

MySQLTuner:

 >>  MySQLTuner 1.7.13 - Major Hayden <[email protected]>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials from Debian maintenance account.
[OK] Currently running supported MySQL version 10.3.36-MariaDB-0 deb10u2
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status:  Aria  CSV  InnoDB  MEMORY  MRG_MyISAM  MyISAM  PERFORMANCE_SCHEMA  SEQUENCE
[--] Data in InnoDB tables: 8.0M (Tables: 40)
[--] Data in MyISAM tables: 223.4M (Tables: 129)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[--] There are 618 basic passwords in the list.

-------- CVE Security Recommendations --------------------------------------------------------------
[OK] NO SECURITY CVE FOUND FOR YOUR VERSION

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 14m 12s (67K q [79.421 qps], 2K conn, TX: 686M, RX: 19M)
[--] Reads / Writes: 99% / 1%
[--] Binary logging is disabled
[--] Physical Memory     : 2.9G
[--] Max MySQL memory    : 2.1G
[--] Other process memory: 142.9M
[--] Total buffers: 624.0M global   11.5M per thread (120 max threads)
[--] P_S Max memory usage: 98M
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 1.9G (63.52% of installed RAM)
[OK] Maximum possible memory usage: 2.1G (70.47% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (10/67K)
[OK] Highest usage of available connections: 85% (102/120)
[!!] Aborted connections: 3.29%  (75/2281)
[--] Skipped name resolution test due to skip_networking=ON in system variables.
[!!] Query cache may be disabled by default due to mutex contention.
[OK] Query cache efficiency: 38.7% (37K cached / 98K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (3 temp sorts / 20K sorts)
[OK] No joins without indexes
[OK] Temporary tables created on disk: 24% (606 on disk / 2K total)
[OK] Thread cache hit rate: 89% (234 created / 2K connections)
[OK] Table cache hit rate: 97% (281 open / 288 opened)
[OK] Open file limit used: 1% (345/32K)
[OK] Table locks acquired immediately: 99% (70K immediate / 70K locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 98.5M
[--] Sys schema isn't installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 2 thread(s).
[--] Using default value is good enough for your version (10.3.36-MariaDB-0 deb10u2)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 38.2% (12M used / 33M cache)
[OK] Key buffer size / total MyISAM indexes: 32.0M/53.7M
[OK] Read Key buffer hit rate: 99.8% (3M cached / 6K reads)
[!!] Write Key buffer hit rate: 83.7% (565 cached / 473 writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 128.0M/8.0M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal 25%
[OK] InnoDB buffer pool instances: 1
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 93.17% (9178 hits/ 9851 total)
[!!] InnoDB Write Log efficiency: 400% (4 hits/ 1 total)
[OK] InnoDB log waits: 0.00% (0 waits / 5 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/1B
[OK] Aria pagecache hit rate: 99.9% (536K cached / 465 reads)

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: MIXED
[--] XA support enabled: ON
[--] Semi synchronous replication Master: OFF
[--] Semi synchronous replication Slave: OFF
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Control warning line(s) into /var/log/mysql/error.log file
    Control error line(s) into /var/log/mysql/error.log file
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Reduce or eliminate unclosed connections and network issues
    Consider installing Sys schema from https://github.com/mysql/mysql-sys
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://dev.mysql.com/doc/refman/8.0/en/innodb-redo-log.html
Variables to adjust:
    query_cache_size (=0)
    query_cache_type (=0)
    innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.

TUNING PRIMER:

 -- MYSQL PERFORMANCE TUNING PRIMER --
      - By: Matthew Montgomery -

MySQL Version 10.3.36-MariaDB-0 deb10u2 x86_64

Uptime = 0 days 0 hrs 27 min 16 sec
Avg. qps = 82.37
Total Questions = 134765
Threads Connected = 2

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/10.3/en/server-system-variables.html

Visit https://github.com/BMDan/tuning-primer.sh for the latest version of
this script, or to suggest improvements.

SLOW QUERIES
The slow query log is NOT enabled.

BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/10.3/en/point-in-time-recovery.html

WORKER THREADS
Current thread_cache_size = 4
Current threads_cached = 3
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 120
Current threads_connected = 1
Historic max_used_connections = 102
The number of used connections is 85% of the configured maximum.
You should raise max_connections

INNODB STATUS
Current InnoDB index space = 832 K
Current InnoDB data space = 7 M
Current InnoDB buffer pool free = 90 %
Current innodb_buffer_pool_size = 128 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 1.38 G
Configured Max Per-thread Buffers : 1.35 G
Configured Max Global Buffers : 240 M
Configured Max Memory Limit : 1.58 G
Physical Memory : 2.91 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 53 M
Current key_buffer_size = 32 M
Key cache miss rate is 1 : 831
Key buffer free ratio = 59 %
Your key_buffer_size seems to be fine

QUERY CACHE
You have query cache enabled.  With many versions of the server, you may see
query cache lock contention, especially if you have more than one core.
Current query_cache_size = 64 M
Current query_cache_used = 16 M
Current query_cache_limit = 128 M
Current Query cache Memory fill ratio = 25.86 %
Current query_cache_min_res_unit = 4 K
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 1 M
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 8.00 M
You have had 2 queries where a join could not use an index properly
join_buffer_size >= 4 M
This is not advised
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.

OPEN FILES LIMIT
Current open_files_limit = 32768 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 2048 tables
Current table_definition_cache = 400 tables
You have a total of 252 tables
You have 286 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 256 M
Current tmp_table_size = 256 M
Of 5806 temp tables, 16% were created on disk
Created disk tmp tables ratio seems fine

TABLE SCANS
Current read_buffer_size = 256 K
Current table scan ratio = 51 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 8205
Your table locking seems to be fine


CodePudding user response:

Enable the slowlog and see what shows up in the slowlog? (use pt-query-digest) More: SlowLog

Change the tables to InnoDB; MyISAM has several ways in which it is less efficient. How much RAM? What is the value of innodb_buffer_pool_size; after changing, set it to 1000M.

Turn off the Query Cache; it is probably doing more to slow things down that speed them up.

(Many of the metrics are useless because of "Up for: 14m 12s" -- it should be at least 24h.)

Swapping is terrible for performance, so let's lower some of the settings that impact RAM.

table_open_cache =  300
max_heap_table_size = 30M
tmp_table_size      = 30M

CodePudding user response:

It looks like you use MyISAM for most tables. I suggest you increase key_buffer_size up to 64M

key_buffer_size = 64M

The root cause of pauses in search and marketing queries might be locking tables during insert operations. Consider migrating all tables to InnoDB.

I'm a founder of Releem - simple MySQL performance monitoring and tuning tool. We'll be honored if you give it a shot.

  • Related