RegEx.Match is much slower in IIS compared to Development Server (Cassini)?
Asked Answered
Z

1

6

While looking at the performance of an asp.net (webservice) application, we noticed that on IIS it is much slower (38 seconds) than on the Dev Server (18 seconds). Running the Performance profiler (in sampling mode) of Visual studio we noticed the difference is calling regex.Match?! In IIS it is taking 70% of the time, running the same test against same app in dev server, it is taking less than 1% of the total time.

So anyone can explain this weird difference in behaviour between IIS and Dev Server??? I already tried stuff with different application pool setting... but nothing helped

Zusman answered 6/7, 2012 at 15:49 Comment(2)
did you measure this only once?Mediocre
no, multiple times. Even rebooted in between: it is consistentZusman
Z
5

Found it!

It seems to be because IIS is running it in 64 bit (and casinni probably in 32 bit). By switching the application pool to use 32 bit, it is also fast in IIS, resetting it back to 64 bit and it is slow again.

By searching on 64 bit + regex slow, I also found that people already found this in 2006, and also that it was supposed to be fixed in a sp on .NET 2.0 (see: http://blogs.msdn.com/b/bclteam/archive/2007/05/21/the-regexoptions-compiled-flag-and-slow-performance-on-64-bit-net-framework-2-0-josh-free.aspx)

However I use .NET 4.0, so I would not have expected that issue to still exist...

(On stackoverflow see also: Regex slow on Windows Server 2008)

B.T.W. if I do not use the RegexOptions.Compiled when creating the regex, it also performs fast on 64 bit. But I need to do some benchmarking to see what the effect of not compiling it is on 32 bit.

Zusman answered 7/7, 2012 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.