md_doc_connection-backoff.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.17"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>GRPC C++: GRPC Connection Backoff Protocol</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="search/searchdata.js"></script>
  14. <script type="text/javascript" src="search/search.js"></script>
  15. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  19. <div id="titlearea">
  20. <table cellspacing="0" cellpadding="0">
  21. <tbody>
  22. <tr style="height: 56px;">
  23. <td id="projectalign" style="padding-left: 0.5em;">
  24. <div id="projectname">GRPC C++
  25. &#160;<span id="projectnumber">1.36.1</span>
  26. </div>
  27. </td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- end header part -->
  33. <!-- Generated by Doxygen 1.8.17 -->
  34. <script type="text/javascript">
  35. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. /* @license-end */
  38. </script>
  39. <script type="text/javascript" src="menudata.js"></script>
  40. <script type="text/javascript" src="menu.js"></script>
  41. <script type="text/javascript">
  42. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  43. $(function() {
  44. initMenu('',true,false,'search.php','Search');
  45. $(document).ready(function() { init_search(); });
  46. });
  47. /* @license-end */</script>
  48. <div id="main-nav"></div>
  49. <!-- window showing the filter options -->
  50. <div id="MSearchSelectWindow"
  51. onmouseover="return searchBox.OnSearchSelectShow()"
  52. onmouseout="return searchBox.OnSearchSelectHide()"
  53. onkeydown="return searchBox.OnSearchSelectKey(event)">
  54. </div>
  55. <!-- iframe showing the search results (closed by default) -->
  56. <div id="MSearchResultsWindow">
  57. <iframe src="javascript:void(0)" frameborder="0"
  58. name="MSearchResults" id="MSearchResults">
  59. </iframe>
  60. </div>
  61. </div><!-- top -->
  62. <div class="PageDoc"><div class="header">
  63. <div class="headertitle">
  64. <div class="title">GRPC Connection Backoff Protocol </div> </div>
  65. </div><!--header-->
  66. <div class="contents">
  67. <div class="textblock"><p>When we do a connection to a backend which fails, it is typically desirable to not retry immediately (to avoid flooding the network or the server with requests) and instead do some form of exponential backoff.</p>
  68. <p>We have several parameters:</p><ol type="1">
  69. <li>INITIAL_BACKOFF (how long to wait after the first failure before retrying)</li>
  70. </ol>
  71. <ol type="1">
  72. <li>MULTIPLIER (factor with which to multiply backoff after a failed retry)</li>
  73. </ol>
  74. <ol type="1">
  75. <li>JITTER (by how much to randomize backoffs).</li>
  76. </ol>
  77. <ol type="1">
  78. <li>MAX_BACKOFF (upper bound on backoff)</li>
  79. </ol>
  80. <ol type="1">
  81. <li>MIN_CONNECT_TIMEOUT (minimum time we're willing to give a connection to complete)</li>
  82. </ol>
  83. <h1><a class="anchor" id="autotoc_md77"></a>
  84. Proposed Backoff Algorithm</h1>
  85. <p>Exponentially back off the start time of connection attempts up to a limit of MAX_BACKOFF, with jitter.</p>
  86. <div class="fragment"><div class="line">ConnectWithBackoff()</div>
  87. <div class="line"> current_backoff = INITIAL_BACKOFF</div>
  88. <div class="line"> current_deadline = now() + INITIAL_BACKOFF</div>
  89. <div class="line"> while (TryConnect(Max(current_deadline, now() + MIN_CONNECT_TIMEOUT))</div>
  90. <div class="line"> != SUCCESS)</div>
  91. <div class="line"> SleepUntil(current_deadline)</div>
  92. <div class="line"> current_backoff = Min(current_backoff * MULTIPLIER, MAX_BACKOFF)</div>
  93. <div class="line"> current_deadline = now() + current_backoff +</div>
  94. <div class="line"> UniformRandom(-JITTER * current_backoff, JITTER * current_backoff)</div>
  95. </div><!-- fragment --><p>With specific parameters of MIN_CONNECT_TIMEOUT = 20 seconds INITIAL_BACKOFF = 1 second MULTIPLIER = 1.6 MAX_BACKOFF = 120 seconds JITTER = 0.2</p>
  96. <p>Implementations with pressing concerns (such as minimizing the number of wakeups on a mobile phone) may wish to use a different algorithm, and in particular different jitter logic.</p>
  97. <p>Alternate implementations must ensure that connection backoffs started at the same time disperse, and must not attempt connections substantially more often than the above algorithm.</p>
  98. <h1><a class="anchor" id="autotoc_md78"></a>
  99. Reset Backoff</h1>
  100. <p>The back off should be reset to INITIAL_BACKOFF at some time point, so that the reconnecting behavior is consistent no matter the connection is a newly started one or a previously disconnected one.</p>
  101. <p>We choose to reset the Backoff when the SETTINGS frame is received, at that time point, we know for sure that this connection was accepted by the server. </p>
  102. </div></div><!-- contents -->
  103. </div><!-- PageDoc -->
  104. <!-- start footer part -->
  105. <hr class="footer"/><address class="footer"><small>
  106. Generated on Wed Mar 3 2021 19:17:22 for GRPC C++ by &#160;<a href="http://www.doxygen.org/index.html">
  107. <img class="footer" src="doxygen.png" alt="doxygen"/>
  108. </a> 1.8.17
  109. </small></address>
  110. </body>
  111. </html>