Performance tips for RIA Service with Silverlight 4

No.of Views1197
Bookmarked0 times
Downloads 
Votes0
By  Manas Patnaik   On  10 Apr 2011 05:04:58
Tag : Silver Light and XAML , Applications
Performance is a vital part for any application possibly more important for web based app.With wizard based approach of RIA service generally we tends to comprise all entities, exposing to the client and also allowing the DomainService to go for everything from the database. Not only this approach takes a toll on security, but also it loads the middle tier unreasonably. So this post is about few tips using which we can improve the performance. Well mostly we will cover the Pagination, Limiting
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

 Performance is a vital part for any application possibly more important for web based app.With wizard based approach of RIA service generally we tends to comprise all entities, exposing to the client and also allowing the DomainService to go for everything from the database. Not only this approach takes a toll on security, but also it loads the middle tier unreasonably.

So this post is about few tips using which we can improve the performance. Well mostly we will cover the Pagination, Limiting Query results and Output cache of the results.

 

The Example

As we need a database with records that really exist on real worlds scenario.I am going to stick with Adventure Database example database from Microsoft.As mentioned on my earlier post ,More details regarding the database can be found from here.Also you can download database samples from codeplex  with following links AdventureWorksLT 2005 Version,AdventureWorksLT 2008 Version.For Presentation model scenario i am going to use a part of the Data Model which involves Customer and Address .

And we will use the same sample as mentioned in my Presentation Model article.

RIA Performance Tips

Before beginning with the performance measures allow me to put some light on basic configurations and coding of the project.In this example the DataBinding is achieved  declaratively through DomainDataSource control .The DomainDataSourceControl code is as follows

1
2
3
4
5
6
7
8
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:CustomerPresentationModel, CreateList=true}" Height="0"
                              LoadedData="customerPresentationModelDomainDataSource_LoadedData"
                              Name="customerPresentationModelDomainDataSource"
                              QueryName="GetCustomersWithAddressQuery" Width="0">
    <riaControls:DomainDataSource.DomainContext>
        <my:ADVWORKDomainContext />
    </riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>

The next step is bind the the DomainDataSource to the Item Source of DataGrid ,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<sdk:DataGrid AutoGenerateColumns="False" Height="468"  ItemsSource="{Binding ElementName=customerPresentationModelDomainDataSource, Path=Data}" Margin="0,66,0,0" Name="customerPresentationModelDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top">
    <sdk:DataGrid.Columns>
        <sdk:DataGridTextColumn x:Name="addressIDColumn" Binding="{Binding Path=AddressID}" Header="Address ID" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="addressLine1Column" Binding="{Binding Path=AddressLine1}" Header="Address Line 1" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="addressLine2Column" Binding="{Binding Path=AddressLine2}" Header="Address Line 2" Width="SizeToHeader" />
        <sdk:DataGridTemplateColumn x:Name="addressModifiedDateColumn" Header="Address Modified Date" Width="SizeToHeader">
            <sdk:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <sdk:DatePicker SelectedDate="{Binding Path=AddressModifiedDate, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellEditingTemplate>
            <sdk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=AddressModifiedDate, StringFormat=\{0:d\}}" />
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellTemplate>
        </sdk:DataGridTemplateColumn>
        <sdk:DataGridTextColumn x:Name="cityColumn" Binding="{Binding Path=City}" Header="City" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="customerIDColumn" Binding="{Binding Path=CustomerID, Mode=OneWay}" Header="Customer ID" IsReadOnly="True" Width="SizeToHeader" />
        <sdk:DataGridTemplateColumn x:Name="customerModifiedDateColumn" Header="Customer Modified Date" Width="SizeToHeader">
            <sdk:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <sdk:DatePicker SelectedDate="{Binding Path=CustomerModifiedDate, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellEditingTemplate>
            <sdk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=CustomerModifiedDate, StringFormat=\{0:d\}}" />
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellTemplate>
        </sdk:DataGridTemplateColumn>
        <sdk:DataGridTextColumn x:Name="emailAddressColumn" Binding="{Binding Path=EmailAddress}" Header="Email Address" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="firstNameColumn" Binding="{Binding Path=FirstName}" Header="First Name" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="lastNameColumn" Binding="{Binding Path=LastName}" Header="Last Name" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="phoneColumn" Binding="{Binding Path=Phone}" Header="Phone" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="postalCodeColumn" Binding="{Binding Path=PostalCode}" Header="Postal Code" Width="SizeToHeader" />
        <sdk:DataGridTextColumn x:Name="stateProvinceColumn" Binding="{Binding Path=StateProvince}" Header="State Province" Width="SizeToHeader" />
    </sdk:DataGrid.Columns>
