問題描述
IIS 重寫模塊重寫映射性能 (IIS Rewrite Module rewrite map performance)
I'm writing a new site to overtake an old site and need to handle the old url redirects (w/ appropriate content migration). I'm thinking I'd like to use rewrite maps rather than develop a bunch of regular expressions to match b/c the old site has a huge variety of strange url formats. But, I could have up to 8,000 old urls to map and I'm worried that this might consume too many resources and slow down my site. Anyone have any data/experience/guidance regarding rewrite map performance w/ large amounts of urls?
Thanks!
參考解法
方法 1:
The question is referring to the II7 Url Rewrite module 2.0 and the implementation of a large set of items inside a rewritemap. Adding this as custom functionality to the 404 page is not a good design and not optimal for the request pipeline.
The rewritemap is specifically designed to handle large url collections and shouldn't be a problem as long as you have memory to hold 8k urls in addition to yoru other memory needs.
You can easily test the server using jmeter or visual studio to see if the rewritemap size has any significant impact on response time.
方法 2:
I have implemented a URL redirect mechanism on more than one occasion; i've mostly used the 404 handler for this (as this does not incur an overhead penalty for the new URLs); if a request triggers the 404 handler see if it's not actually a redirect; if it is send 301 else send 404.
Redirects can be stored in an indexed lookup (like a Dictionary in c#) which guarantees near constant-time lookup performance for the size you're indicating (8k entries).
Alternatives could be using an HttpModule or (ugh) ISAP filters but your "404 aspx error page" is the most straightforward and easiest to implement.
As for performance; this is a proven solution for a site with 9M+ hits/day.
(by skeej、Develicious、Bjørn van Dommelen)