即使处于非活动状态,Hangfire也会继续运行SQL查询 [英] Hangfire keeps running SQL queries even when inactive

查看:210
本文介绍了即使处于非活动状态,Hangfire也会继续运行SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing an ASP.net 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.

显然,此问题是通过调整轮询间隔而引起的,并且已得到解决,请参阅

The issue is obviously caused - and remedied - by adjusting the polling interval, see the respective section of http://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查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