DNN Blog

Sep 10

Posted by: Charles Nurse
9/10/2006  RssIcon

As our current version is coming towards the end of its stabilization phase,  I find myself looking at what comes next.   At this time we haven't finalised a Roadmap (in terms of features) for vNext, but we have decided that Performance improvements will be a key component.

I have therefore spent quite a bit of time in the last couple of weeks, profiling our current version (4.3.5).  I have been using a combination of tools,  Red-Gate ANTS Profiler, SQL Server 2005 Profiler, and CacheManager (by Steve Smith on ASPAlliance).

My next few blogs will focus on some of the important bottlenecks I have found, both in memory and speed, and how Module Developers can review their own code to ensure that their modules are not contributing to poor performance.

My first topic is a discussion of the CBO class, and when it should be used, and more importantly when it shouldn't be used.

Let me first describe what the CBO class does.  The CBO (or Custom Business Object) class provides a number of static methods that take a DataReader and converts it into a Business Object.  This is often referred to as "hydration" - the business object is hydrated (or filled). 

As the CBO methods do not know at compile time what kind of object they are "hydrating" they use Reflection.   Reflection is by nature an espensive operation.  It is orders of magnitude slower to create an object using Activator.CreateInstance than to use New.  Equally, PropertyInfo.SetValue is also an extremely expensive operation compared with a simple Property setter in a class.

The TabController, ModuleController and MembershipProvider do not use the CBO class to build their business objects.  They instead have custom "hydrators", such as FillTabInfo, FillModuleInfo etc.  The initial reason for using "custom" hydrators for these classes, rather than the CBO class is that these objects have a deep object structure - CBO only works for simple data types.

Not surprisingly, given the previous discussion, one of the first discoveries I made when profiling the application is that CBO.CreateObject() was one of the top 10 slowest methods, contributing to performance on every request. 

The CBO class is a convenience class, it allows us to use a "generic" methodolgy to hydrate any object, so when we write a Controller class's Get methods we just need to make calls to CBO.FillObject or CBO.FillCollection.  However, this convenience comes at a price, and we need to be aware of this. 

Is the price in performance worth the time it takes to develop a custom hydrator?  In my opinion, I don't think it is worth it.  I spent a few hrs last week writing custom dedicated hydrators for the more common classes, PortalInfo, TabPermissionInfo, ModulePermissionInfo and RoleInfo, and the increase in performance was noticable - CBO.CreateObject is no longer a significant contributor to each request.

As a Module Developer I would recommend that you review your Controller code and for the most common classes build your own custom dedicated hydrators - only rely on CBO for rarely used classes.




Tags:
Categories:
Location: Blogs Parent Separator Charles Nurse

6 comment(s) so far...


Re: Performance, Performance, Performance

YES! YES! YES!

does the Users Class also use CBO methods?

how do we write custom hydrators? -- can you give a sample?

By afromobile on   9/10/2006

Re: Performance, Performance, Performance

Hmm...

I agree, although by just thinking of DNN I would suggest that this is one of the slowest and most used functionalities.

And as this is (as you said yourself) an expensive operation, things tend to get slow (don't get me wrong... there are allot of other places in DNN which need optimizing... one good example is the administrative UI... with a better layed out UI people would get a much faster usage experience).

Back to the point... a custom hydrator could be made with a little help of code generation in .NET and could help allot... Ill try to write on this on my blog tonight (if I have any strength left as I am working a 12hrs work day today...) to try to explain what I think... but basically if you generate enumareted properties for your class you could easily without reflection mimic the CBO functionality.


kind regards,
Vladan Strigo

http://Vladan.Strigo.NET

By vladan on   9/10/2006

Re: Performance, Performance, Performance

With ASP.NET 2.0, creating your own custom hydrator is actually very easy.

I posted an example in my blog at:

http://dotnetnuke.com/Community/Blogs/tabid/825/EntryID/1118/Default.aspx

By AdefWebserver on   9/11/2006

Re: Performance, Performance, Performance

To answer afromobile's question, the answer is no. The UserInfo class is hydrated in the AspNetMembershipProvider using a custom hydrator.

By cnurse on   9/11/2006

Re: Performance, Performance, Performance

I just published one template on MyGeneration site that creates complete set of Custom Hydrator for any selected Table/View.
I have simulated FillObject and FillCollection method just like one available in core. so all you have to do append this code to your controller class and replace "CBO." with "".

http://www.mygenerationsoftware.com/TemplateLibrary/Template/?id=1fba275d-5bd4-43f4-9178-412c84dda11d

By ab13122k on   9/11/2006

Re: Performance, Performance, Performance

Our web site is built base on DNN4.0.2.
One month ago, we desided to use Active Directory, so our user can logon automatically. But we found the performance became very poor. Sometimes the server is down when too much users are using the web site. Do yo think using AD will let the performance to be poor?
By the way, we haven't found the solution to deal with the poor performance. Could you have us?

By yunkun_yang on   9/11/2006
Attend A Webinar
Free Demo Site
Download DotNetNuke Professional Edition Trial
Have Someone Contact Me
Have Someone Contact Me

Like Us on Facebook Join our Network on LinkedIn Follow DNN Corporate on Twitter Follow DNN on Twitter

Advertisers

Sponsors

DotNetNuke Corporation

DotNetNuke Corp. is the steward of the DotNetNuke open source project, the most widely adopted Web Content Management Platform for building web sites and web applications on Microsoft. Organizations use DotNetNuke to quickly develop and deploy interactive and dynamic web sites, intranets, extranets and web applications. The DotNetNuke platform is available in a free Community and subscription-based Professional and Enterprise Editions with an Elite Support option. DotNetNuke Corp. also operates the DotNetNuke Store where users purchase third party apps for the platform.