views:

74

answers:

4

Hi

I work on a big project in company. We collect data which we get via API methods of the CMS.

ex.

DataSet users = CMS.UserHelper.GetLoggedUser(); // returns dataset with users

Now on some pages we need many different data, not just users, also Nodes of the tree of the CMS or specific data of subtreee.

So we thought of write an own "helper class" in which we later can get different data easy.

ex:

MyHelperClass.GetUsers();
MyHelperClass.Objects.GetSingleObject( ID );

Now the problem is our "Helper Class" is really big and now we like to collect different data from the "Helper Class" and write them into a typed dataset . Later we can give a repeater that typed dataset which contains data from different tables. (which even comes from the methods I wrote before via API)

Problem is: It is so slow now, even at loading the page! Does it load or init the whole class??

By the way CMS is Kentico if anyone works with it.

I'm tired. Tried whole night..but it's soooo slow. Please give a look to that architecture. May be you find some crimes which are not allowed :S

I hope we get it work faster. Thank you.

alt text

+2  A: 

Are you already using Caching and Session state?

The basic idea being to defer as much of the data loading to these storage mediums as possible and not do it on individual page loads. Caching especially can be useful if you only need to get the data once and want to share it between users and over time.

If you are already doing these things, ore cant directly implement them try deferring as much of this data gathering as possible, opting to short-circuit it and not do the loading up front. If the data is only occasionally used this can also save you a lot of time in page loads.

GrayWizardx
thank you. no we want to implement caching at end. which of these 1000 chaching methods should I use, and implement that in classes or in the methods where I receive the data?
snarebold
A: 

First thing first... Enable Trace for your application and try to optimize Response size, caching and work with some Application and DB Profilers... By just looking at the code I am afraid no one can be able to help you better.

S M Kamran
ok Thank you. So there is no problem with static classes or a basic mistake of me?
snarebold
Static classes is not as bad.. Unless you maintain a good amount of static data in that. From your class it seems that you are returning Datasets for each method calls. You may be persisting this data in memory on your view but as far as this static class is concern it doesn't holds any data itself.
S M Kamran
So there is no question on how much space the code of your class takes when loaded its not even a consideration.
S M Kamran
+1  A: 

I suggest you try to profile your application and see where the bottlenecks are:

Slow load from the DB?

Slow network traffic?

Slow rendering?

Too much traffic for the client?

The profiling world should be part of almost every senior programmer. It's part of the general toolbox. Learn it, and you'll have the answers yourself.

Cheers!

Ron Klein
Thank you. Hmm. So I have to copy the whole project from our live server. or is it possible remote profiling?
snarebold
(1) maybe you have a staging / testing environment? (2) some profiling tools **can** work remotely, like MS SQL Profiler
Ron Klein
ok, I will copy it. Which tool you most like to test performance of the application?
snarebold
Profilers? hmm.. let's see.. Take a look at the profiling tag here at stackoverflow: http://tinyurl.com/y99jljs , you'd sure want to visit this .net profilers entry: http://tinyurl.com/yb2dx3c :-)
Ron Klein
+2  A: 

Bottlenecks usually come in a few forms:

  • Slow or flakey network.
  • Heavy reading/writing to disk, as disk IO is 1000s of times slower than reading or writing to memory.
  • CPU throttle caused by long-running or inefficiently implemented algorithm.

Lots of things could affect this, including your database queries and indexes, the number of people accessing your site, lack of memory on your web server, lots of reflection in your code, just plain slow hardware etc. No one here can tell you why your site is slow, you need to profile it.


For what its worth, you asked a question about your API architecture -- from a code point of view, it looks fine. There's nothing wrong with copying fields from one class to another, and the performance penalty incurred by wrapper class casting from object to Guid or bool is likely to be so tiny that its negligible.

Since you asked about performance, its not very clear why you're connecting class architecture to performance. There are really really tiny micro-optimizations you could apply to your classes which may or may not affect performance -- but the four or five nanoseconds you'll gain with those micro-optimizations have already been lost simply by reading this answer. Network latency and DB queries will absolutely dwarf the performance subtleties of your API.

In a comment, you stated "so there is no problem with static classes or a basic mistake of me". Performance-wise, no. From a web-app point of view, probably. In particular, static fields are global and initialized once per AppDomain, not per session -- the variables mCurrentCultureCode and mcurrentSiteName sound session-specific, not global to the AppDomain. I'd double-check those to see your site renders correctly when users with different culture settings access the site at the same time.

Juliet
Thank you! Informative. Thumb up.
snarebold