我怎样才能找到瓶颈?

我怎样才能找到瓶颈?

我有一个EC2 m1.large Ubuntu 13.04实例运行PHP 5.5PHP-FPMNGINX。缓存由Elastic Cache使用处理Redis,数据库连接到单独的m1.large MongoDB服务器。内容可以相当动态,因为新闻源可以是动态的,我的服务器由 iOS 应用程序使用。

我正在进行围攻测试,siege -d5 -c150如果我只进行 1 次围攻,我看到的响应时间不到 1 秒。如果我添加另一台服务器来执行另一项操作,siege -d5 -c150我的响应时间将上升到 9-15 秒`

我对服务器设置还很陌生,但有些东西告诉我,如果我的服务器的 CPU 负载始终平均为 40-50%,并且消耗的内存不到 1GB。在拥有如此多的可用资源的情况下,我不应该看到 10++ 秒的延迟吗?

我的瓶颈可能是什么或者我怎样才能找到它?

在此处输入图片描述 在此处输入图片描述

/etc/sysctl.conf 是

 net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 0
net.ipv4.ip_local_port_range = 2000 65000
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_max_syn_backlog = 3240000
net.core.somaxconn = 3240000
net.ipv4.tcp_max_tw_buckets = 1440000
kernel.shmmax = 1073741824
net.ipv4.tcp_rmem = 4096 25165824 25165824
net.core.rmem_max = 25165824
net.core.rmem_default = 25165824
net.ipv4.tcp_wmem = 4096 65536 25165824
net.core.wmem_max = 25165824
net.core.wmem_default = 65536
net.core.optmem_max = 25165824
net.ipv4.tcp_mem = 1474560    1966080    2949120

/etc/php5/fpm/pool.d/www.conf

pm = dynamic
pm.max_children = 32
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.max_requests = 150

/etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 32768;
    multi_accept on;
    use epoll;
}

http {

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

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 15;

    server_tokens off;

    # allow the server to close the connection after a client stops responding. Frees up socket-associated memory.
    reset_timedout_connection on;


    # send the client a "request timed out" if the body is not loaded by this time. Default 60.
    client_body_timeout 10;

    # If the client stops reading data, free up the stale client connection after this much time. Default 60.
    send_timeout 10;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "MSIE [1-6]";

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    server {
        listen 80 default;
        root /var/www/;
        index index.php index.htm index.html;

        # php-fpm bridge
        # execute all .php files with php-fpm
           location ~ .php$ {
              fastcgi_pass   unix:/var/run/php5-fpm.sock;
              fastcgi_index  index.php;
              fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
              fastcgi_buffer_size 128k;
              fastcgi_buffers 256  16k;
              fastcgi_busy_buffers_size 256k;
              fastcgi_temp_file_write_size 256k;
              include fastcgi_params;
           }
    }
}

围攻结果

ransactions:                    1265 hits
Availability:                  99.68 %
Elapsed time:                1196.10 secs
Data transferred:              21.30 MB
Response time:                 11.48 secs
Transaction rate:               1.06 trans/sec
Throughput:                     0.02 MB/sec
Concurrency:                   12.14
Successful transactions:        1265
Failed transactions:               4
Longest transaction:           26.88
Shortest transaction:           0.00

答案1

  • 单独测试每个组件,然后一起测试所有组件。
  • 对于每个独立测试,请确保只测试纯性能,例如在 nginx 中执行

    location /perftest/ {
        return 200;
    }
    
  • 当你确定每个组件都调整好了之后,开始组合它们并再次测试

顺便问一下,您在 mongo 上使用了正确的索引吗?

相关内容