Welcome!

Blog Feed Post

ASP.NET MVC: Hidden Performance Problem with HtmlHelper.RenderPartial functions

The problem that has been discovered in this blog entry was resolved - thanks to Simone. Read my follow up blog post that describes why I ran into this problem: http://blog.dynatrace.com/2009/04/23/aspnet-mvc-htmlhelperrenderpartial-caches-resolved-names-in-release-mode/

Original Post

There are some great blog entries about how to improve ASP.NET MVC Performance. Simone Chiaretta bloged about How to improve the performance of ASP.NET MVC web applications. One of his thoughts were on HtmlHelper.RenderPartial and that it can have a significant performance impact on your application. I ran across the same problem and I figured out why that is!

What is HtmlHelper.RenderPartial?

System.Web.Mvc.Html.RenderPartialExtension.RenderPartial extends the HtmlHelper class by offering the ability to render a partial view into your ASP.NET Web Page. The first string parameter allows you to provide a partial view name. This can be the name of an aspx or aspc file. The file can be in the same directory as the ASP.NET Page that calls RenderPartial or it can be in the Shared subdirectory. RenderPartial will make sure to find the correct view to render. Here is an example how it looks in the markup code:

Call to HtmlHelper.RenderPartial. Will ultimately render SearchBox.ascx

Call to HtmlHelper.RenderPartial. Will ultimately render SearchBox.ascx

What happens when a normal ASP.NET MVC Page is processed?

I am currently working with the project Kigg from CodePlex. Its a great application that makes extensive use of ASP.NET MVC. When browsing to the default page several things happen. ASP.NET processes the default page. The application uses a master page which also gets processed. Both - the master page and the default page contain calls to the HtmlHelper class to render certain controls like Menu, SearchBox, MembershipBox and more. Kigg uses RenderPartial by passing a partial name as first parameter. From the outside everything looks fine and it works great. You might be surprised to see the following view captured with dynaTrace:

Exceptions thrown by a single page request

Exceptions thrown by a single page request

When we drill into the PurePath we see that those exception are thrown by RenderPartial:

3 Exceptions thrown for each RenderPartial

3 Exceptions thrown for each RenderPartial

Why do we see this problem?

When passing a partial view name to the RenderPartial method - RenderPartial needs to resolve the partial view name to a physical file that will be loaded and rendered. In order to do this - the ViewEngine is used to resolve the name. The default ViewEngine for ASP.NET MVC Applications is System.Web.Mvc.WebFormViewEngine. In the constructor of this engine we can see the individual file patterns that are used to locate the partial view.

WebFormViewEngine search patterns

WebFormViewEngine search patterns

This location patterns are used in case a partial name is passed to the RenderPartial method. For every pattern - RenderPartial is calling a File.Exists to check the files existance - and throwing an exception in case the file does not exist. In the case of the PurePath shown above - the actual control that was referenced was stored in the ~/Views/Shared directory and had an .ascx extension. The first 3 attempts to locate the file with the other file patterns failed. The 4th succeeded and the control could be loaded.

The problem that we have though is that every page request is throwing many exceptions. Exceptions that are hidden for us developers and that don’t actually show a real problem with the application. But - the more exceptions that are thrown the more overhead you have. Imagine several hundred concurrent users on this front page. Every web request throws 16 exception (in this case) - making it several thousand exceptions every second if we expect some decent load. Exceptions - that cause overhead and degrade overall performance.

How can we solve it?

The easiest way to solve this is by providing the full name to the control that should be rendered. Instead of using

we can use

Conclusion

Frameworks like ASP.NET MVC make it easy to write applications. As with any framework it is essential to understand whats going on under the hood. Hidden exceptions can impact the overall performance. Without knowing about these exceptions its impossible to solve this problems that lead to the exceptions.

When specifying the full path, the ViewEngine is not going to resolve the name with the defined search locations but is using the full qualified filename as it is passed as parameter.

