http301 redirects seems to be causing massive increase in cpu useage w3wp and sqlservr

Hi,
I've recently added asp scripted http301 redirects on my website for seo purposes, and have found that this seems to have caused a large increase in cpu usage.  I'm after any help on improving the code, or other suggestions on maybe iis optimisations, helicon tech rules, etc.. I can do to help improve performance.
This is asp classic, sql server2000, iis6, and helicon tech isapi  url-rewriting software v2.
basically, the re-writing software allows all sorts of variants of url to display the same page, so I have written some asp (attached) which runs on all asp pages on the website, which checks that the requested name is correct, or redirects to the correct name.
For the attached code, some of the variables are already set elsewhere, the getelement opens a db connection gets the info and closes the connection, setting conn and recordset to nothing.
Sub Main()
dim category_id, category_name
dim product_id, document_id
'
Dim strhost, rc, strMetaLang, strCorrectURL, strRequestedHost, StrRequestedURL, StrRequestedURLPage, baseurl
strMetaLang = getsessionvariable("language")
baseurl=getsessionvariable("xmysite")
strhost = lcase(Request.ServerVariables("HTTP_HOST"))
category_id = ""
category_name = ""
product_id = ""
document_id = ""
 
StrRequestedURLPage = lcase(Request.ServerVariables("URL"))
if left(StrRequestedURLPage,1) = "/" then StrRequestedURLPage = mid(StrRequestedURLPage,2,len(StrRequestedURLPage)-1)
'javalert Request.ServerVariables("HTTP_X_REWRITE_URL")
select case replace(lcase(Request.ServerVariables("URL")),"/","")
    case "showproducts.asp"
        category_id = lcase(request.querystring("id")) ' category
        category_id = SQL_Strip_Bad_Chars(category_id)
        if category_id <> "" AND not isnumeric(category_id) then 
            category_id=""
        else
            category_name = lcase(Request.querystring("cat"))' category
            CleanseMessage category_name, rc
            if rc> 0 then category_name=""
            category_name 	= Replace(category_name,"'","''")' category
        end if
        strCorrectURL = GetISAPLinkByType("category", strMetaLang, xActivateRW, category_id, "", "")
    case "showproduct.asp"
            product_id 		= lcase(Request.querystring("id")) ' product
            product_id = SQL_Strip_Bad_Chars(product_id)
            product_id = SQL_Strip_Bad_Chars(product_id)
            if product_id <> "" AND not isnumeric(product_id) then product_id = ""
            strCorrectURL = GetISAPLinkByType("product", strMetaLang, xActivateRW, product_id, "", "")
    case "default.asp"
        strCorrectURL = "/"
    case "showdocument.asp"
	    if request("docid") = "" then
		    document_id = request("id")
	    else
		    document_id = request("docid")
	    end if
        document_id = SQL_Strip_Bad_Chars(document_id)
        if document_id <> "" AND not isnumeric(document_id) then document_id = ""
        strCorrectURL = GetISAPLinkByType("content", strMetaLang, xActivateRW, document_id, "", "")
case "showcategories.asp"
        category_id = lcase(request.querystring("id")) ' category
        category_id = SQL_Strip_Bad_Chars(category_id)
        if category_id <> "" AND not isnumeric(category_id) then 
            category_id=""
        else
            category_name = lcase(Request.querystring("cat"))' category
            CleanseMessage category_name, rc
            if rc> 0 then category_name=""
            category_name 	= Replace(category_name,"'","''")' category
        end if
        strCorrectURL = GetISAPLinkByType("categories", strMetaLang, xActivateRW, category_id, "", "")
    case else
end select
 
StrRequestedURL = lcase(Request.ServerVariables("HTTP_X_REWRITE_URL"))
 
if left(StrRequestedURL,1) = "/" and len(StrRequestedURL) > 1 then StrRequestedURL = mid(StrRequestedURL,2,len(StrRequestedURL)-1)
strRequestedHost = "http://" & lcase(Request.ServerVariables("HTTP_HOST")) & "/"
if strRequestedHost = lcase(baseurl) then
    if strCorrectURL <> "" and StrRequestedURL <> strCorrectURL then 
    MetaRedirectPerm strCorrectURL
    end if
