123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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.17"/>
- <meta name="viewport" content="width=device-width, initial-scale=1"/>
- <title>GRPC Core: Polling Engine Usage on gRPC client and Server</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 Core
-  <span id="projectnumber">15.0.0</span>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.17 -->
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- var searchBox = new SearchBox("searchBox", "search",false,'Search');
- /* @license-end */
- </script>
- <script type="text/javascript" src="menudata.js"></script>
- <script type="text/javascript" src="menu.js"></script>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(function() {
- initMenu('',true,false,'search.php','Search');
- $(document).ready(function() { init_search(); });
- });
- /* @license-end */</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="PageDoc"><div class="header">
- <div class="headertitle">
- <div class="title">Polling Engine Usage on gRPC client and Server </div> </div>
- </div><!--header-->
- <div class="contents">
- <div class="textblock"><p><em>Author: Sree Kuchibhotla (@sreecha) - Sep 2018</em></p>
- <p>This document talks about how polling engine is used in gRPC core (both on client and server code paths).</p>
- <h1><a class="anchor" id="autotoc_md94"></a>
- gRPC client</h1>
- <h2><a class="anchor" id="autotoc_md95"></a>
- Relation between Call, Channel (sub-channels), Completion queue, <tt>grpc_pollset</tt></h2>
- <ul>
- <li>A gRPC Call is tied to a channel (more specifically a sub-channel) and a completion queue for the lifetime of the call.</li>
- <li>Once a <em>sub-channel</em> is picked for the call, the file-descriptor (socket fd in case of TCP channels) is added to the pollset corresponding to call's completion queue. (Recall that as per <a class="el" href="grpc-cq_8md.html">grpc-cq</a>, a completion queue has a pollset by default)</li>
- </ul>
- <p><img src="../images/grpc-call-channel-cq.png" alt="image" class="inline"/></p>
- <h2><a class="anchor" id="autotoc_md96"></a>
- Making progress on Async <tt>connect()</tt> on sub-channels (<tt>grpc_pollset_set</tt> usecase)</h2>
- <ul>
- <li>A gRPC channel is created between a client and a 'target'. The 'target' may resolve in to one or more backend servers.</li>
- <li>A sub-channel is the 'connection' from a client to the backend server</li>
- <li>While establishing sub-channels (i.e connections) to the backends, gRPC issues async <a href="https://github.com/grpc/grpc/blob/v1.15.1/src/core/lib/iomgr/tcp_client_posix.cc#L296"><code>connect()</code></a> calls which may not complete right away. When the <code>connect()</code> eventually succeeds, the socket fd is make 'writable'<ul>
- <li>This means that the polling engine must be monitoring all these sub-channel <code>fd</code>s for writable events and we need to make sure there is a polling thread that monitors all these fds</li>
- <li>To accomplish this, the <code>grpc_pollset_set</code> is used the following way (see picture below)</li>
- </ul>
- </li>
- </ul>
- <p><img src="../images/grpc-client-lb-pss.png" alt="image" class="inline"/></p>
- <h1><a class="anchor" id="autotoc_md97"></a>
- gRPC server</h1>
- <ul>
- <li>The listening fd (i.e., the socket fd corresponding to the server listening port) is added to each of the server completion queues. Note that in gRPC we use SO_REUSEPORT option and create multiple listening fds but all of them map to the same listening port</li>
- <li>A new incoming channel is assigned to some server completion queue picked randomly (note that we currently <a href="https://github.com/grpc/grpc/blob/v1.15.1/src/core/lib/iomgr/tcp_server_posix.cc#L231">round-robin</a> over the server completion queues)</li>
- </ul>
- <p><img src="../images/grpc-server-cq-fds.png" alt="image" class="inline"/> </p>
- </div></div><!-- contents -->
- </div><!-- PageDoc -->
- <!-- start footer part -->
- <hr class="footer"/><address class="footer"><small>
- Generated on Wed Mar 3 2021 19:17:11 for GRPC Core by  <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/>
- </a> 1.8.17
- </small></address>
- </body>
- </html>
|