当前位置: 移动技术网 > 网络运营>服务器>Windows > 优化IIS7.5支持10万个同时请求的配置方法

优化IIS7.5支持10万个同时请求的配置方法

2019年05月31日  | 移动技术网网络运营  | 我要评论

通过对iis7的配置进行优化,调整iis7应用池的队列长度,请求数限制,tcpip连接数等方面,从而使web服务器的性能得以提升,保证web访问的访问流畅。

iis7.5是微软推出的最新平台iis,性能也较以前有很大的提升,但是默认的设置配不适合很大的请求。但是我们可以根据实际的需要进行iis调整,使其性能更佳,支持同时10万个请求。

以下方案,通过对iis7的配置进行优化,调整iis7应用池的队列长度,请求数限制,tcpip连接数等方面,从而使web服务器的性能得以提升,保证web访问的访问流畅。

今天下午17点左右,博客园博客站点出现这样的错误信息:

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。

iis manager > applicationpools > advanced settings

queue length : 65535

2.  调整iis 7的appconcurrentrequestlimit设置

由原来的默认5000改为100000。

c:\windows\system32\inetsrv\appcmd.exe set config /section:serverruntime /appconcurrentrequestlimit:100000

在%systemroot%\system32\inetsrv\config\applicationhost.config中可以查看到该设置:

<serverruntime appconcurrentrequestlimit="100000" />


3. 调整machine.config中的processmodel>requestqueuelimit的设置

1、单击“开始”,然后单击“运行”。

2、在“运行”对话框中,键入 notepad %systemroot%\microsoft.net\framework64\v4.0.30319\config\machine.config,然后单击“确定”。(不同的.net版本路径不一样,你可以选择你自己当前想设置的.net版本的config)

对于.net2.0对应的是

notepad %systemroot%\windows\microsoft.net\framework64\v2.0.50727\config\machine.config

.4.0

notepad %systemroot%\microsoft.net\framework64\v4.0.30319\config\machine.config

3、找到如下所示的 processmodel 元素:<processmodel autoconfig="true" />

4、将 processmodel 元素替换为以下值:<processmodel enable="true" requestqueuelimit="100000" />

5、保存并关闭 machine.config 文件。
由原来的默认5000改为100000。


<configuration>
    <system.web>
        <processmodel enable="true" requestqueuelimit="100000"/>参考文章:

4. 修改注册表,调整iis 7支持的同时tcpip连接数

由原来的默认5000改为100000。

reg add hklm\system\currentcontrolset\services\http\parameters /v maxconnections /t reg_dword /d 100000

可在注册表中查看

5. 运行命令使用设置生效

net stop http  & net start  http & iisreset 完成上述4个设置,就可以支持10万个并发请求,博客园博客服务器已经启用上述设置。

解决方案:

步骤一:调整iis的应用程序池队列长度。
在【应用程序池】列表中,选择你相应网站所使用的应用程序池,将原来的队列长度由1000改为65535。当然这里的队列长度你可以根据自己的访问用户*1.5来设置,例如:你有2000用户,你此处就可以设置为3000(3000=2000用户数*1.5), 官方参考

设置如下图:

 步骤二:调整iis的appconcurrentrequestlimit值

打开cmd命令,运行命令:c:\windows\system32\inetsrv\appcmd.exe set config /section:serverruntime /appconcurrentrequestlimit:100000

 步骤三:修改asp.net请求队列限制即调整machine.config中的processmodel>requestqueuelimit

1、单击“开始”,然后单击“运行”。

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 文件。

步骤四:修改注册表,调整iis支持的并发tcpip连接数

在cmd命令中运行命令:reg add hklm\system\currentcontrolset\services\http\parameters /v maxconnections /t reg_dword /d 100000,当然也可以手动去注册表修改

为了方法大家与自己使用,我把上面能用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" //www.jb51.net/article/36073.htm

下面为大家补充一点知识:

支持高并发的iis web服务器常用设置
适用的iis版本:iis 7.0, iis 7.5, iis 8.0

适用的windows版本:windows server 2008, windows server 2008 r2, windows server 2012

1、应用程序池(application pool)的设置:

•general->queue length设置为65535(队列长度所支持的最大值)
•process model->idle time-out设置为0(不让应用程序池因为没有请求而回收)
•recycling->regular time interval设置为0(禁用应用程序池定期自动回收)

2、.net framework相关设置

a) 在machine.config中将


<processmodel autoconfig="true" />

改为

<processmodel enable="true" requestqueuelimit="100000"/>

(保存后该设置立即生效)

b) 打开c:\windows\microsoft.net\framework64\v4.0.30319\config\browsers\default.browser,找到<defaultbrowser id="wml" parentid="default" >,注释<capabilities>部分,然后运行在命令行中运行aspnet_regbrowsers -i。

<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>

以解决text/vnd.wap.wml问题。

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"/>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网