Oct 19, 2009, 7:06 PM
HttpProxy Response Takes Too Long
The context.Response returned from my LinesDataEntryHandler.ashx is taking way too long.
I have implemented the paging, returning a limit of 25 records each time; including on the autoload of the store.
Here is the aspx page (nothing in code behind).
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="DataEntryLines.aspx.vb" Inherits="FWLD.WebClient.DataEntryLines" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<link href="../FWLDStyle.css" rel="stylesheet" type="text/css" />
<title></title>
<style type="text/css">
.search-item {
font: normal 11px tahoma, arial, helvetica, sans-serif;
padding: 3px 10px 3px 10px;
border: 1px solid #fff;
border-bottom: 1px solid #eeeeee;
white-space: normal;
color: #555;
}
.search-item h3 {
display: block;
font: inherit;
font-weight: bold;
color: #222;
}
.search-item h3 span {
float: right;
font-weight: normal;
margin: 0 0 5px 5px;
width: 100px;
display: block;
clear: none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ext:ViewPort ID="ViewPortLines" runat="server">
<Body>
<ext:FitLayout ID="FitLayoutLines" runat="server">
<ext:Panel ID="PanelAdminLines"
runat="server"
Border="False"
Header="False">
<Body>
<ext:Store runat="server" ID="LinesStore" AutoLoad="true" SerializationMode="Simple">
<AutoLoadParams>
<ext:Parameter Name="start" Value="0" Mode="Raw" />
<ext:Parameter Name="limit" Value="25" Mode="Raw" />
</AutoLoadParams>
<Proxy>
<ext:HttpProxy Method="GET" Url="../Handlers/LinesDataEntryHandler.ashx" />
</Proxy>
<UpdateProxy>
<ext:HttpWriteProxy Method="POST" Url="../Handlers/LinesDataEntrySaveHandler.ashx" />
</UpdateProxy>
<Reader>
<ext:JsonReader ReaderID="LineID" Root="alllines" TotalProperty="totalCount">
<Fields>
<ext:RecordField Name="LineID" />
<ext:RecordField Name="PlantArea" />
<ext:RecordField Name="Commodity" />
<ext:RecordField Name="ProjSpecID" />
<ext:RecordField Name="Sequence" />
<ext:RecordField Name="PipeDiameter" />
</Fields>
</ext:JsonReader>
</Reader>
<BaseParams>
<ext:Parameter Name="projectID" Value="15" Mode="Raw" />
</BaseParams>
<Listeners>
<LoadException Handler="Ext.MessageBox.alert('Load failed', response.statusText);" />
<SaveException Handler="alert('save failed');" />
<CommitDone Handler="Ext.MessageBox.alert('Status', 'Changes saved successfully.');" />
<CommitFailed Handler="alert('Commit failed\nReason: '+msg)" />
</Listeners>
</ext:Store>
<ext:Store runat="server" ID="ProjectSpecsStore" AutoLoad="false" >
<Proxy>
<ext:HttpProxy Method="GET" Url="../Handlers/ProjectSpecificationsHandler.ashx" />
</Proxy>
<Reader>
<ext:JsonReader ReaderID="ProjSpecID" Root="specs">
<Fields>
<ext:RecordField Name="ProjSpecID" />
<ext:RecordField Name="Spec" />
<ext:RecordField Name="ConstClass" />
</Fields>
</ext:JsonReader>
</Reader>
<BaseParams>
<ext:Parameter Name="ProjectID" Value="15" Mode="Raw" />
</BaseParams>
<Listeners>
<LoadException Handler="Ext.MessageBox.alert('Load failed', response.statusText);" />
</Listeners>
</ext:Store>
<ext:FitLayout ID="FitLayoutgrid" runat="server">
<ext:GridPanel
ID="GridPanelLines"
runat="server"
StoreID="LinesStore"
Title="Lines"
BodyBorder="False"
Border="True"
Header="False"
ClicksToEdit="0"
StripeRows="true"
TrackMouseOver="true"
>
<ColumnModel ID="ColumnModelLine" runat="server">
<Columns>
<ext:Column
ColumnID="LineID"
Header="ID"
Sortable="true"
Width="25"
DataIndex="LineID"
Hidden="true">
</ext:Column>
<ext:Column
ColumnID="PlantArea"
Header="Plant"
Sortable="true"
Width="50"
DataIndex="PlantArea">
<Editor>
<ext:TextField ID="txtPlantArea" runat="server" AllowBlank="false" />
</Editor>
</ext:Column>
<ext:Column
ColumnID="Commodity"
Header="Commodity"
Sortable="true"
Width="75"
DataIndex="Commodity">
<Editor>
<ext:TextField ID="txtCommodity" runat="server" AllowBlank="false" />
</Editor>
</ext:Column>
<ext:Column
ColumnID="ProjSpecID"
Header="Line Class/Spec"
Sortable="true"
Width="75"
DataIndex="ProjSpecID">
<Editor>
<ext:ComboBox
ID="cboProjectSpec"
runat="server"
StoreID="ProjectSpecsStore"
DisplayField="Spec"
ValueField="ProjSpecID" >
<Template ID="templateProjectSpecList" runat="server">
<tpl for=".">
<div class="search-item">
{Spec} {ConstClass}
</tpl>
</Template>
</ext:ComboBox>
</Editor>
</ext:Column>
<ext:Column
ColumnID="Sequence"
Header="Sequence"
Sortable="true"
Width="50"
DataIndex="Sequence">
<Editor>
<ext:NumberField ID="txtSequence" runat="server" AllowDecimals="true" AllowBlank="false" />
</Editor>
</ext:Column>
<ext:Column
ColumnID="PipeDiameter"
Header="Pipe Diameter"
Sortable="true"
Width="65"
DataIndex="PipeDiameter">
<Editor>
<ext:NumberField ID="txtPipeDiameter" runat="server" AllowDecimals="true" AllowBlank="false" />
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
<Listeners>
<RowSelect Handler="#{btnSaveLine}.enable();" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
<TopBar>
<ext:Toolbar ID="toolbarWelds" runat="server" >
<Items>
<ext:ToolbarButton ID="btnAddLine" runat="server" Icon="Add" Text="Add" >
<Listeners>
<Click Handler="#{GridPanelLines}.insertRecord(0, {});#{GridPanelLines}.getView().focusRow(0);#{GridPanelLines}.startEditing(0, 0);" />
</Listeners>
<ToolTips>
<ext:ToolTip ID="ToolTip2" runat="server" Html="Add" />
</ToolTips>
</ext:ToolbarButton>
<ext:ToolbarButton ID="btnSaveLine" runat="server" Icon="Disk" Text="Save" Disabled="false" >
<Listeners>
<Click Handler="#{GridPanelLines}.save();" />
</Listeners>
<ToolTips>
<ext:ToolTip ID="ToolTip1" runat="server" Html="Save" />
</ToolTips>
</ext:ToolbarButton>
</Items>
</ext:Toolbar>
</TopBar>
<BottomBar>
<ext:PagingToolBar
ID="PagingToolBar1"
runat="server"
StoreID="LinesStore"
PageSize="25"
DisplayInfo="true"
DisplayMsg="Displaying Lines {0} - {1} of {2}"
/>
</BottomBar>
</ext:GridPanel>
</ext:FitLayout>
</Body>
</ext:Panel>
</ext:FitLayout>
</Body>
</ext:ViewPort>
</form>
<ext:ScriptManager ID="ScriptManager1" runat="server" />
</body>
</html>
Getting the list of "lines" is very fast. It's when it writes the response that things hang a bit. Takes about 15-25 seconds before the response is rendered in the page.Here is my handler...
Imports System.Web
Imports System.Web.Services
Imports Coolite.Ext.Web
Imports FWLD.WebClient.ListItems
Imports System.Linq.Expressions
Public Class LinesDataEntryHandler
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/json"
Dim start = 0
Dim limit = 25
Dim sort = String.Empty
Dim dir = String.Empty
Dim query = String.Empty
Dim countOf As Integer = 0
Dim projectID = 15
If Not String.IsNullOrEmpty(context.Request("start")) Then
start = Integer.Parse(context.Request("start"))
End If
If Not String.IsNullOrEmpty(context.Request("limit")) Then
limit = Integer.Parse(context.Request("limit"))
End If
If Not String.IsNullOrEmpty(context.Request("sort")) Then
sort = context.Request("sort")
End If
If Not String.IsNullOrEmpty(context.Request("dir")) Then
dir = context.Request("dir")
End If
If Not String.IsNullOrEmpty(context.Request("query")) Then
query = context.Request("query")
End If
If Not String.IsNullOrEmpty(context.Request("projectID")) Then
projectID = Integer.Parse(context.Request("projectID"))
End If
Dim lines As List(Of Line) = LoadLinesPaging(start, limit, sort, dir, query, countOf, projectID)
context.Response.Write(String.Format("{{totalCount:{1},'alllines':{0}}}", JSON.Serialize(lines), countOf))
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Shared Function LoadLinesPaging(ByVal start As Integer, _
ByVal limit As Integer, _
ByVal sort As String, _
ByVal dir As String, _
ByVal filter As String, _
ByRef Count As Integer, _
ByVal projectID As Integer) As List(Of Line)
Dim _myContext As New FWLDEntitiesDataContext()
Dim result As List(Of Line)
result = (From l In _myContext.Lines Select l).ToList
Dim iCount As Integer = result.Count
Count = result.Count()
If ((start + limit) > result.Count) Then
limit = result.Count - start
End If
Dim rangeLines As List(Of Line) = If((start < 0 OrElse limit < 0), result, result.GetRange(start, limit))
Return rangeLines
End Function
End Class
</SELECT>