Related posts:

  1. ASP.NET MVC: HtmlHelper.RenderPartial caches resolved names in release mode In my previous blog post I described a performance problem...
  2. Automated Performance Analysis: What’s going on in my ASP.NET or ASP.NET MVC Application? I’ve spent some time in the last weeks playing with different...
  3. SharePoint: Performance Problem with LookupField Control The Microsoft.SharePoint.WebControls.LookupField control is used as the default control when editing...

Read the original blog entry...

More Stories By Andreas Grabner

Andreas Grabner has been helping companies improve their application performance for 15+ years. He is a regular contributor within Web Performance and DevOps communities and a prolific speaker at user groups and conferences around the world. Reach him at @grabnerandi

Latest Stories
Containers are rapidly finding their way into enterprise data centers, but change is difficult. How do enterprises transform their architecture with technologies like containers without losing the reliable components of their current solutions? In his session at @DevOpsSummit at 21st Cloud Expo, Tony Campbell, Director, Educational Services at CoreOS, will explore the challenges organizations are facing today as they move to containers and go over how Kubernetes applications can deploy with lega...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, will provide a fun and simple way to introduce Machine Leaning to anyone and everyone. Together we will solve a machine learning problem and find an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intellige...
Today most companies are adopting or evaluating container technology - Docker in particular - to speed up application deployment, drive down cost, ease management and make application delivery more flexible overall. As with most new architectures, this dream takes significant work to become a reality. Even when you do get your application componentized enough and packaged properly, there are still challenges for DevOps teams to making the shift to continuous delivery and achieving that reducti...
We all know that end users experience the Internet primarily with mobile devices. From an app development perspective, we know that successfully responding to the needs of mobile customers depends on rapid DevOps – failing fast, in short, until the right solution evolves in your customers' relationship to your business. Whether you’re decomposing an SOA monolith, or developing a new application cloud natively, it’s not a question of using microservices – not doing so will be a path to eventual b...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
As hybrid cloud becomes the de-facto standard mode of operation for most enterprises, new challenges arise on how to efficiently and economically share data across environments. In his session at 21st Cloud Expo, Dr. Allon Cohen, VP of Product at Elastifile, will explore new techniques and best practices that help enterprise IT benefit from the advantages of hybrid cloud environments by enabling data availability for both legacy enterprise and cloud-native mission critical applications. By rev...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
Amazon is pursuing new markets and disrupting industries at an incredible pace. Almost every industry seems to be in its crosshairs. Companies and industries that once thought they were safe are now worried about being “Amazoned.”. The new watch word should be “Be afraid. Be very afraid.” In his session 21st Cloud Expo, Chris Kocher, a co-founder of Grey Heron, will address questions such as: What new areas is Amazon disrupting? How are they doing this? Where are they likely to go? What are th...
As you move to the cloud, your network should be efficient, secure, and easy to manage. An enterprise adopting a hybrid or public cloud needs systems and tools that provide: Agility: ability to deliver applications and services faster, even in complex hybrid environments Easier manageability: enable reliable connectivity with complete oversight as the data center network evolves Greater efficiency: eliminate wasted effort while reducing errors and optimize asset utilization Security: imple...
High-velocity engineering teams are applying not only continuous delivery processes, but also lessons in experimentation from established leaders like Amazon, Netflix, and Facebook. These companies have made experimentation a foundation for their release processes, allowing them to try out major feature releases and redesigns within smaller groups before making them broadly available. In his session at 21st Cloud Expo, Brian Lucas, Senior Staff Engineer at Optimizely, will discuss how by using...
The next XaaS is CICDaaS. Why? Because CICD saves developers a huge amount of time. CD is an especially great option for projects that require multiple and frequent contributions to be integrated. But… securing CICD best practices is an emerging, essential, yet little understood practice for DevOps teams and their Cloud Service Providers. The only way to get CICD to work in a highly secure environment takes collaboration, patience and persistence. Building CICD in the cloud requires rigorous ar...
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
Companies are harnessing data in ways we once associated with science fiction. Analysts have access to a plethora of visualization and reporting tools, but considering the vast amount of data businesses collect and limitations of CPUs, end users are forced to design their structures and systems with limitations. Until now. As the cloud toolkit to analyze data has evolved, GPUs have stepped in to massively parallel SQL, visualization and machine learning.
DevOps at Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to w...