views:

225

answers:

4

The web app uses XML from a web service, which is then transformed to HTML using XSLT. The app uses a HttpModule to get the XML using AddOnPreRequestHandlerExecuteAsync.

Classes Used: XmlDocument - stores the xml. XslCompiledTransform - stores the transform, is cached in Application. Asynchronous HttpWebRequest using BeginGetResponse/EndGetResponse HttpModule with hooked AddOnPreRequestHandlerExecuteAsync events.

I do not want to use the XPathDocument unless there are no other possible optimizations. It would take some complicated code to get all the XML together without the ability to write to the XmlDocument. There is additional XML that does not come from the web service that must also be added to the document.

Any suggestions would be nice. The server doesn't seem to be having memory issues, if that is telltale of anything, just really high cpu usage.

Thanks.

UPDATE

After much searching I found that the issue causing the cpu to race was actually an infinite (or near) loop, which was not in my code at all, and hidden from my profiling due to the nature of where it was coming up. Lesson here, if it doesn't make sense, look for alternative reasoning for the issue before tearing your code apart.

A: 

What version of .NET? It's been a while since I've done anything with it XML/ XSL, but .NET 2.0 had some memory issues in XslCompiledTransform. While that could be the issue, it's more likely something in the code. Can you provide some sample XML and the XSL doc?

What happens if you save both out as static files and try to run the transform (create a small standalone script or unit test that just does this to see if it's an issue)? Make sure you're disposing of your XslCompiledTransform object as soon as you're done with it (and the XML doc as well).

When I run into issues with XSL transforms, I usually save a sample XML document and apply my XSL in Cooktop. It's a little hard to figure out at first, but it's a good sanity check to make sure you don't have a glaring error in your XSL.

Tom
What do you mean by dispose of the XmlDocument and Transform after I'm done using it? The transform is cached for later use (it is used over and over again). I don't specifically do anything with the document after use though, should I set it to null?
aepheus
Yes, set = null is what I meant by dispose of it. Maybe I'm out of date/ out of practice, but while you may be caching the transformed document, the object that you do the transforming with can be disposed of once it's no longer needed, can't it?
Tom
A: 

Consider using Linq to XML to do the transformation - 350 kB is a large text/xml document from a transformation standpoint - it might be faster than an XSLT tranformation. See here for a sample.

Obalix
A: 

Is the web service on the same server? If so, does testing the service by itself show high CPU usage?

How are you putting the transformed document into cache?

Jonathan
The transformed documents cannot be cached, they are user specific at that point.The web service is within the network, but not on the same server.
aepheus
But "...XslCompiledTransform - stores the transform, is cached in Application...."
Jonathan
The xml transforms are on the same server and don't come from a web service, the data xml comes from a different server. Sorry for any confusion
aepheus
A: 

Try to user a Profiler. DotTrace and ANTS have trial versions. This should make you able to pin point your problems. (The nice thing about dotTrace is, that it integrates with unit tests.)

Robert