grpc/cpp/md_doc_connection-backoff.html

99 lines
5.1 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>GRPC C++: GRPC Connection Backoff Protocol</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">GRPC C++
&#160;<span id="projectnumber">1.22.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">GRPC Connection Backoff Protocol </div> </div>
</div><!--header-->
<div class="contents">
<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>
<p>We have several parameters:</p><ol type="1">
<li>INITIAL_BACKOFF (how long to wait after the first failure before retrying)</li>
</ol>
<ol type="1">
<li>MULTIPLIER (factor with which to multiply backoff after a failed retry)</li>
</ol>
<ol type="1">
<li>JITTER (by how much to randomize backoffs).</li>
</ol>
<ol type="1">
<li>MAX_BACKOFF (upper bound on backoff)</li>
</ol>
<ol type="1">
<li>MIN_CONNECT_TIMEOUT (minimum time we're willing to give a connection to complete)</li>
</ol>
<h2>Proposed Backoff Algorithm</h2>
<p>Exponentially back off the start time of connection attempts up to a limit of MAX_BACKOFF, with jitter.</p>
<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>
<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>
<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>
<h2>Reset Backoff</h2>
<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>
<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>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Jul 3 2019 14:51:27 for GRPC C++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>