IIS8 RewriteModule/URLRewrite非常慢 [英] IIS8 RewriteModule / URLRewrite Extremely Slow

查看:327
本文介绍了IIS8 RewriteModule/URLRewrite非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows Server 2012上运行一个带有IIS8的网站.我试图确定是什么导致IIS的CPU使用率高(IIS经常有50%或更多的CPU使用率).服务器全天每秒接收大约40个请求,但每秒可能只接收1-2个需要处理的URL.

I'm running a website with IIS8 on Windows Server 2012. I'm trying to determine what's causing high CPU usage by IIS (frequently 50% or more CPU usage by IIS). Server receives about 40 total requests per second throughout the day, but probably only 1-2 URLs per second that require processing.

我启用了请求跟踪,发现某些RewriteModule请求要花费100秒以上(!)才能完成.我无法确定在硬件足够多的机器上如何做到这一点.完全相同的URL结构在不到一秒钟的时间内通过Apache上的mod_rewrite处理.

I enabled Request Tracing and found that some RewriteModule requests are taking over 100 seconds (!) to complete. I'm having trouble determining how this is possible on a machine with more than sufficient hardware. The exact same URL structure is processed via mod_rewrite on Apache in less than a second.

示例网址如下:

http://<domain-name>/Product/<Parent-Category>/<Child-Category1>/<Child-Category2>/<Child-Category3>/<Product-Name>

随附的重写规则为:

<rule name="Rule" stopProcessing="true">
      <match url="^Product/([^/\?]+)/?([^/\?]+)?/?([^/\?]+)?/?([^/\?]+)?/?([^/\?]+)?/?([^/\?]+)?/?[\?]?(.+)?$"/>
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
      </conditions>
      <action type="Rewrite" url="/Product/index.php?a={R:1}&amp;b={R:2}&amp;c={R:3}&amp;d={R:4}&amp;e={R:5}&amp;f={R:6}&amp;{R:7}" appendQueryString="true"/>
    </rule>

我在定义匹配URL时是否存在导致处理时间长的问题?如果某些匹配的url使用许多父/子类别(最多5个,通常为3-4个),则它们包含大量字符.

Is there something in the way that I'm defining the match URL that's causing high processing time? Some of the matching urls contain a high number of characters if they utilize many parent/child categories (up to 5, typically 3-4).

推荐答案

问题肯定在您的正则表达式中.最好的方法是尝试将其拆分为其他更具体的模式.

Problem is definitely in your regexp. Best way is try to split it to different more specific patterns.

如果不是这种情况,则此规则应保持相同的功能并更快地工作:

If it is not the case, this rule should keep the same functionality and work faster:

<rule name="Rule" stopProcessing="true">
  <match url="^Product/([^/]+)/?([^/]+)?/?([^/]+)?/?([^/]+)?/?([^/]+)?/?([^/]+)?"/>
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
  </conditions>
  <action type="Rewrite" url="/Product/index.php?a={R:1}&amp;b={R:2}&amp;c={R:3}&amp;d={R:4}&amp;e={R:5}&amp;f={R:6}" appendQueryString="true"/>
</rule>

我删除了您的正则表达式中不必要的\?检查,因为<match url中的模式正在检查不带查询字符串的URL,因此,将?检查中的正则表达式是多余的.

I removed unnecessary \? checks in your regexp, because patter inside <match url is checking URL without query string, so, it is redundant to have ? checks in your regexp.

我在PC上进行了检查,它的确可以更快地运行,但是您需要再次检查它是否保持相同的功能

I checked on my PC and it works definitely faster, but you need to double check that it remains the same functionality

这篇关于IIS8 RewriteModule/URLRewrite非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