数字海洋水滴的高内存使用率

ada*_*m78 6 ram memory-management laravel digital-ocean mysql-8.0

我有一个 Laravel 应用程序,已安装在运行 ubuntu 20.4、nginx、MySQL 8 和 php 7.4 的 1GB 标准 Droplet 上

该应用程序还没有运行,我注意到它已经使用了超过 50% 的内存。昨天它使用了 80%,系统重新启动后,它恢复到使用大约 60% 的内存使用率。

下面是当前高内存运行进程的快照。对于 Laravel 应用程序来说,这种内存使用水平是否正常,因为它甚至不是实时的,即负载有限?

top - 19:41:00 up  3:46,  1 user,  load average: 0.08, 0.04, 0.01
Tasks: 101 total,   1 running, 100 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.7 sy,  0.0 ni, 98.7 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :    981.3 total,     90.6 free,    601.4 used,    289.3 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.    212.2 avail Mem


PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
815 mysql     20   0 1305900 417008  13352 S   0.7  41.5   1:32.39 mysqld
2257 www-data  20   0  245988  44992  30180 S   0.0   4.5   0:04.67 php-fpm7.4
2265 www-data  20   0  243700  42204  29572 S   0.0   4.2   0:04.41 php-fpm7.4
2259 www-data  20   0  243960  42104  30380 S   0.0   4.2   0:04.44 php-fpm7.4
988 root      20   0  125160  36188  10604 S   0.3   3.6   0:09.89 php
388 root      19  -1   84404  35116  33932 S   0.0   3.5   0:01.14 systemd-journ+
741 root      20   0  627300  20936   6656 S   0.0   2.1   0:02.11 snapd
738 root      20   0  238392  18588  12624 S   0.0   1.8   0:00.83 php-fpm7.4
743 root      20   0   31348  18344   3844 S   0.0   1.8   0:02.75 supervisord
544 root      rt   0  280180  17976   8184 S   0.0   1.8   0:00.90 multipathd
825 root      20   0  108036  15376   7732 S   0.0   1.5   0:00.10 unattended-up+
736 root      20   0   29220  13200   5544 S   0.0   1.3   0:00.11 networkd-disp+
726 do-agent  20   0  559436  12120   6588 S   0.0   1.2   0:01.78 do-agent
  1 root      20   0  101964  11124   8024 S   0.0   1.1   0:02.52 systemd
623 systemd+  20   0   23912  10488   6484 S   0.0   1.0   0:00.42 systemd-resol+
778 www-data  20   0   71004   9964   5240 S   0.0   1.0   0:02.43 nginx
Run Code Online (Sandbox Code Playgroud)

我担心的是,一旦应用程序上线并且负载增加,更多的数据库连接将会耗尽内存。我知道我可以调整液滴大小并增加内存或设置一些交换空间,但是对于未使用的应用程序来说,这样的内存使用量是否正常?

如何优化mysql、niginx、php等高内存使用进程?Mysql8 似乎是占用所有内存的罪魁祸首。以下是我的mysql设置:

#
# The MySQL database server configuration file.
#
# 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

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld]
#
# * Basic Settings
#
user            = mysql
# pid-file      = /var/run/mysqld/mysqld.pid
# socket        = /var/run/mysqld/mysqld.sock
# port          = 3306
# datadir       = /var/lib/mysql


# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system- variables.html#sysvar_tmpdir
# tmpdir                = /tmp
#
# 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_size         = 16M
# max_allowed_packet    = 64M
# thread_stack          = 256K

# thread_cache_size       = -1

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP

# max_connections        = 151

# table_open_cache       = 4000

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file        = /var/log/mysql/query.log
# general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log                = 1
# slow_query_log_file   = /var/log/mysql/mysql-slow.log
# long_query_time = 2
# 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
# binlog_expire_logs_seconds    = 2592000
max_binlog_size   = 100M
# binlog_do_db          = include_database_name
# binlog_ignore_db      = include_database_name   
Run Code Online (Sandbox Code Playgroud)

任何提示和建议都非常感谢,因为这是我第一次使用 vps。

小智 0

有时mysql事务没有关闭,所以,你需要注意这一点。您可以show full processlist在 MySql cli 中使用 , 列出所有进程。另外,检查您的交易在使用时是否正确关闭DB::beginTransaction(这是DB::befinTrasaction在之前使用的一个好方法try-catch