[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-04
4
Medium Priority
?
278 Views
Last Modified: 2013-11-05
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

0
Comment
Question by:harrylockhart
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
_Stilgar_ earned 1500 total points
ID: 22929249
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
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 23177878
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
 

Author Closing Comment

by:harrylockhart
ID: 31513359
Sorry about the time to respond, sudden rush of work (yes for 2 months solid)
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question