【问题标题】:GatewayTimeout issue running stored procedure in logic app在逻辑应用程序中运行存储过程的 GatewayTimeout 问题
【发布时间】:2020-06-29 07:21:19
【问题描述】:

我们在使用 Azure 逻辑应用服务和 SQL 数据库同时运行三个存储过程 (SP) 时遇到问题。

无论 SP 的运行顺序如何,问题总是出现在第一个运行的 SP 中。

处理最初需要几秒钟才能成功运行和执行,但我们注意到执行时间和所需的 DTU(数据库吞吐量单位)每天都在增加。

其中一个 SP 使用按日期过滤表 TABLE1 的变量,并仅显示 TABLE2 中的“当前日期”数据。过滤器变量(在 SP 中使用)在逻辑应用程序中定义为 SUBSTRING(startOfDay(utcNow()), 0, 10),它返回当前日期值。

我们的代码仅包含过滤当天TABLE1 的值,将其放入TABLE2,对其运行一些计算并将结果存储回TABLE1。在 SP 代码中使用了 WITHLast_ValueFirst_ValueINSERT 函数。 INSERT 函数用于将生成的行插入到TABLE1(大约 74 行)中。

TABLE1中记录的数据行数每天都在增加,但TABLE2中的数据行数是恒定的,因为它是过滤“当天”的结果,所以它只显示当天的值。

使用 SQL Server Management Studio,可以毫无问题地手动执行 SP。

一开始,当我们的数据库 DTU 设置为 400 时,第一个 SP 的 Logic App 执行时间不到 10 分钟,而其余两个 SP 每个都需要几秒钟。

最近第一个 SP 执行失败,出现 GatewayTimeout 错误,逻辑应用执行失败:

当我们将 DTU 增加到 800 时,逻辑应用程序运行成功,但我们仍然收到 GatewayTimeout 的警告。

检查了与数据库的连接,测试了每个单独 SP 的手动执行,过滤器变量数据类型从 datetime 更改为 varchar(与逻辑应用参数匹配),但是问题不断发生。

如果不解决,这个问题可能会再次发生。有什么建议吗?

谢谢。

更新

这是一个SP的代码:

WITH enTotTable 
AS 
  (
    SELECT --TOP(100)
        se.id
        , se.gatewayName
        , se.deviceId
        , se.ts
        , se.pointNameId

        , case 
            when se.presentValue < 0 then 0 else se.presentValue end as presentValue
        , DATEPART(hh,se.ts) as hTs
    FROM dbo.SolarEnergyTable se
    WHERE se.gatewayName IN ('DPJW', 'DAN1') and se.pointNameId = 7 and not se.presentValue = 0 and se.ts >= @tsFilter
  ) 


, calculationTable AS
  (

    SELECT distinct
            FORMAT ( tot.ts , 'yyyy-MM-dd' ) as dayTs
            ,tot.deviceId
            ,tot.gatewayName

            , CASE 
                WHEN  Last_VALUE(tot.hTs) OVER(partition by tot.deviceId, DATEPART(dd, tot.ts)
                    ORDER by tot.hTs ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) 
                    - FIRST_VALUE(tot.hTs) OVER(partition by tot.deviceId, DATEPART(dd, tot.ts)
                    ORDER by tot.hTs ) >=12 
                then 1 
                Else NULL end as ifAllDay

            , CASE 
                WHEN  Last_VALUE(tot.hTs) OVER(partition by tot.deviceId, DATEPART(dd, tot.ts)
                    ORDER by tot.hTs ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) 
                    - FIRST_VALUE(tot.hTs) OVER(partition by tot.deviceId, DATEPART(dd, tot.ts)
                    ORDER by tot.hTs ) >=12 
                then (LAST_VALUE(tot.presentValue) OVER(partition by tot.deviceId, DAY(tot.ts)
                        ORDER by tot.deviceId desc, tot.ts
                        ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) 
                    - FIRST_VALUE(tot.presentValue) OVER(partition by tot.deviceId, DAY(tot.ts)
                        ORDER by tot.deviceId desc, tot.ts) )
                else NULL 
                end as enTdy

            ,case 
                when LAST_VALUE(tot.presentValue) OVER(partition by tot.deviceId, DAY(tot.ts)
                    ORDER by tot.deviceId desc, tot.ts
                    ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) < 0 then NULL

                else  
                    LAST_VALUE(tot.presentValue) OVER(partition by tot.deviceId, DAY(tot.ts)
                    ORDER by tot.deviceId desc, tot.ts
                    ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) 
                end as lastPvalueDay
            , case 
                when FIRST_VALUE(tot.presentValue) OVER(partition by tot.deviceId, DAY(tot.ts)
                    ORDER by tot.deviceId desc, tot.ts
                    ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) < 0 then NULL

                else 
                    FIRST_VALUE(tot.presentValue) OVER(partition by tot.deviceId, DAY(tot.ts)
                    ORDER by tot.deviceId desc, tot.ts) 
                end as firstPvalueDay            
    FROM enTotTable tot 
    WHERE not tot.presentValue = 0 
  )

