谈谈关于老人带新人的问题:
在一般的公司进去之后,就会分配一个人来带你这个菜B,那么怎么带比较好呢?一般的情况就是给你一些文档,然后开始做吧,出现问题ask,ask again,老人会告诉你步骤,然后一步一步去做,对于成熟的企业来说,如果都是一些固定的步骤,那么在这个方面,你不会有任何收获,你所做的只是指定的步骤,你对这些东西的背后运行的原理依旧是一窍不通,当你离开之后,你会发现,你并没有懂多少。。。。
感觉好的方式就是:说原理,讲架构,你提出新的想法,新的疑问,新的思路,让老人也会有收获,让你也有所提高,否则,新人只是一味的获取,那么必然只是拖累老人的步伐,老人需要你的原因,只是因为一些僵化的东西,僵化步骤不再愿意重复,所以需要你,而你最主要的作用,是提出新的想法,来改进原有僵化的步骤,提出改进,让生活变得更加美好!!!!
nginx单独分出静态资源服务器的主要目的是为了动静分离,从而提高网站的性能。
1、静态资源配置
在将nginx作为静态资源服务器的时候,简单配置如下所示:
location / {
root /imagedata; (静态资源根目录)
index index.html index.htm;
}
location ~* \.(jpg|gif|jpeg|png|bmp|swf|curl|exe|cab)$ {
root /imagedata/image/;
expires 31536000s; (过期时间为1年)
}
location ~* \.(ico|css|js|txt)$ {
root /imagedata/static/;
expires 259200s;(过期时间三天)
}
location ~* \.kel$ {
root /imagedata/kel/; (未设置过期时间)
}
在进行静态资源配置的时候,如上所示,在图片等资源获取的时候,设置过期时间为一年,主要是图片这些资源的改变不是很多;而对于css和js等资源可能变化比较多,从而设置过期时间为3天,最后一个主要是用来测试在加了过期时间之后,会在http的响应头部添加相关的信息,如下所示:
可以看出,在设置了过期时间之后,那么在http的响应头部会添加expires过期时间和cache-control。
在更新了相关静态资源文件之后,还是可以获取最新的资源文件。
2、测试如下
在使用ab测试工具测试如下:
[root@RHAN ~]# ab -n 1000 -c 1000http://172.168.1.78/1.css
Server Software: nginx/1.6.3
Server Hostname: 172.168.1.78
Server Port: 80
Document Path: /1.css
Document Length: 1739282 bytes
Concurrency Level: 1000
Time taken for tests: 27.057 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 1739591000 bytes
HTML transferred: 1739282000 bytes
Requests per second: 36.96 [#/sec] (mean)
Time per request: 27057.232 [ms] (mean)
Time per request: 27.057 [ms] (mean, across all concurrentrequests)
Transfer rate: 62786.15 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 342 1865 901.1 2061 3178
Processing: 23436 24873 979.2 24711 26608
Waiting: 234 1613 936.2 1417 3220
Total: 26611 26738 80.6 26737 26952
Percentage of the requests served within a certaintime (ms)
50% 26737
66% 26778
75% 26803
80% 26818
90% 26852
95% 26866
98% 26877
99% 26929
100% 26952 (longest request)
3、优化后
优化后的结果如下:
[root@RHAN ~]# ab -n 1000 -c 1000http://172.168.1.78/1.css
Server Software: nginx/1.6.3
Server Hostname: 172.168.1.78
Server Port: 80
Document Path: /1.css
Document Length: 1739282 bytes
Concurrency Level: 1000
Time taken for tests: 26.759 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 1739591000 bytes
HTML transferred: 1739282000 bytes
Requests per second: 37.37 [#/sec] (mean)
Time per request: 26759.215 [ms] (mean)
Time per request: 26.759 [ms] (mean, across all concurrentrequests)
Transfer rate: 63485.40 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 306 1557 723.1 1395 3265
Processing: 23410 24912 786.0 25066 26289
Waiting: 169 1436 735.4 1604 2722
Total: 26360 26469 68.8 26458 26676
Percentage of the requests served within a certaintime (ms)
50% 26458
66% 26505
75% 26525
80% 26540
90% 26565
95% 26581
98% 26592
99% 26601
100% 26676 (longest request)
优化的具体参数如下:
sendfile on;(开启sendfile从而nginx可以省略拷贝数据到缓冲区内,可以将数据直接进行发送)
sendfile_max_chunk 1m;(最快传输为1m,防止一个快速连接占用了整个worker进程)
tcp_nopush on;(在nginx通过sendfile获取数据块之后在一个包内发送http响应头)
tcp_nodelay on;(解决小的数据包在慢网速的问题,将数据包放在缓冲区内,然后一起发送)
[root@RHANCL conf]# grep somaxconn /etc/sysctl.conf(内核优化,可以处理高流量的网络)
net.core.somaxconn=65535
优化受限于很多条件,大家可以多测试(根据不同的文件大小进行测试)。
[root@RHAN ~]# ab -n 1000 -c 1000http://172.168.1.78/1.css(开启四个CPU,也就是开启四个worker进程处理结果如下,但是在使用top查看的时候,没有进行绑定CPU,使用的参数为)
worker_processes 4;
worker_cpu_affinity 0001 0010 01001000;
测试结果如下:
Server Software: nginx/1.6.3
Server Hostname: 172.168.1.78
Server Port: 80
Document Path: /1.css
Document Length: 1739282 bytes
Concurrency Level: 1000
Time taken for tests: 26.492 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 1739591000 bytes
HTML transferred: 1739282000 bytes
Requests per second: 37.75 [#/sec] (mean)
Time per request: 26492.216 [ms] (mean)
Time per request: 26.492 [ms] (mean, across all concurrentrequests)
Transfer rate: 64125.23 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 251 1621 833.5 1596 3410
Processing: 23077 24706 829.0 24693 26153
Waiting: 189 1191 607.7 1133 2302
Total: 26221 26327 73.3 26317 26487
Percentage of the requests served within a certaintime (ms)
50% 26317
66% 26343
75% 26365
80% 26382
90% 26484
95% 26485
98% 26487
99% 26487
100% 26487 (longest request