月50万PVほどあるメディアサイトを運営しております。
Topページには画像を20枚程使用しており、画像サイズもでかいため、完全に読み込むまでには6秒程かかります。(遅延ロードのため、3秒ほどでページは描画されます。)
メモリ改善のため、余計なプラグインを削除したり、一つ一つプラグインを削除して、検証の後、問題なさそうなプラグインのみ残しております。(8プラグイン程使用しております。)
しかし、これでも月に1回ほどサーバーが落ちてしまい、ログを見ると、メモリエラーになります。
$ php -i | grep memory_limit memory_limit => 128M => 128M
こちらのmemory_limitをさげてしまうと、メモリエラーの発生割合を減らせられるのかもしれませんが、その分、ページロードが遅くなりそうなため、このままにしております。
わからない点は次の通りです。
1, そもそも月50万PV(今後も増やしたい)に対して、メモリ4GBが少なすぎるのでしょうか?
2, 他にメモリのチューニングをするためにできることはありますでしょうか?
3, 1ページに画像を20枚ほど使用しているため、仮に半分に減らすだけでも効果があるようでしたら、ページを複数に分けるなどして対応しようかと思っております。
4, AWSのEC2でメモリ8GB以上のプランを選ぶととたんに値段が上がるため、他のレンタルサーバーも含め検討しております。
以下記事等をみていると、他のサーバー会社の方が値段が圧倒的にやすいのですが、EC2サーバーの活用の仕方を間違っているのでしょうか?(ELBは導入しているものの、複数台にスケールできるようにした方が後のことも考えて良いのでしょうか?)
https://bazubu.com/how-to-choose-wp-server-22864.html
宜しくお願い致します。
--
ちなみに4GBあるメモリのうち、常に72%程のメモリの使用量が発生しているため、アクセスが集中したときに、
メモリエラーでサーバーダウンしてしまいます。
追記
php -v PHP 5.6.30 (cli) (built: Mar 8 2017 00:17:28)
WebサーバーはApatcheを使っております。
また、httpd.confのファイルになります。
ServerRoot "/etc/httpd" Listen 80 Include conf.modules.d/*.conf User apache Group apache ServerAdmin root@localhost <Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "/var/www/html" <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> <Directory "/var/www/html"> Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html </IfModule> # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <Files ".ht*"> Require all denied </Files> # # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here. # ErrorLog "logs/error_log" # # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule> <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig /etc/mime.types # # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz # # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi # For type maps (negotiated resources): #AddHandler type-map var # # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> # # Specify a default charset for all content served; this enables # interpretation of all content as UTF-8 by default. To use the # default browser choice (ISO-8859-1), or to allow the META tags # in HTML content to override this choice, comment out this # directive: # AddDefaultCharset UTF-8 <IfModule mime_magic_module> # # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # MIMEMagicFile conf/magic </IfModule> # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # # # EnableMMAP and EnableSendfile: On systems that support it, # memory-mapping or the sendfile syscall may be used to deliver # files. This usually improves server performance, but must # be turned off when serving from networked-mounted # filesystems or if support for these functions is otherwise # broken on your system. # Defaults if commented: EnableMMAP On, EnableSendfile Off # #EnableMMAP off EnableSendfile on # Supplemental configuration # # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf LoadModule rewrite_module modules/mod_rewrite.so
top -a でメモリ使用量を調べた際の結果
一番重いTopページにアクセスした際の結果です。
2858 apache 20 0 569m 94m 16m S 0.0 2.4 0:01.77 httpd 2775 apache 20 0 568m 92m 16m S 0.0 2.3 0:04.49 httpd 2698 apache 20 0 567m 92m 16m S 0.0 2.3 0:03.06 httpd 2772 apache 20 0 566m 91m 16m S 0.0 2.3 0:02.78 httpd 2761 apache 20 0 741m 73m 16m S 0.0 1.9 0:01.24 httpd 2868 apache 20 0 549m 73m 16m S 0.0 1.9 0:01.22 httpd 2903 apache 20 0 549m 73m 16m S 0.0 1.9 0:01.25 httpd 2896 apache 20 0 452m 56m 12m S 0.0 1.4 0:00.45 httpd 2811 mysql 20 0 539m 46m 9632 S 0.0 1.2 0:24.12 mysqld 2884 root 20 0 406m 22m 15m S 0.0 0.6 0:08.41 httpd 2804 apache 20 0 414m 15m 8716 S 0.0 0.4 0:00.02 httpd 2893 apache 20 0 414m 15m 8584 S 0.0 0.4 0:00.01 httpd 2518 root 20 0 117m 7184 6084 S 0.0 0.2 0:00.00 sshd
その他
昨日から今日にかけて経過観察していると、
常時のメモリ使用量がまたふえて現在は83%を推移しております。
sarコマンドを使ってみておりますが、昨日が72%だったことをふまえると、底上げしつつあるため、
記事の配信数に影響するのではと思いました。
記事は1日2記事ほど執筆しております。