RepDetec
RepDetec

Reputation: 751

.NET Web Service Poor Performance (using MVC3 thinking about switching to WCF)

I am working on building a .NET-Based web service where I pass in a string as part of the URL, and I return another string. The returned string is actually JavaScript.

Currently, I am using MVC3 for this service, because the requirements seemed very simple, and I did not see any reason to bring WCF into it. -Especially since I am just returning JS, and don't need any data wrapped up in XML or anything.

During initial load testing, the performance of the service seemed to be unacceptable (throughput of about 85/second). Since I am building JavaScript on-the-fly, and returning it, I decided to see what the performance would be if I simply returned some hard-coded JS. This doubled my performance (throughput of about 175/second). Nothing earth shattering, but it was about twice as fast. I expected this.

Then, for fun I decided to see how fast it would be to load test just pulling actual pre-generated JS files from IIS. This blew my mind. It was about 30 times faster (throughput of 2,200/second)! I expected pulling flat-files to be much faster than generating JS and then returning it, but this is so much faster, I am wondering if MVC3 is very slow, or if there is a problem with the server.

If I switch to WCF, will I see a significant throughput increase? Will WCF even let me return a string of JS (or does it expect everythigng to be wrapped up in XML)? If I need very fast response times, should I be using something besides WCF or MVC3?

Thanks

As I stated previously,

Upvotes: 1

Views: 406

Answers (4)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

You are complaining about performance but you don't show how did you test the performance and how do you build your JSON object. For performance testing be aware that ASP.NET (both WebForms and MVC) has synchronized processing when session state is enabled. It means only one request from the given user session can be processed at the time to ensure session state consistency. Check if the performance will increase if you turn off the session state for the controller.

Generally WCF will not increase throughput. It has probably even more complicated processing and if you want to use it for serving JSON you will most probably end up in allowing AspNetCompatibility which will in turn use the same processing pipeline you are using at the moment + some additional WCF stuff.

Also be aware that static files are cached.

Upvotes: 0

Dmitry S.
Dmitry S.

Reputation: 8503

If the generated JavaScript only depends on a few variables and is often the same, you can use an OutputCache attribute on the action method. VaryByParam property will allow you to have multiple cached copies for different variable values.

Upvotes: 1

Truong Hong Thi
Truong Hong Thi

Reputation: 384

Could it be that pre-generated JS files are cached at client side, so performance improves so much?

Upvotes: 0

Adam Tuliper
Adam Tuliper

Reputation: 30152

Pulling the files from iis is a completely different operation and allows extreme performance gains because of server file caching and no processing required. I don't think your wcf will be that different (yes you can return JavaScript) but it would be a simple perf test.

Upvotes: 0

Related Questions