移动到 Azure Sql v12 后的 Webjob 错误

Webjob Errors since move to Azure Sql v12

每天凌晨 4 点,计划任务会在消息队列中创建大约 500 条消息。每条消息都是要发送的电子邮件的 ID。每条消息都被拾取并创建一个 url 并通过 await HttpClient.GetAsync(url) 发送 url 目标然后创建并发送电子邮件。这几个月来效果很好。

我刚刚升级到 SQL Azure v12,现在一切都不太好。

要处理的第一条消息(2 分钟后 运行 时间)抛出了

"System.Threading.Tasks.TaskCanceledException"

我也看到了

"System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached."

和几个

"The timeout period elapsed prior to completion of the operation or the server is not responding. This failure occurred while attempting to connect to the routing destination. The duration spent while attempting to connect to the original server was - [Pre-Login] initialization=6; handshake=426; [Login] initialization=0; authentication=0;"

向 api 发送请求的 Web 作业正在等待响应。我想知道 是否因为它是异步的,在等待响应时线程被释放并处理另一个队列项 - 因此创建另一个 api 请求,本质上这会命中 api 一次又一次,直到 api 正在处理如此多的请求,所有的广告都在使用 - 我最好不要让 webjob 异步,因为那样的话('trapped' thread) 只会在第一个请求完成后才发送请求?那正确吗?编辑:实际上 IIS 日志表明 api 请求并非同时发生。所以我的问题是 "what should I look at next? Are these common SQL v12 errors or is the recent upgrade a red-herring?"

澄清一下,为响应队列消息而触发的 Web 作业只是执行以下操作: using (HttpClient client = new HttpClient()) { response = await client.GetAsync(url); }

并访问 Always On 标准层 Azure 网站的网络 api。发生这种情况时,数据库 DTU % 约为 25%。

编辑:

"Gateway no longer provides retry logic in V12 Before version V12, Azure SQL Database had a gateway that acted as a proxy to buffer all interactions between the database and your client program. The gateway provided automated retry logic for some transient errors.

V12 eliminated the gateway. Now your program must more fully handle transient errors."

为 SqlAzureExecutionStrategy 添加 DbConfiguration class。那么今晚的运行情况如何。

添加 EF 重试配置 class 修复了暂时性错误。取消的任务是不同的问题(新问题)

//https://msdn.microsoft.com/en-us/data/jj680699
public class SqlAzureConfiguration : DbConfiguration
{
    public SqlAzureConfiguration()
    {
        this.SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
    }
}

在web.config中(因为我有多个上下文)

<entityFramework codeConfigurationType="Abc.DataService.SqlAzureConfiguration, Abc.DataService">