Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: optimization, faster page load


Message #1 by "SpyderJonz" <ajjones13@m...> on Thu, 13 Jun 2002 16:06:57
The code below loads a product selection page with quantity boxes for 
multiple selections. I want to know if I can do anyting to speed up the 
load time for this page.  It currently takes about 12-15 seconds to load 
on 56K and 6-10 seconds on 115K.  I want to speed up at least 3 seconds

thanks,
Spyder

<%@ Language=VBScript %>
<% pageTitle = "Products by Category" %>
<!-- #include file="db.asp" -->
<!-- #include file="adovbs.inc" -->
<%
intCatalogID = Request.QueryString("intCatalogID")
strCatalog_name = Request.QueryString("strCatalog_NAME")
%>
<html>
<head>
<title>Dining Services</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.text1 {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
size: 10pt}
.text12 {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
size: 14pt}
a:link {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
size: 10pt; font-style: normal; line-height: normal; font-weight: bold; 
text-decoration: none}
a:hover {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
size: 10pt; font-weight: bold; text-decoration: none; color: #FF0000}
a:visited {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
size: 10pt; font-weight: bold; text-decoration: none}
.text8 {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
size: 8pt}
-->
</style>
</head>
<body bgcolor="#FFFFFF" topmargin="0" marginheight="0" 
background="../../images/back.gif" link="#003399" vlink="#003399" 
alink="#003399">
<table border="0" cellspacing="0" cellpadding="0" align="center" 
bgcolor="#CCCC99" height="600" width="605">
   <form action="selection.asp" method="post" id="form1" name="form1">
<tr valign="top"> 
    <td rowspan="2" width="137" background="../../images/sideback.gif"> 
      <div align="left"><img src="../../images/sidenav.gif" width="137" 
height="123" usemap="#Map2" border="0">
<map name="Map2">
          <area shape="rect" coords="22,15,116,109" 
href="../../default.asp">
        </map> 
<!--#include file="menu.inc"-->
      </div>
    </td>
    <td width="488" height="105" 
background="../../images/cateringmenu.jpg"> 
      <p><br>
        <br>
        <br>
        <img src="../../images/customername.gif" width="212" height="25" 
hspace="12" vspace="9"></p>
    </td>
  </tr>
  <tr valign="top"> 
    <td width="488" bgcolor="#FFFFFF" height="495" 
background="../../images/contentback.jpg"> 
      <table width="90%" border="0" cellspacing="0" cellpadding="10" 
align="center">
        <tr valign="top"> 
          <td> 
            <table border="0" cellspacing="4" cellpadding="4" width="390">
             
           <tr valign="top"> 

                <td> <span class="text12"><%=strCatalog_name%> 
Selections</span> 
                  <span class="text1"><br>
                  Choose a selection below or <a href="default.asp">go 
back to 
                  categories</a><br>
                  <br>
                  </span> 
                  <table border="0" cellspacing="1" cellpadding="2" 
width="100%" bgcolor="#666699">
<%Dim iPageSize       'Number of rows in page
Dim iPageCount      'The number of pages we'll get back
Dim iPageCurrent    'The page we want to show
Dim strParam		'Passing a parameter
Dim strSQL          'SQL command
Dim iRecordsShown   'Loop controller for displaying just iPageSize records
Dim I               'Standard looping var
Dim recordcount     'count records that have quantites
Dim prodIndex
iPageSize = 20      'Change this integer to the number of records to 
display on page

' Retrieve page to show or default to 1
If Request.QueryString("page") = "" Then
	iPageCurrent = 1
Else
	iPageCurrent = CInt(Request.QueryString("page"))
End If

'Read in parameters for your query.
'Read in order or default to intCatalogID
If Request.QueryString("intcatalogID") = "" Then
	strParam = Response.Write (rsCatalog("catalogID")) 
&strCatalog_NAME=Response.Write (Server.URLEncode(rsCatalog
("catalogName"))) &rsCatalog("catalogName")
Else
	strParam = Request.QueryString("intCatalogID")
End If

' Build SQL String using the parameters
strSQL = "SELECT productID,productName,productPrice FROM products WHERE 
catalogID = '"&strParam&"'"

' Create and open our connection           
      Set Conn = Server.CreateObject("ADODB.Connection")
	  Conn.Open ConString

	  Set rsCatalog = Server.CreateObject("ADODB.Recordset")
	  
rsCatalog.Open "catalogs",Conn,adOpenStatic,adLockReadOnly,adCmdTable 
	  Set rsProdInfo = Server.CreateObject("ADODB.Recordset")
      Set rsProd = Server.CreateObject("ADODB.Recordset")
      rsProd.Open strSQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
	  rsProdInfo.PageSize = iPageSize
	  rsProdInfo.CacheSize = iPageSize
	  rsProdInfo.Open strSQL, Conn, adOpenStatic, adLockReadOnly, 
adCmdText 
	  
	  iPageCount = rsProdInfo.PageCount
	  
	  	If iPageCurrent > iPageCount Then
			 iPageCurrent = iPageCount
		end if
		If iPageCurrent < 1 Then
			 iPageCurrent = 1
		end if
		
		
		If iPageCount = 0 Then
			Response.Write "No records found!"
		Else
		'Move to the selected page
		rsProdInfo.AbsolutePage = iPageCurrent
%>
                    <tr class="text1"> 
                      <td align="left" valign="center" nowrap width="6%"> 
                        <div align="center"><b><font color="#ffffff" 
class="text1" > 
                          ID</font></b></div>
                      </td>
                      <td align="left" valign="center" nowrap width="57%"> 
                        <div align="center"><b><font color="#ffffff" 
class="text1" >Catering 
                          Items </font></b></div>
                      </td>
                      
                      <td align="left" valign="center" nowrap width="14%"> 
                        <div align="center"><b><font color="#ffffff" 
>Price</font></b></div>
                      </td>
                      <td align="left" valign="center" nowrap width="6%"> 
                        <div align="center"><b><font color="#ffffff" 
class="text1" > 
                          Quantity</font></b></div>
                      </td>
                    </tr>
                    <%	  
		iRecordsShown = 0
		Do While Not rsProdInfo.EOF
'	 iRecordsShown < iPageSize And
%>
                    <tr class="text1"> 
                      <td align="center" valign="middle" nowrap width="6%" 
bgcolor="#FFFFFF"><font face="Verdana" name=<%= rsProdInfo("productID")%> 
value=<%= rsProdInfo("productID")%> size="1"><b><%= rsProdInfo
("productID")%></b></font></td>
                      <td align="left" valign="middle" nowrap width="57%" 
bgcolor="#FFFFFF"><font face="Verdana" name=<%= rsProdInfo("productname")%
> value=<%= rsProdInfo("productname")%> size="1"><b><a href="#" 
onClick="NewWindow=window.open('description.asp?intProdID=<%= rsProdInfo
("productID")%
>','NewWindow','toolbar=no,top=yes,left=yes,location=no,directories=no,stat
us=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=350,');">
                        <%= rsProdInfo("productName") %> 
</a></b></font></td>
                      
                      <td align="right" valign="middle" nowrap width="14%" 
bgcolor="#FFFFFF"><font face="Verdana" size="1"> 
                        $<%= formatNumber(rsProdInfo("productPrice"),2) %
></font></td>
                        <td align="center" valign="middle" nowrap 
width="6%" bgcolor="#FFFFFF"><font face="Verdana" size="1"><b><span 
class="text1">
                          <input type="numeric" size="2" name="quant" 
class="formtext" value="0" >
                          </span></b></font></td>

                     </tr><input type="hidden" name="strAddProducts" 
value="<%= rsProdInfo("productID") %>,<%=  rsProdInfo("productname") %
>, ">                  
<%
     iRecordsShown = iRecordsShown + 1
      rsProdInfo.MoveNext  
      Loop
    
 End if
  rsProdInfo.Close
		set rsProdInfo = Nothing
          
		Conn.Close
		set Conn = Nothing         
	%>
                </table>
                  <%

If iPageCurrent <> 1 Then
	%> <a href="productsByCategory.asp?intCatalogID=<%= 
Server.URLEncode(strParam) %>&amp;page=<%= iPageCurrent - 1 %
>"><b>Previous</b></a> 
                  &nbsp;&nbsp; <%
End If

If iPageCurrent < iPageCount Then
	%> <a href="productsByCategory.asp?intCatalogID=<%= 
Server.URLEncode(strParam) %>&amp;page=<%= iPageCurrent + 1 %
>"><b>Next</b></a> 
                  <%
End If
%> </td>
               </tr>
            </table>
              <span class="text1"> </span> 
              <table width="400" border="0">
                <tr>
                  <td align="center"><span class="text1"> 
                    <input type="image" value="Add to Cart" id="submit1" 
name="submit12" src="images/addtoorder.gif" width="139" height="19">
                    </span></td>
                </tr>
                <tr>
                  <td align="center"><span class="text1"><font 
face="Tahoma, Arial" size="2"><a href="reviewOrder.asp" 
onMouseOver="test3.src='images/btnDown_ck.gif'" 
onMouseOut="test3.src='images/btnUp_ck.gif'"><img 
src="images/btnUp_ck.gif" alt="Review Order and/or Check Out" border="0" 
name="test3" width="264" height="20"></a></font></span></td>
                </tr>
              </table>
              <span class="text1"><br>
              <br>
              <br>
              <font face="Tahoma, Arial" size="2"></font> </span></td>
        </tr>
      </table>
      <p align="center"><span class="text1"><img 
src="../../images/bar2.gif" width="375" height="3"><br>
        </span><span class="text1"> <br>
        <a href="http://www.compass-usa.com" target="_blank"><img 
src="../../images/eurest.gif" width="371" height="18" border="0"></a><br>
        <br>
        <br>
        <br>
        </span></p>
      <p align="center">&nbsp;</p>
      <p align="center"><span class="text1"><br>
        <br>
        <span class="text8"><br>
        </span></span></p>
    </td>
  </tr>

</form></table>
</body>
</html>
Message #2 by "Ken Schaefer" <ken@a...> on Fri, 14 Jun 2002 10:38:09 +1000
a) Speed of rendering on the client is determined by the amount of
HTML/Javascript/CSS etc that you need to push down the pipe. Eg a page that
is 30kb of HTML will take twice as long as something that is 15kb of HTML.
This is completely independant of any ASP logic you might have on the page.
So, to cut down on load time, I suggest you optimise your HTML, eg by using
an external style sheet, and by using CSS classes more (eg you can do away
with align="left" and all the <font> tags).

