简体   繁体   English

asp.net无限循环-可以做到吗?

[英]asp.net infinite loop - can this be done?

This question is about limits imposed to me by ASP.NET (like script timeout etc'). 这个问题是关于ASP.NET给我的限制(例如脚本超时等)。

I have a service running under ASP.NET and I want to create a counterpart service for monitoring. 我有一个在ASP.NET下运行的服务,我想创建一个用于监视的对等服务。

The main service's data is located at a database. 主服务的数据位于数据库中。
I was thinking about having the monitor service query the database in intervals of 1 second, within a loop, issued by an http request done by the remote client. 我正在考虑让监视服务在一个循环内以1秒的间隔查询数据库,该循环由远程客户端执行的http请求发出。
Now the actual serving of this monitoring will be done by a client http request, which will make the script loop (written in C#) and when new data is detected it'll aggregate that data into that one looping request output buffer, send it, and exit the loop, thus finishing the request. 现在,此监视的实际服务将由客户端http请求完成,这将使脚本循环(用C#编写),并且在检测到新数据时,它将把该数据聚合到该循环请求输出缓冲区中,然后将其发送,并退出循环,从而完成请求。
The client will have to issue a new request in order to keep getting updates. 客户端将不得不发出新请求,以保持更新。

This is actually exactly like TCP (precisely like Windows IOCP); 实际上,这和TCP完全一样(与Windows IOCP一样)。 You request the service for data and wait for it. 您向服务请求数据并等待它。 When it arrives you fire another request. 到达后,您会触发另一个请求。

My actual question is : Have you done it before? 我的实际问题是 :您以前做过吗? How did it go? 怎么样了 Am I limited by some (configurable) limits imposed by the IIS/ASP.NET framework? 我是否受到IIS / ASP.NET框架施加的某些(可配置)限制的限制? What are my limits in such situation , or, what are better options without complicating things too much ? 在这种情况下我有什么限制? 或者,在不使事情变得过于复杂的 情况下更好的选择是什么

Note that I do not expect many such monitoring requests at a time, maybe a few dozens. 请注意,我预计一次不会有很多这样的监视请求,也许是几十个。
This means however that 10 such concurrent monitoring requests will keep 10 threads busy, and the question is; 但是,这意味着10个此类并发监视请求将使10个线程处于繁忙状态,问题是; Can it hurt IIS/performance? 它会损害IIS /性能吗? How will IIS handle 10 busy threads? IIS将如何处理10个繁忙线程? Will it issue more? 它会发行更多吗? What are the limits? 有什么限制? This is just one example of a limit I can think of. 这只是我能想到的一个限制示例。

I think you main concern in this situation would be timeouts, which are pretty much configurable. 我认为在这种情况下,您最关心的是超时,超时几乎是可配置的。 But I think that it is a wrong solution - you'd be better of with some background service, running constantly/periodically, and writing the monitoring data to some data store and then your monitoring page would just return it upon request. 但是我认为这是一个错误的解决方案-最好使用一些后台服务,该服务不断/周期性地运行,并将监视数据写入某些数据存储中,然后监视页面将根据请求将其返回。

if you want your page to display something only if the monitorign data is available- implement it with ajax - on page load query monitoring service, then if some monitoring events are available- render them, if not- sleep and query again. 如果您希望页面仅在Monitorign数据可用时显示某些内容-使用Ajax实施-在页面加载查询监视服务中,则如果某些监视事件可用-呈现它们,如果不休眠-再次查询。

IMO this would be a much better solution than a reallu long running requests. 与长期运行的请求相比,IMO将是一个更好的解决方案。

I think it won't be a very good idea to monitor a service using ASP.NET due to the following reasons... 我认为使用ASP.NET监视服务不是一个好主意,原因如下:

  1. What happens when your application pool crashes? 当您的应用程序池崩溃时会发生什么?

  2. What if you decide to do IISReset? 如果您决定进行IISReset怎么办? Which application will come up first... the main app, or the monitoring app? 主应用程序或监视应用程序将首先出现哪个应用程序?

  3. What if the monitoring application hangs due to load? 如果监视应用程序由于负载而挂起怎么办?

  4. What if the load is already high on the Main Service. 如果主服务上的负载已经很高怎么办。 Wouldn't monitoring it every 1 sec, increase the load on the Primary Service, as well as IIS? 难道不是每1秒钟监视一次,是否会增加主服务以及IIS的负载?

You get the idea... 你明白了...

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

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