ASP.NET 网站在处理长进程时没有响应
当我的应用程序面临长时间的处理时,即获取查询(SELECT a, b, c FROM d) 此查询需要 10 秒才能在 MSSQL Management Studio 中完成,但是当 ASP.NET 应用程序尝试获取它时,它拒绝返回对该服务器上发出的任何其他请求的任何响应。
我在具有良好规格的 VPS 服务器上托管我的应用程序,我给出的示例(从 d 中选择 a、b、c)只是为了告诉您问题,它可以是任何进程,可能处理电影,甚至获取一些通过外部 API 获取的数据正在经历一些缓慢的情况,或者其他什么情况。
任何帮助或建议将不胜感激。
When my Application face a long-time process, i.e fetch a query (SELECT a, b, c FROM d)
This query needs 10 seconds to be completed in the MSSQL Management Studio, but when the ASP.NET application try to fetch it, it refuse to return any response to any other requests made on that Server.
I am hosting my Application on VPS Server with good specifications, and I am giving this example the (SELECT a, b, c FROM d) just to tell you the issue, it can be any process, maybe processing a movie, or even fetching some data through external API that is experiencing some slow-down,or whatever.
Any help or suggestions would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我强烈建议您熟悉 Sql Server Studio 附带的 Sql Profiler。
启动它,看看有什么数据传入/传出您的 sql 服务器以及持续多长时间。
您是否收到任何异常或只是超时?
你能单步执行代码吗?
它是本地服务器(您的机器)还是其他机器? (可能是网络连接问题)
i highly recommend that you familiarize yourself with Sql Profiler that comes with Sql Server Studio.
Launch it, and see what goes to/from your sql server and for how long.
do you get any exceptions back or just timeout?
can you step through the code?
is it a local server (your machine) or some other machine? (possible could be network connectivity issues)
当您在某个页面上进行调用时,该页面将使用其中一个应用程序池来获取数据。如果此调用需要 10 秒才能完成,则此池将在此请求上堆栈。
为了避免这种情况,我可以建议一些方法。
您可以使用多个应用程序池。然而,在这种情况下,您将面临一些其他问题,为了解决这些问题,您必须在程序的某些部分使用互斥锁,因为您将面临多线程同步问题,
您可以使用线程与页面并行运行,并创建一个线程进程,释放页面,然后进行一些重新获取结果...或者使用任何其他线程技巧来释放池的处理。
你可以优化你的sql 10秒来运行一些东西,时间太长了。在我的程序中,唯一需要花时间完成的路由是一些统计计算。我让它们在后台运行,缓存结果,然后在它们请求时显示结果。
希望这对您有帮助。
When you make a call on a page, then this page is use one of the application pool to get the data. If this call is make 10 seconds to complete then this pool is stack on this request.
To avoid this stop, I can suggest some ways.
You can use more than one application pool. How ever in this case you going to face some other problems and for solve them you must use mutex in some parts of your program, because you going to face muthithread synchronize issues,
You can use threads to run paraller with the page, and make a thread process, and release the page, and then make some refress to get the results... or make any other thread tricks to release the pool from processing.
You can optimize your sql 10 seconds to run somthing is too much time. In my programs the only routing that take this time to compliete is some statistics calculations. I make them run on background, cache the results, and then just show the results when they request for.
Hope this help you.