, plantAndTdyTable 
AS
(   
    SELECT 
        tdy.gatewayName
        ,tdy.dayTs as ts
        ,CAST(2 as INT) as deviceId
        , CAST(20 as INT) as pointNameId
        , Case When 
            tdy.ifAllDay = 1 
            then SUM(tdy.lastPvalueDay)-SUM(tdy.firstPvalueDay)
            else NULL end as presentValue
    FROM calculationTable tdy
    GROUP BY tdy.dayTs ,tdy.ifAllDay, tdy.gatewayName
 UNION

    SELECT 
        tdy.gatewayName
        ,tdy.dayTs as ts
        ,CAST(2 as INT) as deviceId
        , CAST(17 as INT) as pointNameId
        ,SUM(tdy.lastPvalueDay) as presentValue
    FROM calculationTable tdy
    GROUP BY tdy.dayTs, tdy.gatewayName
 UNION


    SELECT 
        tdy.gatewayName
        , tdy.dayTs as ts
        , tdy.deviceId
        , CAST(6 as INT) as pointNameId
        , tdy.enTDY as presentValue
  From calculationTable tdy
  
)


INSERT INTO [dbo].[SolarEnergyTable]
SELECT 
    pt.gatewayName
    ,pt.ts
    ,pt.deviceId
    ,pt.pointNameId
    ,pt.presentValue
FROM plantAndTdyTable pt



-- SELECT *
-- From
-- plantAndTdyTable
-- -- calculationTable
-- -- enTotTable

【问题讨论】:

  • 您好 Jojoe,欢迎来到该网站。您必须至少显示导致问题的 SP 的代码。请在问题底部发布代码。用户更有可能回答包含代码的问题。谢谢。
  • 嗨@Sabuncu 谢谢你的消息。我更新了一个SP的代码。

标签: azure stored-procedures azure-logic-apps bad-gateway


【解决方案1】:

请看下面的回答here

我使用azure logic app stored procedure taking too long找到它。

【讨论】:

  • 感谢您的回答。所以除了增加逻辑应用程序的退出时间外,我无能为力
  • @Jojoe 好吧,这只是一种解决方法。 Azure 专家会知道速度变慢的原因。您是否尝试过联系 Azure 支持?我发现它们在 Twitter 上非常有用:twitter.com/…
【解决方案2】:

我终于改变了我的架构来运行我的 SP。为了避免 Logic 应用程序在需要连接到数据库时出现 GatewayTimeout,我使用了 azure 自动化帐户。我创建了一个 PowerShell 脚本来运行我的 SP,并使用逻辑应用程序来运行 PowerShell 脚本。在我的情况下效果更好。

【讨论】:

    猜你喜欢
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 2020-02-02
    • 1970-01-01
    • 2016-11-18
    • 2023-04-06
    • 2021-08-09
    • 2011-11-04
    相关资源
    最近更新 更多