b) Your paging system is expensive (using adOpenStatic). Consider
www.adopenstatic.com/experiments/recordsetpaging.asp for alternative ways of
paging - in particular look at:
    - using .GetRows and the resulting VBScript array rather than
maintaining an expensive recordet
    - using fast adOpenForwardOnly cursor

c) You need to see how expensive your SQL query is - you might be able to
speed it up if you can better optimise indexes etc - however I don't know
how much of a bottle neck this is.

d) Remove the adovbs.inc include. That's a huge file, and you only need a
few of the constants. Instead, include the ADO typelib in your global.asa
file:
www.adopenstatic.com/faq/800a0bb9step2.asp -or- create your own
adoconstants.inc file which contains only the constants you need.

Ceers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "SpyderJonz" <ajjones13@m...>
Subject: [access_asp] optimization, faster page load


: The code below loads a product selection page with quantity boxes for
: multiple selections. I want to know if I can do anyting to speed up the
: load time for this page.  It currently takes about 12-15 seconds to load
: on 56K and 6-10 seconds on 115K.  I want to speed up at least 3 seconds
:
: thanks,
: Spyder
:
: <%@ Language=VBScript %>
: <% pageTitle = "Products by Category" %>
: <!-- #include file="db.asp" -->
: <!-- #include file="adovbs.inc" -->
: <%
: intCatalogID = Request.QueryString("intCatalogID")
: strCatalog_name = Request.QueryString("strCatalog_NAME")
: %>
: <html>
: <head>
: <title>Dining Services</title>
: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
: <style type="text/css">
: <!--
: .text1 {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
: size: 10pt}
: .text12 {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
: size: 14pt}
: a:link {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
: size: 10pt; font-style: normal; line-height: normal; font-weight: bold;
: text-decoration: none}
: a:hover {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
: size: 10pt; font-weight: bold; text-decoration: none; color: #FF0000}
: a:visited {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
: size: 10pt; font-weight: bold; text-decoration: none}
: .text8 {  font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-
: size: 8pt}
: -->
: </style>
: </head>
: <body bgcolor="#FFFFFF" topmargin="0" marginheight="0"
: background="../../images/back.gif" link="#003399" vlink="#003399"
: alink="#003399">
: <table border="0" cellspacing="0" cellpadding="0" align="center"
: bgcolor="#CCCC99" height="600" width="605">
:    <form action="selection.asp" method="post" id="form1" name="form1">
: <tr valign="top">
:     <td rowspan="2" width="137" background="../../images/sideback.gif">
:       <div align="left"><img src="../../images/sidenav.gif" width="137"
: height="123" usemap="#Map2" border="0">
: <map name="Map2">
:           <area shape="rect" coords="22,15,116,109"
: href="../../default.asp">
:         </map>
: <!--#include file="menu.inc"-->
:       </div>
:     </td>
:     <td width="488" height="105"
: background="../../images/cateringmenu.jpg">
:       <p><br>
:         <br>
:         <br>
:         <img src="../../images/customername.gif" width="212" height="25"
: hspace="12" vspace="9"></p>
:     </td>
:   </tr>
:   <tr valign="top">
:     <td width="488" bgcolor="#FFFFFF" height="495"
: background="../../images/contentback.jpg">
:       <table width="90%" border="0" cellspacing="0" cellpadding="10"
: align="center">
:         <tr valign="top">
:           <td>
:             <table border="0" cellspacing="4" cellpadding="4" width="390">
:
:            <tr valign="top">
:
:                 <td> <span class="text12"><%=strCatalog_name%>
: Selections</span>
:                   <span class="text1"><br>
:                   Choose a selection below or <a href="default.asp">go
: back to
:                   categories</a><br>
:                   <br>
:                   </span>
:                   <table border="0" cellspacing="1" cellpadding="2"
: width="100%" bgcolor="#666699">
: <%Dim iPageSize       'Number of rows in page
: Dim iPageCount      'The number of pages we'll get back
: Dim iPageCurrent    'The page we want to show
: Dim strParam 'Passing a parameter
: Dim strSQL          'SQL command
: Dim iRecordsShown   'Loop controller for displaying just iPageSize records
: Dim I               'Standard looping var
: Dim recordcount     'count records that have quantites
: Dim prodIndex
: iPageSize = 20      'Change this integer to the number of records to
: display on page
:
: ' Retrieve page to show or default to 1
: If Request.QueryString("page") = "" Then
: iPageCurrent = 1
: Else
: iPageCurrent = CInt(Request.QueryString("page"))
: End If
:
: 'Read in parameters for your query.
: 'Read in order or default to intCatalogID
: If Request.QueryString("intcatalogID") = "" Then
: strParam = Response.Write (rsCatalog("catalogID"))
: &strCatalog_NAME=Response.Write (Server.URLEncode(rsCatalog
: ("catalogName"))) &rsCatalog("catalogName")
: Else
: strParam = Request.QueryString("intCatalogID")
: End If
:
: ' Build SQL String using the parameters
: strSQL = "SELECT productID,productName,productPrice FROM products WHERE
: catalogID = '"&strParam&"'"
:
: ' Create and open our connection
:       Set Conn = Server.CreateObject("ADODB.Connection")
:   Conn.Open ConString
:
:   Set rsCatalog = Server.CreateObject("ADODB.Recordset")
:
: rsCatalog.Open "catalogs",Conn,adOpenStatic,adLockReadOnly,adCmdTable
:   Set rsProdInfo = Server.CreateObject("ADODB.Recordset")
:       Set rsProd = Server.CreateObject("ADODB.Recordset")
:       rsProd.Open strSQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
:   rsProdInfo.PageSize = iPageSize
:   rsProdInfo.CacheSize = iPageSize
:   rsProdInfo.Open strSQL, Conn, adOpenStatic, adLockReadOnly,
: adCmdText
:
:   iPageCount = rsProdInfo.PageCount
:
:   If iPageCurrent > iPageCount Then
: iPageCurrent = iPageCount
: end if
: If iPageCurrent < 1 Then
: iPageCurrent = 1
: end if
:
:
: If iPageCount = 0 Then
: Response.Write "No records found!"
: Else
: 'Move to the selected page
: rsProdInfo.AbsolutePage = iPageCurrent
: %>
:                     <tr class="text1">
:                       <td align="left" valign="center" nowrap width="6%">
:                         <div align="center"><b><font color="#ffffff"
: class="text1" >
:                           ID</font></b></div>
:                       </td>
:                       <td align="left" valign="center" nowrap width="57%">
:                         <div align="center"><b><font color="#ffffff"
: class="text1" >Catering
:                           Items </font></b></div>
:                       </td>
:
:                       <td align="left" valign="center" nowrap width="14%">
:                         <div align="center"><b><font color="#ffffff"
: >Price</font></b></div>
:                       </td>
:                       <td align="left" valign="center" nowrap width="6%">
:                         <div align="center"><b><font color="#ffffff"
: class="text1" >
:                           Quantity</font></b></div>
:                       </td>
:                     </tr>
:                     <%
: iRecordsShown = 0
: Do While Not rsProdInfo.EOF
: ' iRecordsShown < iPageSize And
: %>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index