Website Performance Issue(s)

kevp75
kevp75 used Ask the Experts™
on
Alright.  I need a little help here.  

I have a CMS built, that I am just trying to tweak right for performance.

The CMS has a token system, that replaces tokens with certain functions, strings, etc... (which, I think may be causing the issue... not sure though.)

Everything is backed by a SQL 2005 db, and everything is run with stored procedures pulling the data from indexed views.

The development site (http://indev.zipcm.com) takes over 16 seconds to load up, and in firebug it looks like it is just the main request that is taking so long.

The production site takes just over 4 seconds (http://www.zipcm.com), with the same Firebug thing above.

Can someone tell me where I am going wrong here?  I'm sorta newish to .net so bear with me if I don't get it ;)

Here's the code for the class that does all the work for processing the site.

Yes I know, there are a few things here that don't seem to be doing anything...  but they will.  I just need to get this performance thing outta the way first...

Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Web.Caching

Namespace ZipCM

    ''' <summary>
    ''' Site Renderer
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Renderer

#Region "Properties"

        ''' <summary>
        ''' Set the pageID to pull content from
        ''' </summary>
        ''' <value></value>
        ''' <remarks></remarks>
        Public WriteOnly Property PageID() As Long
            Set(ByVal value As Long)
                _PageID = value
            End Set
        End Property

        ''' <summary>
        ''' Set a Pare parentID if any
        ''' </summary>
        ''' <value></value>
        ''' <remarks></remarks>
        Public WriteOnly Property ParentID() As Long
            Set(ByVal value As Long)
                _ParentID = value
            End Set
        End Property

        ''' <summary>
        ''' Set a message if there is any
        ''' </summary>
        ''' <value></value>
        ''' <remarks></remarks>
        Public WriteOnly Property ErrorMessage() As String
            Set(ByVal value As String)
                _ErrMsg = value
            End Set
        End Property

        ''' <summary>
        ''' Is the user logged in?
        ''' </summary>
        ''' <value>Boolean</value>
        ''' <remarks></remarks>
        Public WriteOnly Property LoggedIn() As Boolean
            Set(ByVal value As Boolean)
                _LoggedIn = value
            End Set
        End Property

        Public ReadOnly Property SiteTemplate() As String
            Get
                Return _PageTemplate
            End Get
        End Property

        Private _PageID As Long, _ParentID As Long, _ErrMsg As String, _LoggedIn As Boolean
        Private _Tokens() As String, _Replacements() As String
        Private objDb As New ZipCM.Database, objSet As New ZipCM.Settings
        Private _PageTitle As String, _PageKeywords As String, _PageDescription As String
        Private _PageTemplate As String, _PageContent As String

#End Region

        ''' <summary>
        ''' Render the site while compressing the scripts and stylesheets
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub RenderSite()
            Dim objComp As New ZipCM.Compression
            GetSiteContent()
            Common.Write(objComp.ReturnTemplate(_PageTemplate))
            objComp = Nothing
        End Sub

        ''' <summary>
        ''' Get the sites template
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetTemplate() As String
            With objDb
                .CommandType = 4
                .Query = "spSelectLayoutContent"
                .ParamNames = New String() {"@SITEID"}
                .ParamValues = New String() {LookUps.GetSiteID}
                .ExecuteDataReader()
                If .TotalRecords > 0 Then
                    '----------------------------------------------------------------
                    'Get our site content
                    GetSiteContent()
                    Return ProcessTokens(.ReturnValues(0, 0)(1))
                    Erase .ReturnValues
                Else
                    Return "This site currently has no template.  Please <a href=""" & objSet.EmailsFrom & """>contact the site administrator</a> for more information."
                End If
            End With
        End Function


        Public Sub GetSiteContent()
            Dim tmpString As New StringBuilder, tmpCA As Integer
            If ZipCM.Security.CanAccess(New Integer() {1, 2, 3, 4, 5}) Then
                tmpCA = 1
            Else
                tmpCA = 0
            End If
            With objDb
                .CommandType = 4
                .Query = "spSelectPage"
                .ParamNames = New String() {"@PageID", "@SiteID"}
                .ParamValues = New String() {_PageID, LookUps.GetSiteID}
                .ExecuteDataReader()
                If .TotalRecords > 0 Then
                    tmpString.Append("<div class=""site_content"">")
                    tmpString.Append(.ReturnValues(0, 0)(1))
                    tmpString.Append("</div>")
                    If .ReturnValues(5, 0)(1) = 1 Then 'Tag Cloud
                        tmpString.Append("<div id=""tag_cloud"">" & .ReturnValues(1, 0)(1) & "</div>" & vbCrLf)
                    End If
                    If .ReturnValues(4, 0)(1) = 1 Then 'Page Modified, and Created
                        tmpString.Append("<div class=""pageMod"">Added: " & .ReturnValues(2, 0)(1) & "</div>" & vbCrLf)
                        tmpString.Append("<div class=""pageMod"">Modified: " & .ReturnValues(3, 0)(1) & "</div>" & vbCrLf)
                    End If
                    tmpString.Append("<h1 style=""font-size:0px;margin:0;padding:0;border:none;background:none;height:0;width:0;"">" & .ReturnValues(6, 0)(1) & "</h1>")
                    tmpString.Append("<h1 style=""font-size:0px;margin:0;padding:0;border:none;background:none;height:0;width:0;"">" & .ReturnValues(7, 0)(1) & "</h1>")
                    _PageTitle = .ReturnValues(8, 0)(1)
                    _PageDescription = .ReturnValues(7, 0)(1)
                    _PageKeywords = .ReturnValues(6, 0)(1)
                    _PageTemplate = .ReturnValues(9, 0)(1)
                    _PageContent = tmpString.ToString.Replace("##SITE_ID##", LookUps.GetSiteID())
                    Erase .ReturnValues
                Else
                    _PageTitle = ""
                    _PageKeywords = ""
                    _PageDescription = ""
                    _PageTemplate = ""
                    _PageContent = "This site currently has no content.  Please <a href=""" & objSet.EmailsFrom & """>contact the site administrator</a> for more information."
                End If
            End With
            _PageTemplate = ProcessTokens(_PageTemplate)
            'HttpContext.Current.Cache("Page_" & _PageID) = tmpString.ToString().Replace("##SITE_ID##", LookUps.GetSiteID())
            'Return tmpString.ToString().Replace("##SITE_ID##", LookUps.GetSiteID())
            tmpString.Length = 0 : tmpString = Nothing
        End Sub

        ''' <summary>
        ''' Gets the sites main navigation links
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function GetMainNavigation() As String
            Try
                Dim tmpString As New StringBuilder()
                Dim sClass As String = String.Empty
                objDb.CommandType = 4
                objDb.Query = "spGetSiteNavigation"
                Dim tmp As Object = New Integer() {1, 2, 3, 4, 5}
                If ZipCM.Security.CanAccess(tmp) Then
                    objDb.ParamValues = New String() {"{" & LookUps.GetSiteID & "}", 0, 1}
                    objDb.ParamNames = New String() {"@SiteID", "@ParentID", "@LoggedIn"}
                Else
                    objDb.ParamValues = New String() {"{" & LookUps.GetSiteID & "}", 0, 0}
                    objDb.ParamNames = New String() {"@SiteID", "@ParentID", "@LoggedIn"}
                End If
                tmp = Nothing
                objDb.ExecuteDataReader()
                If objDb.TotalRecords > 0 Then
                    tmpString.Append("<ul>" & vbCrLf)
                    For i As Long = 0 To objDb.TotalRecords - 1
                        sClass = " class=""site_nav"""
                        If i = 0 Then
                            sClass = " class=""nav_start"""
                        End If
                        If i = objDb.TotalRecords - 1 Then
                            sClass = " class=""nav_end"""
                        End If
                        If objDb.ReturnValues(0, i)(1) = objSet.HomePage Then
                            tmpString.Append("          <li" & sClass & "><a href=""/"" title=""" & objDb.ReturnValues(3, i)(1) & """>" & objDb.ReturnValues(4, i)(1) & "</a></li>" & vbCrLf)
                        Else
                            tmpString.Append("          <li" & sClass & "><a href=""/page/" & objDb.ReturnValues(3, i)(1).Replace(" ", "_") & """ title=""" & objDb.ReturnValues(3, i)(1) & """>" & objDb.ReturnValues(4, i)(1) & "</a></li>" & vbCrLf)
                        End If
                    Next
                    tmpString.Append("      </ul>" & vbCrLf)
                    Erase objDb.ReturnValues
                End If
                Return tmpString.ToString()
                tmpString.Length = 0 : tmpString = Nothing
            Catch ex As Exception
                Dim objErr As New ZipCM.ErrorManager
                objErr.Location = "SiteHandler - SiteNavigation"
                objErr.Stack = ex.StackTrace()
                objErr.Except = ex
                objErr.ParseError()
                objErr = Nothing
            End Try
        End Function

        ''' <summary>
        ''' Gets the sites sub-navigation links
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function GetSubNavigation() As String
            Try
                Dim tmpString As New StringBuilder()
                Dim sClass As String = String.Empty
                objDb.CommandType = 4
                objDb.Query = "spGetSiteNavigation"
                Dim tmp As Object = New Integer() {1, 2, 3, 4, 5}
                If ZipCM.Security.CanAccess(tmp) Then
                    objDb.ParamValues = New String() {"{" & LookUps.GetSiteID & "}", _PageID, 1}
                    objDb.ParamNames = New String() {"@SiteID", "@ParentID", "@LoggedIn"}
                Else
                    objDb.ParamValues = New String() {"{" & LookUps.GetSiteID & "}", _PageID, 0}
                    objDb.ParamNames = New String() {"@SiteID", "@ParentID", "@LoggedIn"}
                End If
                tmp = Nothing
                objDb.ExecuteDataReader()
                If objDb.TotalRecords > 0 Then
                    tmpString.Append("<ul>" & vbCrLf)
                    For i As Long = 0 To objDb.TotalRecords - 1
                        sClass = " class=""site_sub_nav"""
                        If i = 0 Then
                            sClass = " class=""nav_start"""
                        End If
                        If i = objDb.TotalRecords - 1 Then
                            sClass = " class=""nav_end"""
                        End If
                        If objDb.ReturnValues(0, i)(1) = objSet.HomePage Then
                            tmpString.Append("  <li" & sClass & "><a href=""/"" title="""">" & objDb.ReturnValues(4, i)(1) & "</a></li>" & vbCrLf)
                        Else
                            tmpString.Append("  <li" & sClass & "><a href=""/page/" & objDb.ReturnValues(0, i)(1) & """ title="""">" & objDb.ReturnValues(4, i)(1) & "</a></li>" & vbCrLf)
                        End If
                    Next
                    tmpString.Append("</ul>" & vbCrLf)
                    Erase objDb.ReturnValues
                End If
                Return tmpString.ToString()
                tmpString.Length = 0 : tmpString = Nothing
            Catch ex As Exception
                Dim objErr As New ZipCM.ErrorManager
                objErr.Location = "SiteHandler - SiteSubNavigation"
                objErr.Stack = ex.StackTrace()
                objErr.Except = ex
                objErr.ParseError()
                objErr = Nothing
            End Try
        End Function

        ''' <summary>
        ''' Gets the sites breadcrumb navigation where needed
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function GetBreadcrumbNavigation() As String
            Try
                With objDb
                    .CommandType = 4
                    .Query = "spBreadCrumbNav"
                    .ParamNames = New String() {"@PageID", "@Delimiter"}
                    .ParamValues = New String() {_PageID, " >> "}
                    .ExecuteDataReader()
                    If .TotalRecords > 0 Then
                        Return .ReturnValues(0, 0)(1)
                        Erase .ReturnValues
                    Else
                        Return String.Empty
                    End If
                End With
            Catch ex As Exception
                Dim objErr As New ZipCM.ErrorManager
                objErr.Location = "SiteHandler - ShowBreadCrumbs"
                objErr.Stack = ex.StackTrace()
                objErr.Except = ex
                objErr.ParseError()
                objErr = Nothing
            End Try
        End Function

        ''' <summary>
        ''' Shows the system messages
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function ShowSystemMessage() As String
            Dim tmpString As New StringBuilder
            If Len(_ErrMsg) > 0 Then
                tmpString.Append("<script type=""text/javascript"">")
                tmpString.Append("    $(document).ready(function(){")
                tmpString.Append("    ShowMessage('" & _ErrMsg & "');")
                tmpString.Append("    });")
                tmpString.Append("</script>")
                HttpContext.Current.Response.Cookies("err").Expires = DateTime.Now.AddYears(-30)
            End If
            Return tmpString.ToString
            tmpString.Length = 0 : tmpString = Nothing
        End Function

#Region "Scripts & Styling"

        ''' <summary>
        ''' Insert the jQuery Library, including the PNG Fix Plugin, and the Pre-Load CSS Image Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJquery() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.js""></script>" & vbCrLf)
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.pngFix.pack.js""></script>" & vbCrLf)
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.preloadcssimages.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Tag Cloud Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryTagCloud() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.tagcloud.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery UI
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryUI() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/ui/jquery-ui-1.8.custom.js""></script>" & vbCrLf)
            tmpString.Append("<link type=""text/css"" rel=""stylesheet"" href=""/scripts/libraries/jquery/ui/jquery-ui-1.8.custom.css"" />" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Form Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryForm() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.form.js""></script>" & vbCrLf)
            Return tmpString.ToString
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Datepicker Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryDatePicker() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.dates.js""></script>" & vbCrLf)
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.datepicker.js""></script>" & vbCrLf)
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/ui/jquery.ui.datepicker.js""></script>" & vbCrLf)
            tmpString.Append("<link type=""text/css"" rel=""stylesheet"" href=""/scripts/libraries/jquery/ui/jquery.ui.datepicker.css"" />" & vbCrLf)
            Return tmpString.ToString
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Autocomplete Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryAutocomplete() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.autocomplete.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Cycle All Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryCycleAll() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.cycle.all.min.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Equal Columns Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryEqualColumns() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.equalcolumns.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Easy Slider Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryEasySlider() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/easyslider1.5.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Floating Box Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryFloatingBox() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.floatingbox.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery FlyOff Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryFlyOff() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.flyoffpage.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Timepicker Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJQueryTimePicker() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.timepicker.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery URL Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryURL() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.url.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the jQuery Form Validation Plugin
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertJqueryValidation() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/jquery/jquery.validate.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the Code Highlighter Library
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertHighlighter() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/highlighter/shCore.js""></script>" & vbCrLf)
            tmpString.Append("<script type=""text/javascript"">" & vbCrLf)
            tmpString.Append("SyntaxHighlighter.config.clipboardSwf = ""/scripts/libraries/highlighter/scripts/clipboard.swf"";" & vbCrLf)
            tmpString.Append("SyntaxHighlighter.all();" & vbCrLf)
            tmpString.Append("</script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the Highslide Library
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertHighslide() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/libraries/highslide/highslide-full.js""></script>" & vbCrLf)
            tmpString.Append("<link type=""text/css"" rel=""stylesheet"" href=""/scripts/libraries/highslide/high_dark.css"" />" & vbCrLf)
            Return tmpString.ToString
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the default Javascript Libraries
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertDefaultScripts() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<script type=""text/javascript"" src=""/scripts/built/o7th.js""></script>" & vbCrLf)
            tmpString.Append("<script type=""text/javascript"" src=""/sites/" & LookUps.GetSiteID() & "/scripts/custom.js""></script>" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

        ''' <summary>
        ''' Insert the Default CSS Stylesheet
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function InsertStyles() As String
            Dim tmpString As New StringBuilder
            tmpString.Append("<link type=""text/css"" rel=""stylesheet"" href=""/sites/" & LookUps.GetSiteID() & "/styles/layout.css"" />" & vbCrLf)
            Return tmpString.ToString()
            tmpString.Length = 0 : tmpString = Nothing
        End Function

#End Region

#Region "Start & End"

        Public Sub New()
            objDb.ConnectionString = Common.ConnString
            objSet.SiteSettings()
        End Sub

        Protected Overrides Sub Finalize()
            objSet = Nothing
            objDb = Nothing
        End Sub

#End Region

        ''' <summary>
        ''' Render our tokens
        ''' </summary>
        ''' <param name="_Processing">The site template or content page to process</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function ProcessTokens(ByVal _Processing As String) As String
            Dim tmpString As String = _Processing
            'Load up our Add-Ons
            '----------------------------------------------------------------
            'User Profiling
            Dim objUP As New ZipCM.UserProfiling
            '----------------------------------------------------------------
            'Site Mapper
            Dim objSM As New ZipCM.SiteMapper
            '----------------------------------------------------------------
            'Social Networking
            Dim objSN As New ZipCM.SocialNetworking
            '----------------------------------------------------------------
            'Newsletter
            _Tokens = New String() {"##SITE_ID##", _
                                    "##PAGE_CONTENT##", _
                                    "##PAGE_TITLE##", _
                                    "##PAGE_KEYWORDS##", _
                                    "##PAGE_DESCRIPTION##", _
                                    "##SITE_NAV##", _
                                    "##SITE_SUB_NAV##", _
                                    "##BREADCRUMB##", _
                                    "##SYSTEM_MESSAGES##", _
                                    "##INSERT_STYLES##", _
                                    "##INSERT_DEFAULT_SCRIPTS##", _
                                    "##INSERT_HIGHSLIDE##", _
                                    "##INSERT_CODE_HIGHLIGHTER##", _
                                    "##INSERT_JQUERY##", _
                                    "##INSERT_JQUERY_TAGCLOUD##", _
                                    "##INSERT_JQUERY_UI##", _
                                    "##INSERT_JQUERY_FORM##", _
                                    "##INSERT_JQUERY_DATEPICKER##", _
                                    "##INSERT_JQUERY_AUTOCOMPLETE##", _
                                    "##INSERT_JQUERY_CYCLE_ALL##", _
                                    "##INSERT_JQUERY_EQUAL_COLUMNS##", _
                                    "##INSERT_JQUERY_EASY_SLIDER##", _
                                    "##INSERT_JQUERY_FLOATING_BOX##", _
                                    "##INSERT_JQUERY_FLYOFF##", _
                                    "##INSERT_JQUERY_TIMEPICKER##", _
                                    "##INSERT_JQUERY_URL##", _
                                    "##INSERT_JQUERY_VALIDATION##", _
                                    "##PROFILE_SCRIPTS##", _
                                    "##USER_REGISTRATION##", _
                                    "##USER_LOGIN_FORM##", _
                                    "##USER_LOGOUT##", _
                                    "##USER_CHANGE_PASSWORD##", _
                                    "##USER_PROFILE##", _
                                    "##SITEMAP_SHOW##", _
                                    "##SOCIAL_NETWORKING_PROFILE_LINKS##", _
                                    "##SOCIAL_NETWORKING_SUBMIT_LINKS##", _
                                    "##SOCIAL_NETWORKING_CODES##", _
                                    "##SOCIAL_NETWORKING_RSS_FEEDS##"}
            _Replacements = New String() {LookUps.GetSiteID, _
                                          _PageContent, _
                                          _PageTitle, _
                                          _PageKeywords, _
                                          _PageDescription, _
                                          GetMainNavigation(), _
                                          GetSubNavigation(), _
                                          GetBreadcrumbNavigation(), _
                                          ShowSystemMessage(), _
                                          InsertStyles(), _
                                          InsertDefaultScripts(), _
                                          InsertHighslide(), _
                                          InsertHighlighter(), _
                                          InsertJquery(), _
                                          InsertJqueryTagCloud(), _
                                          InsertJqueryUI(), _
                                          InsertJqueryForm(), _
                                          InsertJqueryDatePicker(), _
                                          InsertJqueryAutocomplete(), _
                                          InsertJqueryCycleAll(), _
                                          InsertJqueryEqualColumns(), _
                                          InsertJqueryEasySlider(), _
                                          InsertJqueryFloatingBox(), _
                                          InsertJqueryFlyOff(), _
                                          InsertJQueryTimePicker(), _
                                          InsertJqueryURL(), _
                                          InsertJqueryValidation(), _
                                          objUP.ProfileScripts(), _
                                          objUP.RegForm(), _
                                          objUP.LoginForm(), _
                                          objUP.LogoutUser(), _
                                          objUP.ChangePasswordForm(), _
                                          objUP.UsersProfile(), _
                                          objSM.DisplaySiteMap(), _
                                          objSN.DisplaySNProfileLinks(), _
                                          objSN.DisplaySNSubmitLinks(), _
                                          objSN.DisplaySNCodes(), _
                                          objSN.DisplaySNFeeds()}
            objSN = Nothing
            objSM = Nothing
            objUP = Nothing
            For i As Integer = 0 To UBound(_Tokens)
                tmpString = Regex.Replace(tmpString, _Tokens(i), _Replacements(i), RegexOptions.IgnoreCase)
            Next
            Return tmpString
        End Function

    End Class

End Namespace

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I suggest you to try a very simple query with a very simple page.
For example write a query like this;
select count(*) from Users
Then create a simple page with a label. And on page load put the result to the label.

Test this page on test server and production server.

If you get different resulttimes, then I guess you have a problem in your test server, not in your query.

Author

Commented:
the test query runs great on both production and test servers.

here is an additional code bit that may be part of the culprit as well...it's the Compression class from the Render routine above.

Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.IO.Compression

Namespace ZipCM

    Public Class Compression

        ''' <summary>
        ''' Return the Javascript string
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property JSString() As String
            Get
                Return HttpContext.Current.Cache("JS")
            End Get
        End Property

        ''' <summary>
        ''' Return the CSS string
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property CSSString() As String
            Get
                Return HttpContext.Current.Cache("CSS")
            End Get
        End Property

        Private FileCSS As String, FileJS As String, RetTemplate As String

        ''' <summary>
        ''' Compress and combine the CSS
        ''' </summary>
        ''' <param name="_Template"></param>
        ''' <remarks></remarks>
        Private Sub CompressStyleSheets(ByVal _Template As String)
            Dim FilesM As MatchCollection, FileName As String
            FilesM = Regex.Matches(_Template, "<link.*?href=""(.*?)"".*? />")
            Dim M(FilesM.Count - 1) As String
            For i As Long = 0 To M.Length - 1
                'This is the file
                M(i) = FilesM(i).Groups(1).Value
                FileName = Common.BasePath & M(i).Replace("/", "\")
                FileName = FileName.Replace("\\\", "\")
                If File.Exists(FileName) Then
                    Using objFile As New StreamReader(FileName)
                        FileCSS += objFile.ReadToEnd
                        objFile.Close()
                    End Using
                    'Remove Comments
                    FileCSS = Regex.Replace(FileCSS, "/\*[^*]*\*+([^/][^*]*\*+)*/", "")
                    FileCSS = Regex.Replace(FileCSS, "/\*.+?\*/", "", RegexOptions.Singleline)
                    'Remove Line Breaks
                    FileCSS = Regex.Replace(FileCSS, "\n+", "")
                    'Remove Carriage Returns
                    FileCSS = Regex.Replace(FileCSS, "\r+", "")
                    'Remove Tabs
                    FileCSS = Regex.Replace(FileCSS, "\t+", "")
                    'Remove Spaces greater than 2
                    FileCSS = Regex.Replace(FileCSS, "\s{2}", "")
                    'Remove Spaces next to characters
                    FileCSS = FileCSS.Replace(" {", "{")
                    FileCSS = FileCSS.Replace(" :", ":")
                    FileCSS = FileCSS.Replace(": ", ":")
                    FileCSS = FileCSS.Replace(", ", ",")
                    FileCSS = FileCSS.Replace("; ", ";")
                    FileCSS = FileCSS.Replace(";}", "}")
                    'Remove Extras
                    FileCSS = Regex.Replace(FileCSS, "(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,}(?=&nbsp;)|(?<=&ndsp;)\s{2,}(?=[<])", String.Empty)
                    FileCSS = Regex.Replace(FileCSS, "/\*[\d\D]*?\*/", String.Empty)
                    'Pop In The SiteID If Needed
                    FileCSS = FileCSS.Replace("##SITE_ID##", LookUps.GetSiteID)
                End If
            Next
            FilesM = Nothing
            Dim tmp As MatchCollection
            tmp = Regex.Matches(_Template, "<link.*?href=""(.*?)"".*? />")
            Dim tmpCt As Long = 0
            For Each tmpS As Match In tmp
                tmpCt += 1
                If tmpCt = tmp.Count Then
                    _Template = _Template.Replace(tmpS.Groups(0).ToString(), "          <link type=""text/css"" rel=""stylesheet"" href=""/applications/compression.aspx?type=1"" />")
                Else
                    _Template = _Template.Replace(tmpS.Groups(0).ToString(), "")
                End If
            Next
            tmp = Nothing
            RetTemplate = _Template
            HttpContext.Current.Cache("CSS") = FileCSS
        End Sub

        ''' <summary>
        ''' Compress and combine the Javascripts
        ''' </summary>
        ''' <param name="_Template"></param>
        ''' <remarks></remarks>
        Private Sub CompressJavascripts(ByVal _Template As String)
            Dim FilesM1 As MatchCollection, FileName As String
            FilesM1 = Regex.Matches(_Template, "<script.*?src=""(.*?)"".*?></script>")
            Dim M1(FilesM1.Count - 1) As String
            For j As Long = 0 To M1.Length - 1
                'This is the file
                M1(j) = FilesM1(j).Groups(1).Value
                FileName = Common.BasePath & M1(j).Replace("/", "\")
                FileName = FileName.Replace("\\\", "\")
                If File.Exists(FileName) Then
                    Using objFile1 As New StreamReader(FileName)
                        FileJS += objFile1.ReadToEnd
                        objFile1.Close()
                    End Using
                    'Remove Single Line Comments
                    FileJS = Regex.Replace(FileJS, "(// .*?$)", "", RegexOptions.Multiline)
                    'Remove Tabs
                    FileJS = Regex.Replace(FileJS, "\t+", " ")
                    'Remove Uneeded Whitespace
                    FileJS = Regex.Replace(FileJS, "^[\s]+|[ \f\r\t\v]+$", String.Empty, RegexOptions.Multiline)
                    FileJS = Regex.Replace(FileJS, "([\s]){2,}", "$1")
                    'Remove Extras
                    FileJS = Regex.Replace(FileJS, "/\*.*?\*/", String.Empty, RegexOptions.Multiline)
                    FileJS = Regex.Replace(FileJS, "^\s*", String.Empty, RegexOptions.Multiline)
                    FileJS = Regex.Replace(FileJS, "\s*{\s*", "{", RegexOptions.ECMAScript Or RegexOptions.Compiled)
                    FileJS = Regex.Replace(FileJS, "\r\n(?<=\b(abstract|boolean|break|byte|case|catch|char|class|const|continue|default|delete|do|double|else|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|while|with)\r\n)", " ", RegexOptions.ECMAScript Or RegexOptions.Compiled)
                    FileJS = Regex.Replace(FileJS, "^[\s]+|[ \f\r\t\v]+$", String.Empty)
                    FileJS = Regex.Replace(FileJS, "([+-])\n\1", "$1 $1")
                    FileJS = Regex.Replace(FileJS, "([^+-][+-])\n", "$1")
                    FileJS = Regex.Replace(FileJS, "([^+]) ?(\+)", "$1$2")
                    FileJS = Regex.Replace(FileJS, "(\+) ?([^+])", "$1$2")
                    FileJS = Regex.Replace(FileJS, "([^-]) ?(\-)", "$1$2")
                    FileJS = Regex.Replace(FileJS, "(\-) ?([^-])", "$1$2")
                    FileJS = Regex.Replace(FileJS, "([;}]else)\n", "$1 ")
                    FileJS = Regex.Replace(FileJS, "(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,}(?=&nbsp;)|(?<=&ndsp;)\s{2,}(?=[<])", String.Empty)
                    'Insert the SiteID if needed
                    FileJS = FileJS.Replace("##SITE_ID##", LookUps.GetSiteID)
                End If
            Next
            FilesM1 = Nothing
            Dim tmp1 As MatchCollection
            tmp1 = Regex.Matches(_Template, "<script.*?src=""(.*?)"".*?></script>")
            Dim tmpCt1 As Long = 0
            For Each tmpS As Match In tmp1
                tmpCt1 += 1
                If tmpCt1 = tmp1.Count Then
                    _Template = _Template.Replace(tmpS.Groups(0).ToString(), "      <script type=""text/javascript"" src=""/applications/compression.aspx?type=2""></script>")
                Else
                    _Template = _Template.Replace(tmpS.Groups(0).ToString(), "")
                End If
            Next
            tmp1 = Nothing
            RetTemplate = _Template
            HttpContext.Current.Cache("JS") = FileJS
        End Sub

        ''' <summary>
        ''' Return the template with the compressed JS, CSS, and HTML
        ''' </summary>
        ''' <param name="_Template"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function ReturnTemplate(ByVal _Template As String) As String
            CompressStyleSheets(_Template)
            CompressJavascripts(RetTemplate)
            RetTemplate = RetTemplate.Replace(vbTab, String.Empty)
            RetTemplate = RetTemplate.Replace("  ", String.Empty)
            RetTemplate = RetTemplate.Replace(vbCrLf, String.Empty)
            Return RetTemplate
        End Function

    End Class

End Namespace

Open in new window

Author

Commented:
p.s.  by 'runs great' I mean there is no difference in execution time between the 2 servers when run on both
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
I just tested the entire app on both servers.  The app runs the same in both.  What I did notice was, when I comment out the Replace sections in the Compression code, that the pages loaded a bit faster (in both environments).  Not significantly faster, but noticably faster

This is as per Firebug.

Uncommented replaces (server refresh after fresh build)

Page GET 16.46s
JS GET 4.32s
CSS GET 3.4s

Commented replaces (server refresh after fresh build)

Page GET 14.68s
JS GET 437ms
CSS GET 348ms


It seems that Regular expression replaces of this magnitude can seriously decrease the response time it takes to load a page.

So now I wonder if there is a better way to do the compressions?

Author

Commented:
please note, both these tests were run with the development codebase, not the production codebase (production codebase is completly precompiled)

Author

Commented:
i guess this question can be closed?  

I found and cured the issue but asked a secondary question, so I guess it goes unsolved...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial