Posted By: Apogeum | May 22nd, 2008 @ 6:19 AM
page 1 of 1
Comments: 15 | Views: 1298
I am experiencing major performance issues wthin my web application. And I am concerned about my coding practices.

Counter: Processortime spikes up to 60% wihin one request. In production it reaches up to 80 or 90%.


Concern 1: I am using very long ENUMs (one has over 300 entries)

Concern 2: I am storing rather big structs within hashtables (again several hundred entries in one hashtable)
 
Concern 3: I am using StringBuilder A LOT!

Concern 4: I am collecting the output of the entire page and transforming it with one big xsl document


Please let me know what you think!








AW
AW
The 01.

Concern 1: I don't think that's a problem, isn't enums replaced by their int values at the end?

Concern 3: That is good if you're using StringBuilder for a text which requires lots of manipulation. If you are using it to concat 2 strings - well I don't think it is a best practice (-. BTW, use StringBuilder constructor which takes initial capacity value and set it to a predictable value as this will remove some overheat when expanding its' internal buffer.

Concern 4: I can't say much, but I was working one the project of similar internals, e.g. creating XML document to represent website and then uses XSL transformation for a final xhtml. It was working and was working fast.

Concern 2: maybe using typer dictionaty would be better, o maybe you can use some other caching mechanism?

Apogeum wrote:
Concern 1: I am using very long ENUMs (one has over 300 entries)
well that can't cause serious performance issues you have, the compiler translate a enum to a class where every enumeration is a const field, but it's definitely bad practice to make so big enums, depending on your data you could store it on a database or hardcode it somehow else

Apogeum wrote:
Concern 2: I am storing rather big structs within hashtables (again several hundred entries in one hashtable)
what you are using as a key? a string or a complicated structure? hashing a big structure may take some time if you use that structure as your key, you could post more details about this one, maybe you could find a more suitable data structure
 
Apogeum wrote:
Concern 3: I am using StringBuilder A LOT!
good for you, I don't know why but "a lot" terrifies me, what are you doing exactly?

Apogeum wrote:
Concern 4: I am collecting the output of the entire page and transforming it with one big xsl document
well that depends on how big your page is and what transformation are you doing...

I suggest to use a profiler and see where performance gap is, Visual Studio 2005 Team Suite/2008 Professional has one
W3bbo
W3bbo
The Master of Baiters
Apogeum wrote:
I am experiencing major performance issues wthin my web application. And I am concerned about my coding practices.

Counter: Processortime spikes up to 60% wihin one request. In production it reaches up to 80 or 90%.


Concern 1: I am using very long ENUMs (one has over 300 entries)

Concern 2: I am storing rather big structs within hashtables (again several hundred entries in one hashtable)
 
Concern 3: I am using StringBuilder A LOT!

Concern 4: I am collecting the output of the entire page and transforming it with one big xsl document


Please let me know what you think!


Run the ASP.NET Tracer to identify bottlenecks in your code. Also, if you're running off a 400Mhz box, that also bumps CPU a bit.

As for writing to your own internal buffer then XLS-transforming it, that's probably the problem. Why can't you use client-side XSLT, or generate the right XML in the first place. Are you implementing the MVC pattern?
Not having seen the code I can't really say, but creating a new string builder for each recursion doesn't seem to be the best option to me, this would be wasting a lot of memory space both on the stack and the heap. This might be the source to the bad performance if a LOT of instances are created, the GarbageCollector has to work full time and during a garbage collection nothing else can run, so all requests are halted.
figuerres
figuerres
???
Apogeum wrote:


Concern 2: I am storing rather big structs within hashtables (again several hundred entries in one hashtable)
 


"storing" How?  in a DB?  in a session var?

as in is your hashtable just a local class var or is it a Session[] var ??

also are you seeing the perf issue as one client hit's the server or when many are hitting the server ?

as other said It seems like you may want to re-work the XML and string builder stuff to use the .net xml classes. that might help a lot.

also if you are recusing are the string builders emiting a string when you exit ??

if you have say 10,000 string builders emiting strings that you then re-combine then you are losing much of the benefit of the string builder.... and generating a lot of string garbage to clean up.
Curt Nichols
Curt Nichols
No Silver Bullet
Apogeum wrote:
Please let me know what you think!


I think you should put a profiler on it. Why are you guessing at possible causes when you get get hard data on your app's performance characteristics? Smiley
ZippyV
ZippyV
Fired Up
Apogeum wrote:
Concern 4: I am collecting the output of the entire page and transforming it with one big xsl document


This is probably your biggest bottleneck. Transforming xml is a very expensive process.
figuerres
figuerres
???
Apogeum wrote:

Hashtables:

I am using strings as keys. the values are structs.
The plan was to store the structs within the cache but I had problems with that:

in the production environment it lost values (for no apparent reason).

since there wasn't enought time to investigate I switched to the hashtable.


I would prefer cache tough.



WOW... missed that before....

BIG TIME ISSUE SHOWN HERE!

PLEASE READ the docs about how ASP.NET works!

Cache is like a memory pool, the way it is designed is to hold data for a limited time.
Cache will get flushed when:

a) the item "times out"

