Skip to content

服务调用的超时问题 Some issues with service timeout #1968

Closed

Description

@baigod

dubbo version: 2.5.6

issues code 1

@Component
public class ConsumerA {

    @Reference(version = "1.0.0",retries = 0, timeout = 180000)
    public ProviderB providerB ;

    public void a(){
        try{
            providerB.b(); 
        }catch(Exception e){
            // do something
        }
    }

}

@Service(version = "1.0.0")
public class ProviderB {

    public void b(){ 
        try{
            Thread.sleep(10000); //休眠10秒为了模拟程序执行缓慢
        }catch(Exception e){
        }
    }

}

使用场景,当B服务提供者需要紧急重启的情况下:
此时,B宕机,如何让a()立即捕获到异常信息,而不用等待3分钟才返回,如果大量并发请求在请求中,将可能造成A服务大量请求堆积。这个是否有更友好的办法去处理,或者,我的配置并不完善。
Usage Scenarios When the B Service Provider Needs an Emergency Restart:
At this point, B crashes, how to make a() immediately capture exception information without waiting for 3 minutes to return. If a large number of concurrent requests are in the request, it may cause a large number of A service requests to be accumulated. Is there a more friendly way to deal with this, or my configuration is not perfect.

issues code 2

@Component
public class ConsumerA {

    @Reference(version = "1.0.0",retries = 0, timeout = 3000)
    public ProviderB providerB ;

    public void a(){
        updateSomeRows(); //更新某行数据
        try{
            providerB.b(); 
        }catch(Exception e){
            throw new XXException();
        }
    }

}

@Service(version = "1.0.0")
public class ProviderB {

    public void b(){ 
       insertRow();  //插入某行数据
        try{
            Thread.sleep(10000); //休眠10秒为了模拟程序执行缓慢
        }catch(Exception e){
        }
    }

}

使用场景,当B服务提供者遇到数据库性能瓶颈(updateSomeRows()执行缓慢):
此时,A捕获超时异常,a()的事务因异常回滚,但是B的数据已插入,这是不符合预期的。请问怎么简单优雅地处理这样的问题(不考虑使用分布式事务的情况下)。
Usage scenario, when B service provider encounters a database performance bottleneck (execution of updateSomeRows() is slow):
At this point, A capture timeout exception, a () transaction rollback due to anomalies, but B's data has been inserted, which is not in line with expectations. How to handle such problems simply and gracefully (not considering the use of distributed transactions).