</sdk:DataGrid>

Performance Snapshot – Before

Using Visual Studio Profiler Wizard with CPU sampling ,the snapshot shows the elapsed time for calling the query and fetching the detail from the database.The straight forward approach to RIA service with Domain DataSource control it retrieves all 800 records at one shot.

RIA Performance Tips

Well a detailed tutorial about performance wizard in Visual Studio 2010 can be found here.

Performance Tips and Tricks

As the number of records returned by the query always have a performance impact over web so the following tips and trick in combination proper coding standard always makes a difference lets discuss few of them

  • Pagination with LoadSize and PageSize

The first step of improvements lies with applying paging to the data .Well paging works with out DomainDataSource control but it works better with DomainDataSource control.So lets add a DataPager control to the page and bind the source to Domaindatasource control

1
2
3
<sdk:DataPager Height="26" Margin="0,0,0,44" Name="dpCustomers" PageSize="10" VerticalAlignment="Bottom"
               DisplayMode="FirstLastPreviousNextNumeric" AutoEllipsis="False"
               Source="{Binding Path=ItemsSource,ElementName=customerPresentationModelDataGrid}"/>

Although the paging option will start working but still we are loading everything from the database so we need to some tweaks to the DomainDataSource control

RIA Performance Tips

As mentioned in above image ,LoadSize load exactly specified amount of records with each hit to the Tier interaction.For next 30 records it hits the database again.

RIA Performance Tips

so here with above snap shot from Tier Interaction you can find out for each record after 30th the DomainDataSource control is sending fresh request to fetch next set.

While working with LoadSize and page Size make sure that the PageSize of Datapager and DomainDataSource control are same , here in this example its defined as 10.Also make sure the page size is less than the LoadSize.

  • Limit Results of Query Operation

Instead of fetching all the detail , try using QueryAttribute to limit the results from the query operation .Domain Service at server side supports attribute to limit the result set.For example here in this example each call to domain service returns maximum 30 results.

RIA Performance Tips

Well make sure that your loadsize and pagesize as mentioned in above tips for Datapager must be with in this limit .Well it worth mentioning that one of my reader was facing issues ,the famous LoadOperation failed and on digging a bit we found real problem was timeOut .once we set the ResultLimit , the project was on run.

  • Cashing of output

Well this option really does not meant for real time data where changes are very frequent but you can always cache the output of a method call using attributes.

RIA Performance Tips

As shown above OutoutCacheLocation specifies the location where the resource need to be cached.

Performance Snapshot – After

Well we talked much and now its time for result , as mentioned above the TierInteraction gives you a complete picture of time taken by each method call .

RIA Performance Tips

Comparison of Performance

The last call where you can compare both performance results let you show a complete picture over the improvement.

RIA Performance Tips

The Delta here shows a sharp increment in performance of Tier Interaction  for GetCustomerWithAddress query method.

Conclusion

May be there are lots of scope available for performance improvement such as exposing entities that need to be exposed to client by using Presentation Model and some few tricks over native WCF service but for the time being hope above will make a difference .Keep me suggesting your ideas and comments.

Source Code and Performance Reports

Download Link – : RIAPerformanceTips.zip

 
Sign Up to vote for this article
 
About Author
 
Manas Patnaik
Occupation-Software Engineer
Company-Infosys
Member Type-Fresh
Location-India
Joined date-10 Mar 2011
Home Page-www.manaspatnaik.com
Blog Page-www.manaspatnaik.com/blog
 
 
Other popularSectionarticles
    My earlier post was about the basic CRUD operations on entities with relation .We had discussed about creating simple association and querying as well as Invoking CRUD operation onto them.As i have mentioned there ,here in this article we will have an in-depth look into Presentation Model and its mode of handling related multiple entities.
    Published Date : 10/Mar/2011
    Silvelight is latest buzz in Microsoft.NET Technologies. Silverlight enable us to create rich user interface for the web based application
    Published Date : 16/May/2010
    This article will demonstrate how to build a traditional master page style application in Silverlight.
    Published Date : 16/Feb/2010
    In the previous lesson we talked about COM automation support introduced in Silverlight 4 and we said that COM automation is available only for Silverlight OOB (Out-of-Browser) applications that have Elevated Trust, and that’s one of the security restrictions imposed by Silverlight. Today, we’re going to talk about COM automation in more details and give few Silverlight examples that make use of this great feature.
    Published Date : 31/Mar/2011
    In April 2010 Silverlight 4 was released to the world with one of its great features ever, COM-automation support, that allows you to create cutting-edge applications that do everything you can imagine.
    Published Date : 27/Mar/2011
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top