Link to home
Start Free TrialLog in
Avatar of harrylockhart
harrylockhartFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of _Stilgar_
_Stilgar_
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of harrylockhart

ASKER

Sorry about the time to respond, sudden rush of work (yes for 2 months solid)