Activity

  1. baigod commented on Jun 25, 2018

    @baigod
    Author
  2. wanglei-sky commented on Jun 29, 2018

    @wanglei-sky

    顶

  3. luyuanwan commented on Jul 2, 2018

    @luyuanwan
    Contributor

    对于issue1,可以考虑使用dubbo的心跳,如果心跳检测不到,可以直接返回,不再等待。 @baigod

  4. baigod commented on Jul 3, 2018

    @baigod
    Author

    @luyuanwan 具体怎么实现呢 : )

  5. chickenlj commented on Jul 10, 2018

    @chickenlj
    Contributor

    For case 2, I am afraid there are no perfect solutions, when a heuristic exception occur, you can only retry or check offline.

    For case 1, I think it's meaningful to notify the hanging client requests as soon as possible. When Server goes down it will trigger disconnect on Client, and we can then return all requests related to this channel.

  6. added this to the 2.6.4 milestone on Jul 10, 2018
  7. carryxyh commented on Aug 29, 2018

    @carryxyh
    Member

    @baigod
    Hi, I have fix the issue in case 1 by this pr:
    #2185

    For case 2, I agree with chickenlj.
    U can keep it "eventually consistent".

    Is there any other questions about this issue? If not, we will close it soon. :)

  8. diecui1202 commented on Sep 5, 2018

    @diecui1202

    @carryxyh Does the PR #2185 need to merge back to 2.6.x?

  9. carryxyh commented on Sep 5, 2018

    @carryxyh
    Member

    @diecui1202
    Thanks for reminding me, I have not considered it before. I will submit a pr as soon as possible.

  10. diecui1202 commented on Sep 5, 2018

    @diecui1202

    @carryxyh Great thanks.

  11. diecui1202 commented on Sep 6, 2018

    @diecui1202

    #2451 has been merged to 2.6.x.

  12. falcondsc commented on Jul 29, 2019

    @falcondsc

    @carryxyh 你好, 我們專案中(使用 2.5.3)也遇到 issues code 1 的困擾. 看到這個 issue (修正在2.6.4)之後. 我下載 2.6.6 的代碼到我本地運行. 但是發現. 我從 consumer 送出服務調用請求 並且進到 provider 之後,在 provider 返回處理結果前, 我手動把 provider 的進程刪除,我的 consumer 端仍然處於等待狀態. 為此我調試了 dubbo 2.6.6 底層代碼, 由於對 dubbo 的同訊架構不熟, 我只能從我調試的代碼看出, consumer 的確有收到 provider 斷開, 但是 consumer 收到通知的是 HeaderExchangeChannel 這個類, 而我看了git 上修正的 file, 關鍵的修正是在 HeaderExchangeHandler 類中的 disconnected 方法調用 DefaultFuture.closeChannel(channel);
    因此我實驗性的修改了本地 HeaderExchangeChannel 的 close 方法 加入調用 DefaultFuture.closeChannel(channel); 重新打包後, 在我本地運行. 才真正解決了此 issue code 1 的問題. 請問我這樣修改是正確的嗎? 謝謝!

  13. 5 remaining items

  14. falcondsc commented on Jul 30, 2019

    @falcondsc

    @beiwei30 你好. 請問一下你改的 master branch 是指主分支 2.7.x 嗎? 我測試是使用 2.6.6 的代碼進行修改的. 註冊中心使用的是 zookeeper. consumer 設定 timeout 為 10分鐘, 我並沒有對 2.7.x 版進行調整並測試這個問題.
    本地目前在 2.6.6 調整完 HeaderExchangeChannel.close() 內先調用 DefaultFuture.closeChannel(channel); 或者選擇改 在 finally 才調用 DefaultFuture.closeChannel(channel); 都是可以在 consumer 送出請求後, 等到 provider 接入後, 刪除 provider 進程, consumer 都可以在幾秒內收到拋出的 "Channel xx is inactive. Directly return the unFinished request" 異常. 在未調整前. 我的 consumer 都是要等到 10 分鐘後才能得到一個 timeout exception.
    接著 大概需要幾天的時間 我會先把自己改過的版本 放置我們 測試區 進行驗證. 隨後會再往前推進到我們的正式的生產環境.
    (補充說明. 其實還有幾隻 dubbo 尋找 class loader 的代碼, 我是有特別修改為從當前線程取得 class loader , 但我認為不應該這幾隻修改, 會影響我本次測試的結果.)

    以上的信息 希望對你有些幫助.

  15. falcondsc commented on Jul 30, 2019

    @falcondsc

    補充一下: 另外我的 consumer retries 設定為 0

  16. falcondsc commented on Jul 30, 2019

    @falcondsc

    我另外測試了 註冊中心是使用 Multicast 時. 那麼 consumer 的 HeaderExchangeChannel 將會是
    public void close(int timeout) 這個方法被調用. 此場景下 consumer 也就只能繼續等待到 timeout 了.

  17. beiwei30 commented on Sep 5, 2019

    @beiwei30
    Member

    @beiwei30 你好. 請問一下你改的 master branch 是指主分支 2.7.x 嗎? 我測試是使用 2.6.6 的代碼進行修改的. 註冊中心使用的是 zookeeper. consumer 設定 timeout 為 10分鐘, 我並沒有對 2.7.x 版進行調整並測試這個問題.
    本地目前在 2.6.6 調整完 HeaderExchangeChannel.close() 內先調用 DefaultFuture.closeChannel(channel); 或者選擇改 在 finally 才調用 DefaultFuture.closeChannel(channel); 都是可以在 consumer 送出請求後, 等到 provider 接入後, 刪除 provider 進程, consumer 都可以在幾秒內收到拋出的 "Channel xx is inactive. Directly return the unFinished request" 異常. 在未調整前. 我的 consumer 都是要等到 10 分鐘後才能得到一個 timeout exception.
    接著 大概需要幾天的時間 我會先把自己改過的版本 放置我們 測試區 進行驗證. 隨後會再往前推進到我們的正式的生產環境.
    (補充說明. 其實還有幾隻 dubbo 尋找 class loader 的代碼, 我是有特別修改為從當前線程取得 class loader , 但我認為不應該這幾隻修改, 會影響我本次測試的結果.)

    以上的信息 希望對你有些幫助.

    @falcondsc 是的,是针对 master 分支做的分析和修复。2.6.x 上还麻烦你验证一下,如果工作的话,欢迎提 pull request 过来把 master 上的修复 backport 回来。

  18. modified the milestones: 2.6.4, 2.6.8 on Sep 5, 2019
  19. falcondsc commented on Sep 9, 2019

    @falcondsc

    @beiwei30
    好的. 我會在本周三(9/11) 以前, 在 2.6.x 分支上 進行驗證.

  20. falcondsc commented on Sep 10, 2019

    @falcondsc

    好的. 我會在本周三(9/11) 以前, 在 2.6.x 分支上 進行驗證.

    我獲取了 2.6.x 分支 在 HeaderExchangeChannel.close() 調用 DefaultFuture.closeChannel(channel); 方法. 但測試後發現調用到 HeaderExchangeChannel.close() 的堆棧 和 我先前用 2.6.6 去修改時有些不同, 2.6.x 分支代碼上慢了很多(關閉 dubbo provider 之後, 要等 30 秒以上)才會進到 consumer 端的HeaderExchangeChannel.close() .. 我先再繼續做些測試, 查看下是不是我兩個測試環境有不同而引起的問題.

  21. falcondsc commented on Sep 11, 2019

    @falcondsc

    @beiwei30 想再請教一下, 因為剛接觸 github. 所以我反覆看了整個 issue 和關聯出去的內容.
    你說的在 2.6.x 驗證. 是指包含 使用 你的 4700 pr 和 4698 pr 變更的內容 修改在我的 2.6.x repository上進行驗證嗎?

  22. CrazyHZM commented on Oct 10, 2021

    @CrazyHZM
    Member

    Try it with the latest version, if you still have problems, you can reopen the issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/proposal

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions