即使处于非活动状态,Hangfire也会继续运行SQL查询

编程入门 行业动态 更新时间:2024-10-20 00:31:52
本文介绍了即使处于非活动状态,Hangfire也会继续运行SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个ASP MVC 5网站,并且使用Hangfire计划一些任务,在这种情况下,每3分钟仅执行一次.我知道一个事实,即仅需几秒钟即可运行此类任务(以及与之关联的数据库查询).

I'm developing an ASP MVC 5 web site and I'm using Hangfire for scheduling some tasks, in this case just one every 3 min. I know for a fact that it takes only a few seconds to run such task (and the DB query associated with it).

我面临的问题是,好像Hangfire的SQL Server正在运行"(不知道是什么)(我不知道是什么),并且在SQL Server活动监视器中可以看到我的CPU始终保持在20+使用率百分比,并且数据库I/O操作的速度为(平均1.2 MB/秒).我知道它是Hangfire,因为当我不对其进行初始化时,活动监视器(和任务管理器)不会显示任何额外的开销.我什至已经删除了所有计划的任务以及Hangfire可以运行的任何/一切,但问题仍然存在.

The problem I'm facing is that it seems as if Hangfire has my SQL Server running "something" (I don't know what) and I can see in the SQL Server Activity Monitor that my CPU stays always at 20+% usage and there are Database I/O operations at (1.2 MB/sec average). I know it is Hangfire because when I don't initialize it the Activity Monitor (and Task Manager) shows no extra overhead. I have even gone as far as to remove all scheduled tasks and anything/everything that Hangfire can run and still the problem persists.

我不能像这样去量产,因为我担心这可能会导致性能问题.任何帮助将不胜感激,在此先感谢

I can't go to production like this for I fear it may cause performance issues. Any help will be most appreciated, thanks in advance

推荐答案

我在自己的带有MVC应用程序+ hangfire的服务器上对此进行了一些调查.确实,我的CPU使用率也是20-25%.因此,我搜索了一个合适的监控器应用程序,安装了一个名为"SQLRanger"的漂亮小工具,发现到目前为止最热门的查询是:

I investigated this a bit on my own server with MVC app + hangfire. Indeed my CPU usage is at 20-25% too. So I searched for a suitable monitor app, installed a nifty little tool called "SQLRanger" and found that the top query by far is this:

update top (1) HangFire.JobQueue set FetchedAt = GETUTCDATE() output INSERTED.Id, INSERTED.JobId, INSERTED.Queue where FetchedAt is null and Queue in (@queues1)

因此,基本上,这是进行等待执行的作业的hangfire检查.到目前为止,我还没有遇到任何性能问题或滞后.

So it is basically hangfire checking for jobs waiting to be performed. So far I haven't encountered any performance issues or lags though.

显然,此问题是通过调整轮询间隔而引起的,并且已得到解决,请参阅 docs.hangfire.io/en/latest/configuration/using-sql-server.html

The issue is obviously caused - and remedied - by adjusting the polling interval, see the respective section of docs.hangfire.io/en/latest/configuration/using-sql-server.html

默认间隔为15秒,这确保了对作业的及时处理以及恒定的服务器负载.在非时间紧迫的应用程序中,应该有一个较大的间隔(1分钟,5分钟等). 知道您需要什么并对它作出反应:需要立即进行作业处理或服务器负载低吗?如果是前者,则将时间间隔保持较短,并在需要时考虑升级服务器;如果是后者,则将间隔增加到可接受的最大最小值.

The default interval is 15 seconds, which ensures prompt processing of jobs but also constant server load. In non-time-critical applications a higher interval (1 min, 5 mins etc) should be OK. Know what you need and react to it: need near immediate job-processing or low server load? If the former, keep the interval short and think about upsizing the server if needed; if the latter, increase the interval to the highest acceptable minimum.

我需要前者,并将密切关注服务器是否可以承受负载.

I need the former and will keep an eye on the server whether it can bear the load.

更多推荐

即使处于非活动状态,Hangfire也会继续运行SQL查询

本文发布于:2023-11-13 00:20:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也会   状态   Hangfire   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!