首页 技术 正文
技术 2022年11月15日
0 收藏 973 点赞 3,550 浏览 1884 个字

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

考虑到下面的几个方面:

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

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

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

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

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

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

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

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

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

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

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

 location /status {
stub_status on;
}

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

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

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

 This is ApacheBench, Version 2.3 <$Revision:  $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.210.237.222 (be patient)
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Finished requests Server Software: nginx/1.4.
Server Hostname: 10.210.237.222
Server Port: Document Path: /index.html
Document Length: bytes Concurrency Level:
Time taken for tests: 16.154 seconds
Complete requests:
Failed requests:
(Connect: , Receive: , Length: , Exceptions: )
Write errors:
Non-2xx responses:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 3095.22 [#/sec] (mean)
Time per request: 323.079 [ms] (mean)
Time per request: 0.323 [ms] (mean, across all concurrent requests)
Transfer rate: 2551.24 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 475.5
Processing: 762.3
Waiting: 739.6
Total: 931.7 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request)

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

 Active connections:
server accepts handled requests Reading: Writing: Waiting:

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

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

下一篇: kill杀死进程
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893