elseif document_id = "" then
    MetaRedirectPerm baseurl & strCorrectURL
elseif StrRequestedURL<> "/" then
    MetaRedirectPerm "/"
end if
End Sub
 
 
function GetISAPLinkByType(StrIsapType, strIsapLanguage, strIsapUse, strID, strIsapLinkName, strIsapOther)
Dim Strfieldnameappend
if isnull(strIsapLinkName) then strIsapLinkName = ""
strIsapLinkName = trim(strIsapLinkName)
if isnull(strIsapOther) then strIsapOther = ""
GetISAPLinkByType = ""
if lcase(strIsapLanguage) = "english" then 
Strfieldnameappend = ""
else
Strfieldnameappend = "_fr"
end if
if strIsapUse = "" then
strIsapUse="yes"
else
strIsapUse = lcase(strIsapUse)
end if
 
select case lcase(StrIsapType)
case "category" 'Just Products
    if strIsapUse = "yes" then
        if strIsapLinkName = "" then strIsapLinkName=trim(GetElement("categories",strID,"categorydescription" & Strfieldnameappend,"catid"))
        if strIsapLinkName <> "" then GetISAPLinkByType="categories-" & xInfosRW & "-" & FormatLib_Rw(strIsapLinkName) & "-" & strID & ".html"
    else
        GetISAPLinkByType="showproducts.asp?id=" & strID & "&amp;cat=" & Server.URLEncode(strIsapLinkName) 
    end if          
case "product"
        if strIsapUse = "yes" then
            if strIsapLinkName = "" then strIsapLinkName=trim(GetElement("products",strID,"name" & Strfieldnameappend,"prodid"))
            if strIsapLinkName <> "" then GetISAPLinkByType="ficheproduit-" & xInfosRW & "-" & FormatLib_Rw(strIsapLinkName) & "-" & strID & ".html"
        else
            GetISAPLinkByType="showproduct.asp?catalogid=" & strID
    end if
case "content"
        if strIsapUse = "yes" then
            if strIsapLinkName = "" then strIsapLinkName=trim(GetElement("documents",strID,"name","docid"))
            if strIsapLinkName <> "" then GetISAPLinkByType="document-" & xInfosRW & "-" & FormatLib_Rw(strIsapLinkName) & "-" & strID & ".html"
    else
        GetISAPLinkByType="showdocument.asp?documentID=" & strID
    end if
case "categories" 'Products and sub categories
    if strIsapUse = "yes" then
        if strIsapLinkName = "" then strIsapLinkName=trim(GetElement("categories",strID,"categorydescription" & Strfieldnameappend,"catid"))
        if strIsapLinkName <> "" then GetISAPLinkByType="showcategories-" & xInfosRW & "-" & FormatLib_Rw(strIsapLinkName) & "-" & strID & ".html"
    else
        GetISAPLinkByType="showcategories.asp?id=" & strID & "&amp;cat=" & Server.URLEncode(strIsapLinkName) 
    end if          
case else
GetISAPnameOfByType = ""
end select
end function
 
Sub MetaRedirectPerm(strNewUrl)
Response.Status="301 Moved Permanently" 
Response.AddHeader "Location", strNewUrl
end sub

Open in new window

harrylockhartAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_Stilgar_Commented:
As long as you're not using Server.Transfer or similar, there should be no issue with a simple 301 redirect - all it does is modify the response headers and send it as it is. What could be causing this is either a lousy URL parsing algorithms (perhaps too lengthy SQL calls), or processing the rest of the page while still doing a redirect. Try adding Response.End right after you've called the 301 redirection action.

I would also make sure the redirects are not circullar - so you only redirect once and stop, and do not redirect to another URL that causes another redirect to fire up and so on.

Stilgar.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_Stilgar_Commented:
I provided sufficient info to at least start a debugging procedure, and would have provided more help if the asker would have asked for it. I think my comment could be accepted at least as a partial solution.
0
harrylockhartAuthor Commented:
Sorry about the time to respond, sudden rush of work (yes for 2 months solid)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.