Url rewriting IIS8重写模块/URL重写速度极慢

Url rewriting IIS8重写模块/URL重写速度极慢,url-rewriting,iis-8,windows-server-2012,Url Rewriting,Iis 8,Windows Server 2012,我在Windows Server 2012上运行一个带有IIS8的网站。我试图确定是什么导致IIS的CPU使用率高(通常是IIS的CPU使用率高达50%或更多)。服务器全天每秒接收大约40个请求,但可能每秒只接收1-2个需要处理的URL 我启用了请求跟踪,发现一些重写模块请求需要超过100秒!完成。我很难确定这在一台拥有足够硬件的机器上是如何实现的。在Apache上通过mod_rewrite在不到一秒钟的时间内处理完全相同的URL结构 示例URL如下所示: http://<domain-n

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

我启用了请求跟踪,发现一些重写模块请求需要超过100秒!完成。我很难确定这在一台拥有足够硬件的机器上是如何实现的。在Apache上通过mod_rewrite在不到一秒钟的时间内处理完全相同的URL结构

示例URL如下所示:

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个),则它们包含大量字符

问题肯定在您的regexp中。最好的方法是尝试将其拆分为不同的更具体的模式

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

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

我删除了不必要的\?检查您的regexp,因为patterinside我进行了广泛的测试,并将规则更改为以下内容。这导致CPU下降到1%,之前的100秒完成时间下降到大约50毫秒

我仍然不明白这是怎么可能的-这是一台4 CPU/8核的机器,内存为48GB,IIS8花了100秒来分离一个70个字符的字符串,并将其与以前的正则表达式进行比较。除非前面的例子以某种方式创建了一个近乎无限的循环,否则我不知道它怎么可能那么慢

新规则:

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

我在周五晚些时候发布了我所做的更改,但我接受了你的回答,因为它表明了同样的根本性更改。