質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Q&A

2回答

882閲覧

4GBのWordpress用サーバーでメモリエラーが月に1回ほど発生します。画像を多く使っているメディアサイトなんですが、画像の数や大きさ等は影響が大きいでしょうか?

kinoshitaaa

総合スコア11

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

0グッド

0クリップ

投稿2018/02/08 13:54

編集2022/01/12 10:55

月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記事ほど執筆しております。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CodeLab

2018/02/08 14:46

Webサーバーの問題かとおもいますので、使っているソフト(通常はアパッチかnginxかとおもいますが)と設定値を明記した方が良いかもしれません。
kinoshitaaa

2018/02/08 14:54

ありがとうございます。追記致しました。
guest

回答2

0

コメントより、画像は別サーバーで管理しているということであれば、画像が原因ということは考えにくいです。
Wordpressをお使いということなので、おそらくハッキング対策が不十分なのかと思います。

ログを見てみないとわかりませんが、十中八九、ブルートフォースアタックを受けているのだと思います。
一度、アパッチのアクセスログ等をご覧になってみることをお勧めします。

特に多いのはxmlrpcを経由したもので、詳細はお調べになっていただければと思いますが、特に不要ということでしたら機能を無効にすることをお勧めします。

そのほかにも最低限やっておいた方がいい設定がいくつかあります。

参考
WordPressのセキュリティ対策まとめ 2017
https://ahalog.tdesignworks.net/cms/wordpress/wordpress-security-2017/

投稿2018/02/09 01:49

CodeLab

総合スコア1939

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

画像を動的に変換してないなら、S3に保存するプラグインがあるのでそういうのを使ってS3に画像を持っていきます。

画像の転送が減るので、サーバーの負荷はさがります。

投稿2018/02/08 14:58

kero1209

総合スコア431

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kinoshitaaa

2018/02/08 15:03

ご回答有難う御座います。 質問文に記載できておらず大変恐縮ですが、S3には画像をあげており、Cloudfrontで画像もキャッシュしております。
kero1209

2018/02/08 15:08

S3に画像を上げているのなら、画像のアクセスではWordpressには負荷かからないのではないでしょうか。 DBの負荷が高くないでしょうか。関連ページを取るとか何か重いプラグイン入れてませんか?
kinoshitaaa

2018/02/08 15:58 編集

Topページでは、各カテゴリ毎の新着記事を取得しているため、もしかするとDB負荷が大きいのかもしれません。 MySQLを使用しているのですが、このような場合、どのように調べたら宜しいでしょうか?
kinoshitaaa

2018/02/08 16:19

実行した時時点のMySQLの負荷についてはコマンドを実行することで取得できるかと思いますが、Topページをアクセスしたときに発行したSQLの総数でどれくらいメモリを消費するのかというのを調査する方法がよくわかりません。調べているのですが、上手くヒットせず。
kero1209

2018/02/08 22:06

Serverでtop コマンドを実行して中のCPU負荷とメモリーの使用量を見れば一番負荷をかけているのがそれぞれ何かがわかるかと思います。S3から画像を配信しているのに、表示に数秒かかるというのがありえないほど遅いです。 後は、mysql を使っているのなら、slowquery の設定を変更して時間のかかっているクエリーをログに書くようにして調査する方法もあります。
kinoshitaaa

2018/02/09 02:02

ありがとうございます。 top -a でTopページアクセス時のMySQLのメモリの増加率を見ていましたが、さほど多くありませんでした。(むしろapacheの方が、2倍程メモリをとっておりました。詳細は、後ほど質問本文に追記します。) slowqueryも試してみます。
kinoshitaaa

2018/02/09 02:08

また、昨日から今日にかけて経過観察していると、 常時のメモリ使用量がまたふえて現在は83%を推移しております。 sarコマンドを使ってみておりますが、昨日が72%だったことをふまえると、底上げしつつあるため、 記事の配信数に影響するのではと思いました。 記事は1日2記事ほど執筆しております。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問