md_doc_connection-backoff.html 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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.13"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>GRPC Core: 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 Core
  25. &#160;<span id="projectnumber">6.0.0</span>
  26. </div>
  27. </td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- end header part -->
  33. <!-- Generated by Doxygen 1.8.13 -->
  34. <script type="text/javascript">
  35. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  36. </script>
  37. <script type="text/javascript" src="menudata.js"></script>
  38. <script type="text/javascript" src="menu.js"></script>
  39. <script type="text/javascript">
  40. $(function() {
  41. initMenu('',true,false,'search.php','Search');
  42. $(document).ready(function() { init_search(); });
  43. });
  44. </script>
  45. <div id="main-nav"></div>
  46. <!-- window showing the filter options -->
  47. <div id="MSearchSelectWindow"
  48. onmouseover="return searchBox.OnSearchSelectShow()"
  49. onmouseout="return searchBox.OnSearchSelectHide()"
  50. onkeydown="return searchBox.OnSearchSelectKey(event)">
  51. </div>
  52. <!-- iframe showing the search results (closed by default) -->
  53. <div id="MSearchResultsWindow">
  54. <iframe src="javascript:void(0)" frameborder="0"
  55. name="MSearchResults" id="MSearchResults">
  56. </iframe>
  57. </div>
  58. </div><!-- top -->
  59. <div class="header">
  60. <div class="headertitle">
  61. <div class="title">GRPC Connection Backoff Protocol </div> </div>
  62. </div><!--header-->
  63. <div class="contents">
  64. <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>
  65. <p>We have several parameters:</p><ol type="1">
  66. <li>INITIAL_BACKOFF (how long to wait after the first failure before retrying)</li>
  67. </ol>
  68. <ol type="1">
  69. <li>MULTIPLIER (factor with which to multiply backoff after a failed retry)</li>
  70. </ol>
  71. <ol type="1">
  72. <li>JITTER (by how much to randomize backoffs).</li>
  73. </ol>
  74. <ol type="1">
  75. <li>MAX_BACKOFF (upper bound on backoff)</li>
  76. </ol>
  77. <ol type="1">
  78. <li>MIN_CONNECT_TIMEOUT (minimum time we're willing to give a connection to complete)</li>
  79. </ol>
  80. <h2>Proposed Backoff Algorithm</h2>
  81. <p>Exponentially back off the start time of connection attempts up to a limit of MAX_BACKOFF, with jitter.</p>
  82. <div class="fragment"><div class="line">ConnectWithBackoff()</div><div class="line"> current_backoff = INITIAL_BACKOFF</div><div class="line"> current_deadline = now() + INITIAL_BACKOFF</div><div class="line"> while (TryConnect(Max(current_deadline, now() + MIN_CONNECT_TIMEOUT))</div><div class="line"> != SUCCESS)</div><div class="line"> SleepUntil(current_deadline)</div><div class="line"> current_backoff = Min(current_backoff * MULTIPLIER, MAX_BACKOFF)</div><div class="line"> current_deadline = now() + current_backoff +</div><div class="line"> UniformRandom(-JITTER * current_backoff, JITTER * current_backoff)</div></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>
  83. <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>
  84. <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>
  85. <h2>Reset Backoff</h2>
  86. <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>
  87. <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>
  88. </div></div><!-- contents -->
  89. <!-- start footer part -->
  90. <hr class="footer"/><address class="footer"><small>
  91. Generated on Fri Apr 13 2018 15:03:52 for GRPC Core by &#160;<a href="http://www.doxygen.org/index.html">
  92. <img class="footer" src="doxygen.png" alt="doxygen"/>
  93. </a> 1.8.13
  94. </small></address>
  95. </body>
  96. </html>