views:

42

answers:

2

I have a service that uses a fairly expensive object to create. I would like to improve the performance from call to call.

When I remove the object and run a load test, like how many invocations I can do per second, I have a massive performance difference between to situations.

Situation 1. I remove the expensive object: Invocations per sec ~= 130. Situation 2. I use it as normal, with the object: rate is ~= 2 per sec.

I have a .NET WCF service hosted on an IIS 2008 server.

I was wondering if there was a way I could create an object cache/pool and hand those objects to each invocation of the service.

Any thoughs/comments that may help this situation?

+1  A: 

You could run the WCF service in per session mode and create the object using the singleton pattern, that way you only create the object once per session, as opposed to once per call.

You may also be able to cache the objects using enterprise libray caching.

Shiraz Bhaiji
Changing access to the expensive object (in this case a Castle dynamic proxy) to a static reference solved the problem.
Karl Easterly
A: 

If the expensive part is building the State of the object, and you only want to limit the number of times that you create that object, I suggest using a Durable Service.

A Durable WCF component persists its state between calls and between clients. Each time you call a method it writes its state to a persistence store (the default is a sql server database). The catch is you have to pass around a context token between whoever is going to call your Durable component. This token could be persisted in a file or database or whatever.

This would allow you to make a call against the component, it could create its state one time and then you could keep calling it from other clients as long as they have access to its context token.

Nothing hangs around in memory since the object goes away each time your client closes, but the state persists.

Here's a tutorial.

Terry Donaghe