找到web站点对应的应用程序池,“应用程序池” → 找到对应的“应用程序池” → 右键“高级设置...”
一、一般优化方案
1、基本设置
[1] 队列长度: 默认值1000,将原来的队列长度改为 65535。
[2] 启动32位应用程序:默认值false,改为true, 否则安装一些32的组建或32位的php都会出错。
[3] 托管管道模式:integrated 或 classsic(集成/经典)。
2、高级设置
[1] 闲置超时(分钟):默认20分钟,修改设长。
[2] 快速故障防护 → 已启用 :默认true,改为false。
3、解决pep第一次打开pep速度慢
回收间隔时间
使用windows server 2008 r2解决回收假死的问题
打开应用程序池 -> 高级设置 ->在“禁止重叠回收”里选择“true”,这样就有效避免了应用程序池回收假死问题。
二、支持同时10万个请求
通过对iis7的配置进行优化,调整iis7应用池的队列长度,请求数限制,tcpip连接数等方面,从而使web服务器的性能得以提升,保证web访问的访问流畅。
站点碰到如下问题:
error summary:
http error 503.2 - service unavailable
the serverruntime@appconcurrentrequestlimit setting is being exceeded.
detailed error information:
module iis web core
notification beginrequest
handler staticfile
error code 0x00000000
由于之前使用的是默认配置,服务器最多只能处理5000个同时请求,今天下午由于某种情况造成同时请求超过5000,从而出现了上面的错误。
为了避免这样的错误,我们根据相关文档调整了设置,让服务器从设置上支持10万个并发请求。
具体设置如下:
1. 调整iis 7应用程序池队列长度
将原来的队列长度由默认值 1000 改为 65535。当然这里的队列长度你可以根据自己的 访问用户*1.5 来设置,例如:有2000用户,此处就可以设置为3000(3000=2000用户数*1.5)。
2. 调整iis 7的appconcurrentrequestlimit设置
由原来的默认5000改为100000。
[1] 在cmd中执行:
c:\windows\system32\inetsrv\appcmd.exe set config /section:serverruntime /appconcurrentrequestlimit:100000
[2] 在%systemroot%\system32\inetsrv\config\applicationhost.config中可以查看到该设置:
<serverruntime appconcurrentrequestlimit="100000" />
3. 调整machine.config中的processmodel>requestqueuelimit的设置
[1] 单击“开始”,然后单击“运行”,或者 windows + r。
[2] 在“运行”对话框中,键入 notepad %systemroot%\microsoft.net\framework64\v4.0.30319\config\machine.config,然后单击“确定”。(不同的.net版本路径不一样,可以选择你自己当前想设置的.net版本的config)
[3] 找到如下所示的 processmodel 元素:<processmodel autoconfig="true" />
[4] 将 processmodel 元素替换为以下值:<processmodel enable="true" requestqueuelimit="15000" />
[5] 保存并关闭 machine.config 文件。
由原来的默认5000改为100000。
<configuration>
<system.web>
<processmodel enable="true" requestqueuelimit="100000"/>
参考文章:http://technet.microsoft.com/en-us/library/dd425294(office.13).aspx
4. 修改注册表,调整iis 7支持的同时tcpip连接数
由原来的默认5000改为100000,在cmd中执行:
reg add hklm\system\currentcontrolset\services\http\parameters /v maxconnections /t reg_dword /d 100000
或者直接在注册表中找到这个项目修改。
5. 运行命令使用设置生效
net stop http & net start http & iisreset
完成上述5个设置,就可以支持10万个并发请求。
为了方法大家与自己使用,我把上面能用bat操作简单放到一个bat文件里面了。将下面的内容保存为do.bat文件运行就可以了,需要手工的自己操作
#appconcurrentrequestlimit c:\windows\system32\inetsrv\appcmd.exe set config /section:serverruntime /appconcurrentrequestlimit:100000 reg add hklm\system\currentcontrolset\services\http\parameters /v maxconnections /t reg_dword /d 100000 # too long reg add hkey_local_machine\system\currentcontrolset\services\http\parameters /v maxfieldlength /t reg_dword /d 32768 reg add hkey_local_machine\system\currentcontrolset\services\http\parameters /v maxrequestbytes /t reg_dword /d 32768 #更多的可以可以查看这篇文章,手工操作的可以查看这篇文章 start "c:\program files\internet explorer\iexplore.exe" https://www.jb51.net/article/36073.htm
三、支持高并发的iis web服务器常用设置
适用的iis版本:iis 7.0, iis 7.5, iis 8.0
适用的windows server版本:windows server 2008, windows server 2008 r2, windows server 2012
1、应用程序池(application pool)的设置:
[1] general->queue length设置为65535(队列长度所支持的最大值)
[2] process model->idle time-out设置为0(不让应用程序池因为没有请求而回收)
[3] recycling->regular time interval设置为0(禁用应用程序池定期自动回收)
2、.net framework相关设置
[1] 在machine.config中将
< processmodel autoconfig="true" />
改为
<processmodel enable="true" requestqueuelimit="100000"/>
(保存后该设置立即生效)
[2] 打开c:\windows\microsoft.net\framework64\v4.0.30319\config\browsers\default.browser,找到<defaultbrowser id="wml" parentid="default" >,注释<capabilities>部分,然后在命令行中运行aspnet_regbrowsers -i。以解决text/vnd.wap.wml问题。
<defaultbrowser id="wml" parentid="default" > <identification> <header name="accept" match="text/vnd\.wap\.wml│text/hdml" /> <header name="accept" nonmatch="application/xhtml\+xml; profile│application/vnd\.wap\.xhtml\+xml" /> </identification> <!-- <capabilities> <capability name="preferredrenderingmime" value="text/vnd.wap.wml" /> <capability name="preferredrenderingtype" value="wml11" /> </capabilities> --> </defaultbrowser>
3、iis的applicationhost.config设置
设置命令:
c:\windows\system32\inetsrv\appcmd.exe set config /section:serverruntime /appconcurrentrequestlimit:100000
设置结果:
< serverruntime appconcurrentrequestlimit="100000" />
(保存后该设置立即生效)
4、http.sys的设置
注册表设置命令1(将最大连接数设置为10万):
reg add hklm\system\currentcontrolset\services\http\parameters /v maxconnections /t reg_dword /d 100000
注册表设置命令2(解决bad request - request too long问题):
reg add hkey_local_machine\system\currentcontrolset\services\http\parameters /v maxfieldlength /t reg_dword /d 32768 reg add hkey_local_machine\system\currentcontrolset\services\http\parameters /v maxrequestbytes /t reg_dword /d 32768
(需要在命令行运行 net stop http & net start http & iisreset 使设置生效)
5、针对负载均衡场景的设置
在url rewrite module中增加如下的规则:
<rewrite> <allowedservervariables> <add name="remote_addr" /> </allowedservervariables> <globalrules> <rule name="http_x_forwarded_for-to-remote_addr" enabled="true"> <match url=".*" /> <servervariables> <set name="remote_addr" value="{http_x_forwarded_for}" /> </servervariables> <action type="none" /> <conditions> <add input="{http_x_forwarded_for}" pattern="^$" negate="true" /> </conditions> </rule> </globalrules> </rewrite>
相关博文:迁入阿里云后遇到的request.userhostaddress记录ip地址问题
注意事项:添加该url重写规则会造成iis内核模式缓存不工作,详见微软的坑:url重写竟然会引起iis内核模式缓存不工作。
6、设置cache-control为public
在web.config中添加如下配置:
<configuration> <system.webserver> <staticcontent> <clientcache cachecontrolcustom="public" /> </staticcontent> </system.webserver> </configuration>
7、asp.net线程设置
在machine.config的<processmodel>中添加如下设置:
< processmodel enable="true" maxworkerthreads="100" maxiothreads="100" minworkerthreads="50" miniothreads="50"/>
发表评论