Joe*_*Joe 2 mysql ubuntu performance memory cpu-usage
我正在使用 ubuntu 服务器 12.04 x64。服务器通过 apache 网络服务器(它的轻量级接口)接收大量对 mysql 的请求。从 mysql 统计信息中,我看到从早上 8 点到晚上 9 点大约有 250 个查询/秒。晚上服务器几乎不使用。RAM 主要由 mysql 使用(根据 mysqloptimizer 最大 MySQL ram 使用量为 25GB)。Top 证实了这一点 - mysql 使用了大约 77% 的 RAM。
数据库大小约为 20GB。一张受到最严重攻击的表有大约 1-2 百万条记录(主要是来自几个表的 id 字段加上一些 smallints 计数器)。
我附上了说明我感兴趣的部分的图像(第二个内存图像显示了服务器重启后的内存行为)。
在看 munin 时,我提出了几个问题:
为什么在内存使用中apps
内存几乎永远不会下降?例如在晚上服务器上没有流量时,它不应该减少吗?
以某种方式调整它为缓存提供更多内存空间不是更好吗?
RAM已满时,为什么CPU使用率如此之低?
不活跃的记忆水平也在上升,这让我有点担心。
出现这些问题是因为偶尔流量会在短时间内显着上升,并且在那些时刻服务器没有响应大量请求。但在那些时刻,RAM/CPU 甚至磁盘延迟并没有增加太多,也许只是一点点。这些流量上升是不可避免的,但我不确定用 stringer one 替换服务器是否会做到这一点,或者可能只放置更多 RAM(因为 CPU 使用率最低)?
如果这个问题无法回答 - 抱歉。
编辑: # # MySQL 数据库服务器配置文件。# # 您可以将其复制到以下选项之一:# - "/etc/mysql/my.cnf" 设置全局选项,# - "~/.my.cnf" 设置用户特定选项。# # 可以使用程序支持的所有长选项。# 使用 --help 运行程序以获取可用选项列表,并使用 # --print-defaults 查看它实际理解和使用的选项。# # 有关解释,请参见 # 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
#
# * Fine Tuning
#
key_buffer = 64M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 64
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
max_connections = 400
table_cache = 6000
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 32M
#
# * 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 logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
slow_query_log = 0
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 20
#log-queries-not-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
innodb_file_per_table
innodb_flush_method=O_DIRECT
innodb_log_file_size = 512M
innodb_buffer_pool_size = 24G
bulk_insert_buffer_size = 256M
innodb_open_files = 6000
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_file_io_threads = 4
thread_cache_size = 64
thread_concurrency = 12
query_cache_size = 64M
query_cache_limit = 2M
max_sp_recursion_depth = 50
thread_stack = 384K
tmp_table_size = 64M
max_heap_table_size = 64M
key_buffer_size = 32M
event_scheduler = ON
lower_case_table_names = 1
[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/
Run Code Online (Sandbox Code Playgroud)
数据库(好吧,其中 99%)缓存了所有可以缓存的内容。缓存很好。它使事情进展得更快。您希望您的数据库服务器用尽它所能消耗的所有内存,除非必须,否则永远不要释放它。
它不会缓存东西,除非你要求它(比如在查询中)。也许有工具可以制作 MySQL 预缓存数据,但我不知道。较新的数据库产品开始获得大量内存功能,您可以选择某些数据始终存在于内存中。
CPU 使用率与 RAM 使用率无关。您的查询可能非常轻量级,例如只有细粒度的 SELECTS 每次都会命中索引。换句话说,数据库将为您提供驻留在 RAM 中的缓存数据,因此 CPU 工作很少(例如调度 I/O 以从磁盘检索和处理数据)。
对我来说,这看起来是一个非常健康和快速执行的数据库。真的没有任何问题。如果您有空闲内存,那么它只是意味着数据库不需要缓存更多数据,因为它永远不会被请求。
编辑:您已将 InnoDB 池限制为 24GB,这非常好,因为您的数据库是 20GB。如果数据库增加,则注意增加缓冲池大小。您还提到您担心可用内存的减少 - 只有在数据库以外的其他进程正在消耗它时,这才应该是一个问题。数据库服务器的增长不会超出您的限制。
归档时间: |
|
查看次数: |
3014 次 |
最近记录: |