 |
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0  | This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

April 11th, 2007, 04:03 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Question on scalability and performance
Hi,
I enjoy this book but have the following observations and a question:
- In any business class all the real work is done by a static method.
- This method get a instance of the corresponding data access class.
- At any one time there is only one instance of a data access class.
Question: how does this affect the scalability and performance of the site?
Thanks in advance for your answer/comments
|
|

April 13th, 2007, 11:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How many instances would you like, and how would you decide which one gets used? Besides, they share the same code, anyway. Only state (in the form of instance fields) is separated into class instances.
Static methods always perform better than instance methods, but it's hard to measure much difference unless you compare empty method calls. Instance methods aren't really copied, but they have to be accessed thru a virtual dispatch in most cases, which adds about 40% more overhead (when you compare the dispatch to empty methods that don't do anything). You can reduce the overhead by not marking them virtual, but that could impact your OOP model, especially if you had grand designs on what you wanted to do with instances.
Eric
|
|

April 16th, 2007, 02:54 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Eric,
Thanks for your reply. I understand the difference between static and instance classes. The fact that they both exist means that each must have its own pros and cons. For instance in ASP.NET, the Directory class exposes static methods and the DirectoyInfo class contains instance methods. The former is good for one time use while the latter is good for repeated called of its methods.
In the case of the Website Programming code, I was wondering how much of a performance issue it would be say if we were to implement it for a site with hundreds (or even thousands) of simutaneous user access (like Google or MS site). I normally use instance objects for my business and data access classes, and static class methods when the function is infrequently use.
Regards,
Thanh
|
|

April 17th, 2007, 12:53 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
>the Directory class exposes static methods and the DirectoyInfo class contains instance methods. The former is good for one time use while the latter is good for repeated called of its methods.
Static methods are always more efficient if you don't have to maintain state. It's critical that you get this, or you'll miss the boat. Consider why it's better to have an object instance: specifically so it can remember some of your data between method calls. That's what "state" means. Static calls are fast to dispatch, but they can not maintain any state for you (apart from the possibly of static fields).
Please re-read my message. The code is NEVER copied, regardless of how object instances you have, and how many people hit your site. But it makes sense for you to use a web garden or web farm to help in that regard.
From a design perspective, any extra class instances that aren't needed, and especially those that are unique for each user, will slow down the site and be a drain on server resources. Static objects always make more sense unless you need to retain information.
In ASP.NET you can only maintain information for the time it takes to process one postback unless you utilize the cache, session state, application state, etc. A normal object instance can not survive a page cycle unless it's persisted in some way. So you don't want to be creating a bunch of extra short-lived objects that you don't need because they'll pressure the server; especially in a garbage collection sense. Only create object instances that you need: that will benefit you in some way. Otherwise, use statics.
Eric
|
|

April 17th, 2007, 02:13 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Eric,
Thank you for your patience, I really appreciated your time. I understand the difference between: static and instance method; static and instance variables etc. However this discussion has digressed from my original question namely: how does this affect the scalability and performance of the site?
Your reference to web farm and web garden is interesting though. I was wondering if there are any hard statistics on the performance of websites using static Vs instance classes.
Thanks again,
Thanh
|
|
 |