简体   繁体   English

WCF一段时间不调用后需要时间继续调用

[英]WCF takes time to continue calls after not calling it for a certain period of time

I developed a WCF REST Api, which uses NHibernate as Persistence Layer.我开发了一个 WCF REST Api,它使用 Z111BBE34492093E9894EF9E8B 持久层。 I am currently using a Per-Session service, but have read that Per-Call services is the way to go on something like I am doing.我目前正在使用 Per-Session 服务,但已经读到 Per-Call 服务是 go 的方式,就像我正在做的那样。

There are 2 things (probably very related) I don't like and I wish to remove about it.有两件事(可能非常相关)我不喜欢,我希望删除它。

  1. On the first call to the api it takes like 20 seconds to respond, which may mean that it is loading the libraries and instanciating classes.在第一次调用 api 时,响应需要大约 20 秒,这可能意味着它正在加载库和实例化类。 Can I do this before any call takes place?我可以在打电话之前这样做吗? I already have an static constructor on the ServiceContract implementing class, but it is not diminishing the time for it to load.我已经在实现 class 的 ServiceContract 上有一个 static 构造函数,但这并没有减少它的加载时间。

  2. On subsequent calls, if I stop calling the service for about 10 minutes, the call time goes from 1 sec to over 20 seconds again.在随后的调用中,如果我停止调用该服务大约 10 分钟,调用时间再次从 1 秒变为超过 20 秒。 This is my biggest concern since the clients must have 30 seconds timeout which for the users it may look that the application has crashed.这是我最关心的问题,因为客户端必须有 30 秒的超时时间,这对于用户来说可能看起来应用程序已经崩溃。

How can I improve this?我该如何改进呢? Do you have any tips for improving the performance on these services?您对提高这些服务的性能有什么建议吗?

Seems like a clear case of IIS App Pool recycling, so it's reasonable to assume you are hosting this WCF service in IIS.似乎是 IIS 应用程序池回收的明确案例,因此可以合理地假设您在 IIS 中托管此 WCF 服务。

Several options:几个选项:

  1. Host the service outside of IIS (WCF can be hosted as a standalone Windows service)在 IIS 之外托管服务(WCF 可以作为独立的 Windows 服务托管)
  2. Adjust the app pool recycling frequency调整应用池回收频率

Try logging your Application_Start() and Application_End() to show times of your application start and stop.尝试记录您的 Application_Start() 和 Application_End() 以显示您的应用程序启动和停止的时间。 This can give you an idea if this is your problem.如果这是您的问题,这可以让您知道。

Also it may be a Session_Start/End type of thing too.它也可能是 Session_Start/End 类型的东西。

If you think your site will get busier, then your application stopping and starting all the time won't be such an issue.如果您认为您的站点会变得更加繁忙,那么您的应用程序一直停止和启动就不会成为这样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM