サーバーのパフォーマンスが遅い

サーバーのパフォーマンスが遅い

遅いサーバー パフォーマンスのボトルネックを見つけるのに苦労しています。fastcgi キャッシュと完全な HTML cloudflare キャッシュを備えた単一の wordpress サイト (オンライン ユーザー数 10 ~ 40)。キャッシュのおかげで、訪問者にとってはサイトのパフォーマンスは良好ですが、ログインしたユーザーのページ読み込み時間は 1 ~ 10 秒です。デバッグにはクエリ モニターを使用します。サイトは 1 コア、2 GB RAM のマシンではるかに良好に動作していました。原因がわかりません。どんな助けでも大歓迎です。ありがとうございます。

単一投稿の読み込みが遅い例:クエリモニターの読み込みが遅い

適切な単一投稿ロードの例:クエリモニターの高速ロード

I'm running KVM 2 Cores @ 3.50+ GHz 8 GB Memory 160 GB SSD.
    nginx version: nginx/1.14.1
    PHP 7.4.22 (cli) + memcached 
    10.6.3-MariaDB

root@localhost:~# free -m
              total        used        free      shared  buff/cache   available
Mem:           7987        1546         195         121        6245        6020
Swap:          8191         268        7923

PHP-FPM 設定: (増やしてみましたが、変化なし)

pm = dynamic
pm.max_children = 100
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 8
pm.max_requests = 200

データベース

Server Version  5.5.5
Extension   mysqli
Client Version  70422 (7.4.22)
innodb_buffer_pool_size 2147483648 (~2 GB)
key_buffer_size 134217728 (~128 MB)
max_allowed_packet  16777216 (~16 MB)
max_connections 151
query_cache_limit   1048576 (~1 MB)
query_cache_size    67108864 (~64 MB)
query_cache_type    ON

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 2048;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    types_hash_max_size 2048;
    # server_tokens off;
    proxy_buffering on;
    access_log off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    # access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##
    
    ################## caches ###############
    proxy_cache_path  /etc/nginx/static-cache levels=1:2 keys_zone=s3_cache:200m max_size=1800G inactive=10y use_temp_path=off;

    fastcgi_cache_path /etc/nginx/fastcgi-cache levels=1:2 keys_zone=phpcache:50m max_size=1g inactive=7d use_temp_path=off;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";

    #############################
    client_max_body_size 2000M;



    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

nginx サーバーの設定

# pass the PHP scripts to FastCGI server
location ~ \.php$ {
        try_files $uri =404;
       fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
            fastcgi_read_timeout 150;
        fastcgi_buffers 16 16k; 
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache phpcache;
fastcgi_cache_valid 200 301 302 60m;
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
add_header X-FastCGI-Cache $upstream_cache_status;

}

編集: Wordpress の外でいくつかテストをしました。for サイクルで 100000 個のランダムな文字列を生成します。

    <?php $start_time = microtime(true); ?>

<?php        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL);
        
    # define("WP_USE_THEMES", false);
    #require_once("/var/www/server/wp-blog-header.php");


        for($i = 0; $i < 100000; $i++){
            generateRandomString(2);
        }


function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

        ?>

This page was generated in <?php echo(number_format(microtime(true) - $start_time, 2)); ?>

結果はほとんど同じです。リクエストによっては 0.1 秒で完了するものもあれば、5 秒かかるものもあります。PHP は正常に動作しているようです。おそらく、nginx との接続よりも遅くなるのは php-fpm でしょうか?

答え1

問題は解決したようです。VPS プロバイダーに問い合わせたところ、サーバーがサーマル スロットリングを起こしており、この問題を解決するとのことでした。これで、一部のリクエストが遅い理由がわかりました。

関連情報