md_doc_core_grpc-cq.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 Core: gRPC Completion Queue</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">15.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.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 Completion Queue </div> </div>
  65. </div><!--header-->
  66. <div class="contents">
  67. <div class="textblock"><p><em>Author: Sree Kuchibhotla (@sreecha) - Sep 2018</em></p>
  68. <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>
  69. <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>
  70. <h1><a class="anchor" id="autotoc_md99"></a>
  71. Completion queue attributes</h1>
  72. <p>Completion queue has two attributes</p>
  73. <ul>
  74. <li>Completion_type:<ul>
  75. <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 &#39;tag&#39; is available, the completion queue is being shutdown or deadline...">grpc_completion_queue_pluck()</a>)</li>
  76. <li>GRPC_CQ_PLUCK: <a class="el" href="grpc_8h.html#a0292bf7a0c794771cd66766dc4b8276c" title="Blocks until an event with tag &#39;tag&#39; 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>
  77. <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>
  78. </ul>
  79. </li>
  80. <li>Polling_type:<ul>
  81. <li>GRPC_CQ_NON_POLLING: Threads calling completion_queue_next/pluck do not do any polling</li>
  82. <li>GRPC_CQ_DEFAULT_POLLING: Threads calling completion_queue_next/pluck do polling</li>
  83. <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>
  84. </ul>
  85. </li>
  86. </ul>
  87. <h1><a class="anchor" id="autotoc_md100"></a>
  88. Details</h1>
  89. <p><img src="../images/grpc-cq.png" alt="image" class="inline"/></p>
  90. <h2><a class="anchor" id="autotoc_md101"></a>
  91. &lt;strong&gt;grpc_completion_queue_next()&lt;/strong&gt; &amp; &lt;strong&gt;grpc_completion_queue_pluck()&lt;/strong&gt; APIS</h2>
  92. <div class="fragment"><div class="line">grpc_completion_queue_next(cq, deadline)/pluck(cq, deadline, tag) {</div>
  93. <div class="line"> while(true) {</div>
  94. <div class="line"> \\ 1. If an event is queued in the completion queue, dequeue and return</div>
  95. <div class="line"> \\ (in case of pluck() dequeue only if the tag is the one we are interested in)</div>
  96. <div class="line"> </div>
  97. <div class="line"> \\ 2. If completion queue shutdown return</div>
  98. <div class="line"> </div>
  99. <div class="line"> \\ 3. In case of pluck, add (tag, worker) pair to the tag&lt;-&gt;worker map on the cq</div>
  100. <div class="line"> </div>
  101. <div class="line"> \\ 4. Call grpc_pollset_work(cq’s-pollset, deadline) to do polling</div>
  102. <div class="line"> \\ Note that if this function found some fds to be readable/writable/error,</div>
  103. <div class="line"> \\ it would have scheduled those closures (which may queue completion events</div>
  104. <div class="line"> \\ on SOME completion queue - not necessarily this one)</div>
  105. <div class="line"> }</div>
  106. <div class="line">}</div>
  107. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md102"></a>
  108. Queuing a completion event (i.e., "tag")</h2>
  109. <div class="fragment"><div class="line">grpc_cq_end_op(cq, tag) {</div>
  110. <div class="line"> \\ 1. Queue the tag in the event queue</div>
  111. <div class="line"> </div>
  112. <div class="line"> \\ 2. Find the pollset corresponding to the completion queue</div>
  113. <div class="line"> \\ (i) If the cq is of type GRPC_CQ_NEXT, then KICK ANY worker</div>
  114. <div class="line"> \\ i.e., call grpc_pollset_kick(pollset, nullptr)</div>
  115. <div class="line"> \\ (ii) If the cq is of type GRPC_CQ_PLUCK, then search the tag&lt;-&gt;worker</div>
  116. <div class="line"> \\ map on the completion queue to find the worker. Then specifically</div>
  117. <div class="line"> \\ kick that worker i.e call grpc_pollset_kick(pollset, worker)</div>
  118. <div class="line">}</div>
  119. </div><!-- fragment --> </div></div><!-- contents -->
  120. </div><!-- PageDoc -->
  121. <!-- start footer part -->
  122. <hr class="footer"/><address class="footer"><small>
  123. Generated on Wed Mar 3 2021 19:17:11 for GRPC Core by &#160;<a href="http://www.doxygen.org/index.html">
  124. <img class="footer" src="doxygen.png" alt="doxygen"/>
  125. </a> 1.8.17
  126. </small></address>
  127. </body>
  128. </html>