b) the system needs RAM to process other tasks

c) you clear the item

d) the system re-cylces the IIS/ASP.Net Process


from all that has been posted b and or d are happening to your app.

how many users/requests?  how much ram does the server have?
how much ram is each request using?

I bet your app is grabiing a ton of ram and / or the cpu % is to high wich will cause IIS to re-start / cycle your app.
are users losing pages?  getting errors? timeouts?

thats one of the side efects of a re-start ....

aside from other things you might want to look at re-designing the app to not be so bound to asp.net.

for example:  build a seperate windows service that gets a "request" from a database record, processes the request and then saves the results.

then have the web app store the new request and give the user a way to check back and get the results of the processing.

that way you can stack up as many requests as you want and not have users sitting with a session open waiting for output.
and your app will leave iis / aps.net at a much nicer level of use.

then you can do the other work in the background of the web server or if you need to you can setup 1 or more servers to just crunch the data as fast as you need it.

also a single pass may not be the "optimal" way to process the data.
you might save a huge amount of ram by just doing the job in more than one pass...

do not assume that the only tool is a Hammer, not all problems are Nails....
more than one way to solve a problem.

web servers are *NOT* the best way to do long complex jobs.

BlackTiger
BlackTiger
If you stumbled and fell down, it doesn't mean yet, that you're going in the wrong direction.
Apogeum wrote:
I am experiencing major performance issues wthin my web application. And I am concerned about my coding practices.

Counter: Processortime spikes up to 60% wihin one request. In production it reaches up to 80 or 90%.


Concern 1: I am using very long ENUMs (one has over 300 entries)

Concern 2: I am storing rather big structs within hashtables (again several hundred entries in one hashtable)
 
Concern 3: I am using StringBuilder A LOT!

Concern 4: I am collecting the output of the entire page and transforming it with one big xsl document


Please let me know what you think!

 
Wow! Looks like disaster by design...
Do you know a word "database"?
Apogeum wrote:

I am building the structure with a recursion, so the StringBuilders are created within each recursion.


Recursion is bad, m'kay. Recursive algorithms can always be re-written to be iterative.

In addition to what everyone else has said....
W3bbo
W3bbo
The Master of Baiters
AndyC wrote:

Apogeum wrote:
I am building the structure with a recursion, so the StringBuilders are created within each recursion.


Recursion is bad, m'kay. Recursive algorithms can always be re-written to be iterative.


BURN THE HERETIC!
TommyCarlier
TommyCarlier
I want my scalps!
Long live GOTO! *runs*
figuerres
figuerres
???
AndyC wrote:

Apogeum wrote: 
I am building the structure with a recursion, so the StringBuilders are created within each recursion.


Recursion is bad, m'kay. Recursive algorithms can always be re-written to be iterative.

In addition to what everyone else has said....


No recursion is a good thing when it's used well.

just that you need to know what it's good for and what the trade offs are speed,time,ram,code complexity and so forth.

and the different ways to handle things ....

loop unrolling, tail recusion and other stuff can be usefull or harmfull if not understood and tested.....

like picking a sort ....  qsort is good but for a small array a simple bubble sort might be the "best choice" while in other cases a shell sort may be the one to use.....

it's all a mater of having the tools and knowing how and when and where to use each one.
page 1 of 1
Comments: 15 | Views: 1298
Microsoft Communities