123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <!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: gRPC Completion Queue</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">gRPC Completion Queue </div> </div>
- </div><!--header-->
- <div class="contents">
- <div class="textblock"><p><em>Author: Sree Kuchibhotla (@sreecha) - Sep 2018</em></p>
- <p>Code: <a href="https://github.com/grpc/grpc/blob/v1.15.1/src/core/lib/surface/completion_queue.cc">completion_queue.cc</a></p>
- <p>This document gives an overview of completion queue architecture and focuses mainly on the interaction between completion queue and the Polling engine layer.</p>
- <h1><a class="anchor" id="autotoc_md99"></a>
- Completion queue attributes</h1>
- <p>Completion queue has two attributes</p>
- <ul>
- <li>Completion_type:<ul>
- <li>GRPC_CQ_NEXT: <a class="el" href="grpc_8h.html#ab43d55077bcbeb324044d3dcd26a5c80" title="Blocks until an event is available, the completion queue is being shut down, or deadline is reached.">grpc_completion_queue_next()</a> can be called (but not <a class="el" href="grpc_8h.html#a0292bf7a0c794771cd66766dc4b8276c" title="Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline...">grpc_completion_queue_pluck()</a>)</li>
- <li>GRPC_CQ_PLUCK: <a class="el" href="grpc_8h.html#a0292bf7a0c794771cd66766dc4b8276c" title="Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline...">grpc_completion_queue_pluck()</a> can be called (but not <a class="el" href="grpc_8h.html#ab43d55077bcbeb324044d3dcd26a5c80" title="Blocks until an event is available, the completion queue is being shut down, or deadline is reached.">grpc_completion_queue_next()</a>)</li>
- <li>GRPC_CQ_CALLBACK: The tags in the queue are function pointers to callbacks. Also, neither next() nor pluck() can be called on this</li>
- </ul>
- </li>
- <li>Polling_type:<ul>
- <li>GRPC_CQ_NON_POLLING: Threads calling completion_queue_next/pluck do not do any polling</li>
- <li>GRPC_CQ_DEFAULT_POLLING: Threads calling completion_queue_next/pluck do polling</li>
- <li>GRPC_CQ_NON_LISTENING: Functionally similar to default polling except for a boolean attribute that states that the cq is non-listening. This is used by the grpc-server code to not associate any listening sockets with this completion-queue’s pollset</li>
- </ul>
- </li>
- </ul>
- <h1><a class="anchor" id="autotoc_md100"></a>
- Details</h1>
- <p><img src="../images/grpc-cq.png" alt="image" class="inline"/></p>
- <h2><a class="anchor" id="autotoc_md101"></a>
- <strong>grpc_completion_queue_next()</strong> & <strong>grpc_completion_queue_pluck()</strong> APIS</h2>
- <div class="fragment"><div class="line">grpc_completion_queue_next(cq, deadline)/pluck(cq, deadline, tag) {</div>
- <div class="line"> while(true) {</div>
- <div class="line"> \\ 1. If an event is queued in the completion queue, dequeue and return</div>
- <div class="line"> \\ (in case of pluck() dequeue only if the tag is the one we are interested in)</div>
- <div class="line"> </div>
- <div class="line"> \\ 2. If completion queue shutdown return</div>
- <div class="line"> </div>
- <div class="line"> \\ 3. In case of pluck, add (tag, worker) pair to the tag<->worker map on the cq</div>
- <div class="line"> </div>
- <div class="line"> \\ 4. Call grpc_pollset_work(cq’s-pollset, deadline) to do polling</div>
- <div class="line"> \\ Note that if this function found some fds to be readable/writable/error,</div>
- <div class="line"> \\ it would have scheduled those closures (which may queue completion events</div>
- <div class="line"> \\ on SOME completion queue - not necessarily this one)</div>
- <div class="line"> }</div>
- <div class="line">}</div>
- </div><!-- fragment --><h2><a class="anchor" id="autotoc_md102"></a>
- Queuing a completion event (i.e., "tag")</h2>
- <div class="fragment"><div class="line">grpc_cq_end_op(cq, tag) {</div>
- <div class="line"> \\ 1. Queue the tag in the event queue</div>
- <div class="line"> </div>
- <div class="line"> \\ 2. Find the pollset corresponding to the completion queue</div>
- <div class="line"> \\ (i) If the cq is of type GRPC_CQ_NEXT, then KICK ANY worker</div>
- <div class="line"> \\ i.e., call grpc_pollset_kick(pollset, nullptr)</div>
- <div class="line"> \\ (ii) If the cq is of type GRPC_CQ_PLUCK, then search the tag<->worker</div>
- <div class="line"> \\ map on the completion queue to find the worker. Then specifically</div>
- <div class="line"> \\ kick that worker i.e call grpc_pollset_kick(pollset, worker)</div>
- <div class="line">}</div>
- </div><!-- fragment --> </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>
|