zoukankan      html  css  js  c++  java
  • 关于搭建一个高性能网站的服务器的架设思路以及nginx测试的并发

    对于高性能网站的架设,主要就是请求量大,那我们该如何进行支撑?

    考虑到下面的几个方面:

    1.要减少请求,那对于开发人员来说,网站的css文件进行合并,背景图片也要合并,一般都是请求一张比较大的图片,然后在进行分割,然后就是减少mysql的查询。

    2.对于前端的nginx,我们使用nginx的expire参数,利用浏览器的缓存等,来减少后端服务器的查询。

    3.对于前端的静态的文件,我们使用cdn来进行分发请求。

    那到了最后一步,不可避免的请求-----我们呢可以使用服务器集群+负载均衡来支撑。

    所以在前面三个阶段进行简单的优化后,到了最后一步,我们呢就不要再考虑减少请求这个方向了,而是思考如何更好的响应高并发的请求了

    有一个大的认识----既然响应是不可避免的,我们要做的就是把工作的内容“平均”分给每台服务器上。

    最理想的状态是,每台服务器的性能呢都能被充分的利用。

    接下来测试一下nginx的一个并发量和它的一些调优:

    首先编译的时候,我们需要加上一个nginx的统计模块,

    1 ./configure --prefix=/usr/local/nginx --add-module=/root/src/ngx_http_consistent_hash-master/  --with-http_stub_status_module

    在配置文件中,我们可以这样:

    1 location /status {
    2     stub_status on;
    3 }

    我们在另一台机器上,使用ab进行压测:

    1 /data1/http2/bin/ab -c 2000 -n 50000 http://10.210.237.222/index.html

    接下来看一下最终的结果:

     1 This is ApacheBench, Version 2.3 <$Revision: 655654 $>
     2 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
     3 Licensed to The Apache Software Foundation, http://www.apache.org/
     4 
     5 Benchmarking 10.210.237.222 (be patient)
     6 Completed 5000 requests
     7 Completed 10000 requests
     8 Completed 15000 requests
     9 Completed 20000 requests
    10 Completed 25000 requests
    11 Completed 30000 requests
    12 Completed 35000 requests
    13 Completed 40000 requests
    14 Completed 45000 requests
    15 Completed 50000 requests
    16 Finished 50000 requests
    17 
    18 
    19 Server Software:        nginx/1.4.7
    20 Server Hostname:        10.210.237.222
    21 Server Port:            80
    22 
    23 Document Path:          /index.html
    24 Document Length:        612 bytes
    25 
    26 Concurrency Level:      1000
    27 Time taken for tests:   16.154 seconds
    28 Complete requests:      50000
    29 Failed requests:        17
    30    (Connect: 0, Receive: 0, Length: 17, Exceptions: 0)
    31 Write errors:           0
    32 Non-2xx responses:      17
    33 Total transferred:      42201629 bytes
    34 HTML transferred:       30592860 bytes
    35 Requests per second:    3095.22 [#/sec] (mean)
    36 Time per request:       323.079 [ms] (mean)
    37 Time per request:       0.323 [ms] (mean, across all concurrent requests)
    38 Transfer rate:          2551.24 [Kbytes/sec] received
    39 
    40 Connection Times (ms)
    41               min  mean[+/-sd] median   max
    42 Connect:        0   98 475.5      5   15000
    43 Processing:     0  153 762.3      6   13230
    44 Waiting:        0  140 739.6      6   13230
    45 Total:          1  251 931.7     12   15000
    46 
    47 Percentage of the requests served within a certain time (ms)
    48   50%     12
    49   66%     18
    50   75%     27
    51   80%     35
    52   90%    511
    53   95%   1237
    54   98%   3242
    55   99%   5450
    56  100%  15000 (longest request)

    上面是一个压测的结果,那我们使用http://10.210.237.222/status观察发现:

    1 Active connections: 343 
    2 server accepts handled requests
    3  160843 160843 160883 
    4 Reading: 0 Writing: 221 Waiting: 122 

    情况并不如人意,因此我们需要进行对nginx进行调优。

    好然后我们接下来对nginx进行调优,最终能达到1W的并发!

  • 相关阅读:
    Sql Server 2008卸载后再次安装一直报错
    listbox 报错 Cannot have multiple items selected when the SelectionMode is Single.
    Sql Server 2008修改Sa密码
    学习正则表达式
    Sql Server 查询第30条数据到第40条记录数
    Sql Server 复制表
    Sql 常见面试题
    Sql Server 简单查询 异步服务器更新语句
    jQuery stop()用法以及案例展示
    CSS3打造不断旋转的CD封面
  • 原文地址:https://www.cnblogs.com/shangzekai/p/4689142.html
Copyright © 2011-2022 走看看