开发者

WCF Performance: Can I create a pool of my objects like ConnectionPooling does

开发者 https://www.devze.com 2022-12-18 14:39 出处:网络
I have a service that uses a fairly expensive object to create. I would like to improve the performance from call to call.

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 开发者_Python百科an object cache/pool and hand those objects to each invocation of the service.

Any thoughs/comments that may help this situation?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号