HttpProxy Response Takes Too Long

  1. #1

    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>
  2. #2

    RE: HttpProxy Response Takes Too Long

    It's probably the serialization of your custom Line class. Do you have properties on that class that are doing database hits? Can you try creating a simple LineInfo class with just the properties you want to send back and try that? Finally, can you run fiddler and see if the response returned makes sense in terms of size and content?
  3. #3

    RE: HttpProxy Response Takes Too Long

    Yup, that did the trick. I created a simple LineInfo class and created a list of those instead of using the "Line" class.

    The "Line" class is a LINQ class and I suspect the cause is because of the entity sets and references.


    Is there a way to serialize it without all the extra baggage?


    BTW: Thanks for the Fiddler tip. I took the plunge and; installed Fiddler and watched what was happening. Sure enough I was a couple MB being returned.


    Cheers!!


    Paul
  4. #4

    RE: HttpProxy Response Takes Too Long

    I had the same issue, it happens when you have referenced tables. LINQ by default load referenced tables and you get that error.
    I'm handling it by turning of loading of the referenced tables. You can do that by inserting
    dataContenxt.DeferredLoadingEnabled = false;
  5. #5

    RE: HttpProxy Response Takes Too Long

    Thank you Raku!!

    That did it. I was worried I would have to do a bunch of extra work to save changes. This makes it much easier.


    Whew.


  6. #6

    RE: HttpProxy Response Takes Too Long

    Glad I could help.

    Raku
  7. #7

    RE: HttpProxy Response Takes Too Long

    Thanks, i've had similar problem, but in my case nhibernate was rasing an error during lazy loading one of the related entities collection, during serialization.
    That's when i noticed that related objects are being serialized as well while passing to the grid.
    So i used this "Info" solution too. Works much faster now.

Similar Threads

  1. Replies: 0
    Last Post: Aug 05, 2012, 10:46 AM
  2. [CLOSED] return html server response instead of just long extjs script!
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 17, 2011, 8:38 AM
  3. Replies: 7
    Last Post: Feb 17, 2011, 11:45 AM
  4. Textarea takes the value of Combobox
    By BeroOo in forum 1.x Help
    Replies: 4
    Last Post: Aug 16, 2010, 12:51 PM
  5. Empty Label takes up space in V0.8
    By EzaBlade in forum 1.x Help
    Replies: 0
    Last Post: Jul 07, 2009, 7:09 PM

Posting Permissions