saytik
@saytik
Веб-разработчик

Как пофиксить медленную запись в БД MySQL?

Сервер выделенный, достаточно мощный. База на SSD. Почему-то низкие показатели на запись. Первым индикатором стали показания битрикс "панель производительности". (про то какой битрикс "чудо" продукт, я в курсе).
7f4e7e557e80449d950b5a61a5946e6b.png

Затем провел несколько тестов.


./mysqltuner.pl
>> MySQLTuner 1.6.10 - Major Hayden
>> Bug reports, feature requests, and downloads at mysqltuner.com
>> Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.73
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +CSV +InnoDB +MRG_MYISAM
[--] Data in MyISAM tables: 81K (Tables: 12)
[--] Data in InnoDB tables: 6G (Tables: 3335)
[!!] Total fragmented tables: 149

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 82d 17h 56m 35s (2 q [0.000 qps], 25M conn, TX: 157B, RX: 115B)
[--] Reads / Writes: 100% / 0%
[--] Binary logging is disabled
[--] Physical Memory : 62.9G
[--] Max MySQL memory : 9.9G
[--] Other process memory: 13.8G
[--] Total buffers: 8.2G global + 24.9M per thread (70 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 9.9G (15.76% of installed RAM)
[OK] Maximum possible memory usage: 9.9G (15.72% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/2)
[!!] Highest connection usage: 100% (71/70)
[OK] Aborted connections: 0.51% (130070/25606836)
[OK] Query cache efficiency: 100.0% (457M cached / 457M selects)
[!!] Query cache prunes per day: 1965813
[OK] No Sort requiring temporary tables
[OK] No joins without indexes
[OK] No tmp tables created on disk
[OK] Thread cache hit rate: 99% (10K created / 25M connections)
[OK] Table cache hit rate: 100% (9K open / 0 opened)
[OK] Open file limit used: 0% (124/28K)
[OK] Table locks acquired immediately: 99% (3B immediate / 3B locks)

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.3% (24M used / 134M cache)
[OK] Key buffer size / total MyISAM indexes: 128.0M/138.0K
[OK] Read Key buffer hit rate: 100.0% (1B cached / 30 reads)
[OK] Write Key buffer hit rate: 100.0% (499M cached / 24 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[OK] InnoDB buffer pool / data size: 7.8G/6.6G
[OK] InnoDB Used buffer: 87.81% (449606 used/ 512000 total)
[OK] InnoDB Read buffer efficiency: 100.00% (4784039165461 hits/ 4784039252171 total)
[!!] InnoDB Write Log efficiency: 13.3% (16130866 hits/ 121277476 total)
[!!] InnoDB log waits: 0.00% (7 waits / 105146610 writes)

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

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

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
Enable the slow query log to troubleshoot bad queries
Reduce or eliminate persistent connections to reduce connection usage
Increasing the query_cache size over 128M may reduce performance
Variables to adjust:
max_connections (> 70)
wait_timeout (< 28800)
interactive_timeout (< 28800)
query_cache_size (> 128M) [see warning above]
innodb_log_buffer_size (>= 1M)



mysqlslap -u root -p --auto-generate-sql
Enter password:
Benchmark
Average number of seconds to run all queries: 0.481 seconds
Minimum number of seconds to run all queries: 0.481 seconds
Maximum number of seconds to run all queries: 0.481 seconds
Number of clients running queries: 1
Average number of queries per client: 0


mysqlslap -u root -p --auto-generate-sql --concurrency 20 --iterations 10 --engine=innodb -vvv
Enter password:
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 6.309 seconds
Minimum number of seconds to run all queries: 1.907 seconds
Maximum number of seconds to run all queries: 14.787 seconds
Number of clients running queries: 20
Average number of queries per client: 0


Подскажите где копать?
  • Вопрос задан
  • 7539 просмотров
Решения вопроса 1
saytik
@saytik Автор вопроса
Веб-разработчик
Нашел решение проблемы: dmitro.pro/fixes/1%D1%81-%D0%B1%D0%B8%D1%82%D1%80%...

В итоге фикс в my.cnf:

innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT


А для повышения показателей процессора, поставил OPCache вместо APC:
jlpMmbz.png
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 4
Sanasol
@Sanasol
нельзя просто так взять и загуглить ошибку
Я бы не стал смотреть на такой эталон.
Во-первых, цифры просто нереальные для одного mysql-сервера. Хотя зависит от запросов. Но запись 5к в секунду это как бы овердохуя.

Во-вторых, тесты у битрикса мягко говоря не очень.
Ну а собственно как он считает в вашем случае это количество вообще непонятно. Может быть как рейтинг производительности по ссылке выше, тогда это вообще бред полный. Так мало не может быть даже на дефолт настройке на VPS сервере.
Ответ написан
@neol
Оценка процессора 2.7 на выделенном сервере… Если сервер не на атоме, то проверьте настройки энергосбережения. Возможно стоит перевести cpu governor в performance и результаты теста резко улучшатся.
Ответ написан
ThunderCat
@ThunderCat Куратор тега MySQL
{PHP, MySql, HTML, JS, CSS} developer
тут немного почитать, ну и тут есть по теме, думаю разберетесь.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы