【问题标题】:Hangfire - Background job creation failed. See inner exception for detailsHangfire - 后台作业创建失败。有关详细信息,请参阅内部异常
【发布时间】:2016-12-14 05:42:44
【问题描述】:

我创建了一个hangfire作业作为`BackgroundJob.Enqueue(x => x.Recalculate(itemID));排队工作。当我尝试连续保存几次时,我从 Hangfire 收到以下错误。

这是堆栈跟踪,

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader)
   at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command)
   at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType)
   at Hangfire.SqlServer.SqlServerWriteOnlyTransaction.<>c__DisplayClass7_0.<SetJobState>b__0(SqlConnection x)
   at Hangfire.SqlServer.SqlServerWriteOnlyTransaction.<Commit>b__4_0(SqlConnection connection)
   at Hangfire.SqlServer.SqlServerStorage.<>c__DisplayClass17_0.<UseTransaction>b__0(SqlConnection connection)
   at Hangfire.SqlServer.SqlServerStorage.UseConnection[T](Func`2 func)
   at Hangfire.SqlServer.SqlServerStorage.UseTransaction[T](Func`2 func, Nullable`1 isolationLevel)
   at Hangfire.SqlServer.SqlServerStorage.UseTransaction(Action`1 action)
   at Hangfire.Client.CoreBackgroundJobFactory.Create(CreateContext context)
   at Hangfire.Client.BackgroundJobFactory.<>c__DisplayClass7_0.<CreateWithFilters>b__0()
   at Hangfire.Client.BackgroundJobFactory.InvokeClientFilter(IClientFilter filter, CreatingContext preContext, Func`1 continuation)
   at Hangfire.Client.BackgroundJobFactory.Create(CreateContext context)
   at Hangfire.BackgroundJobClient.Create(Job job, IState state)

异常消息:后台作业创建失败。有关详细信息,请参阅内部异常。(BackgroundJobClientException)

Inner Ex:执行超时已过期。在操作完成之前超时时间已过或服务器没有响应。

有人遇到过这个问题吗?这在本地运行良好。但问题发生在 Azure 部署中。我正在使用 v12 数据库。感谢任何帮助。我注意到我所有的hangfire作业创建平均需要20秒才能将后台作业排队。当我一次又一次地尝试创建工作时,它会超时。超时似乎是 30 秒。

我试图增加连接超时,但是无论我在连接字符串中输入的值是多少,它似乎在 30 秒后超时。但无论如何,增加超时并不能解决根本问题。

【问题讨论】:

  • SQL 数据库上的 DTU 使用情况图是什么样的?

标签: azure-sql-database hangfire


【解决方案1】:

我发现 DTU 的使用率大部分时间都是 100%,这是不可接受的,因为在我测试它的测试环境中没有发生任何事情。然后我查看了 Azure 数据库中的性能数据,这些数据给了我性能最差的查询,这真的很方便。 Handfire 删除作业查询导致了此性能问题。这是我们使用的 Hangfire 版本的问题。解决方案是将 Hangfire 升级到最新版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-21
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多