WCF 服务 - 在启动时创建多个实例?
抱歉,如果之前有人问过这个问题,但我已经搜索过,但找不到答案
我们有一个 WCF 服务,最多可提供 100 个实例 - 因为有 10,000 个客户端,但调用速度非常快。
我们注意到的唯一性能开销是在第一次调用实例时...例如,第一次调用任何实例(或回收后),与任何其他调用相比,都会有明显的延迟。
有没有办法在 IIS 启动时“启动”100 个实例?从而消除这种开销?
有没有办法找出服务上当前有多少实例“活动/实例化”?
非常感谢, 戴夫.
Apologies if this has been asked before, but I've searched and can't find an answer
We have a WCF service that provides upto 100 instances - as there are 10,000 clients but the calls are very quick.
The only performance overhead we've noticed is on the first call to an instance...e.g. the first time any of the instances is called (or after recycling) there is a noticeable delay, compared to any other calls.
Is there any way to "fire up" 100 instances on IIS startup? Thus removing this overhead?
Is there a way to find out how many instances are currently "active/insantiated" on a service?
Many thanks,
Dave.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
启动后,您可以通过服务器的远程接口提供服务。
或者,如果您使用自定义托管,您可以在服务器启动时将服务类的实例传递给 ServiceHost。
如果您在 IIS 中托管,那么您将需要一个 CustomHostFactory。这里有一篇关于如何执行此操作的相当好的文章。 http://msdn.microsoft.com/en-us/library/bb332338。 .aspx.
在跟踪实例方面,您可以只增加/减少服务类中的引用计数。
you could the service via remote interface from the server after startup.
Or perhaps you can pass an instance of the service class to the ServiceHost on server startup if you are using custom hosting.
If you are hosting within IIS then you'll need a CustomHostFactory. There is a fairly good article on how to do this here. http://msdn.microsoft.com/en-us/library/bb332338.aspx.
In terms of keeping track of instances, then the you could just increment/decrement a reference count within the service class.
如果您在IIS 7.5上托管,您一定应该查看应用程序预热模块。
If you are hosting on IIS 7.5, you should definitely check out the Application Warmup Module.
应用程序启动时无法启动 100 个实例。仅当您拥有单例服务=所有请求的一个实例时,才有可能。您的场景使用每次调用实例化,因此每次客户端调用服务时都会创建实例,并在处理调用后释放实例。
要预热您的应用程序,请使用 Enrico 建议的模块。如果您不使用 IIS 7.5,您还有另一个选择。创建自定义控制台应用程序来 ping 您的服务。在 Windows Scheduler 中安排此应用程序。
要跟踪正在运行的实例数量,您可以使用性能计数器。我不确定 WCF 是否提供了这样的开箱即用的计数器,但您始终可以创建自己的计数器并在自定义 ServiceHost 类中使用它。
You can't fire up 100 instances when application start. It is possible only when you have singleton service = one instance for all requests. Your scenario uses per call instancing so instance is created each time the client calls the service and disposed after processing call.
To warm up your application use module Encrico suggested. If you don't use IIS 7.5 you have another option. Create custom console application to ping your service. Schedule this application in Windows Scheduler.
To track number of running instances you can use performance counters. I'm not sure if WCF provides such counter out of the box but you can always create your own counter and work with it in custom ServiceHost class.