md_doc_compression_cookbook.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.6"/>
  7. <title>GRPC Core: gRPC (Core) Compression Cookbook</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="search/search.js"></script>
  13. <script type="text/javascript">
  14. $(document).ready(function() { searchBox.OnSelectItem(0); });
  15. </script>
  16. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  17. </head>
  18. <body>
  19. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  20. <div id="titlearea">
  21. <table cellspacing="0" cellpadding="0">
  22. <tbody>
  23. <tr style="height: 56px;">
  24. <td style="padding-left: 0.5em;">
  25. <div id="projectname">GRPC Core
  26. &#160;<span id="projectnumber">4.0.0</span>
  27. </div>
  28. </td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </div>
  33. <!-- end header part -->
  34. <!-- Generated by Doxygen 1.8.6 -->
  35. <script type="text/javascript">
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. </script>
  38. <div id="navrow1" class="tabs">
  39. <ul class="tablist">
  40. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  41. <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  42. <li><a href="modules.html"><span>Modules</span></a></li>
  43. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  44. <li><a href="files.html"><span>Files</span></a></li>
  45. <li>
  46. <div id="MSearchBox" class="MSearchBoxInactive">
  47. <span class="left">
  48. <img id="MSearchSelect" src="search/mag_sel.png"
  49. onmouseover="return searchBox.OnSearchSelectShow()"
  50. onmouseout="return searchBox.OnSearchSelectHide()"
  51. alt=""/>
  52. <input type="text" id="MSearchField" value="Search" accesskey="S"
  53. onfocus="searchBox.OnSearchFieldFocus(true)"
  54. onblur="searchBox.OnSearchFieldFocus(false)"
  55. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  56. </span><span class="right">
  57. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  58. </span>
  59. </div>
  60. </li>
  61. </ul>
  62. </div>
  63. <!-- window showing the filter options -->
  64. <div id="MSearchSelectWindow"
  65. onmouseover="return searchBox.OnSearchSelectShow()"
  66. onmouseout="return searchBox.OnSearchSelectHide()"
  67. onkeydown="return searchBox.OnSearchSelectKey(event)">
  68. <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>
  69. <!-- iframe showing the search results (closed by default) -->
  70. <div id="MSearchResultsWindow">
  71. <iframe src="javascript:void(0)" frameborder="0"
  72. name="MSearchResults" id="MSearchResults">
  73. </iframe>
  74. </div>
  75. </div><!-- top -->
  76. <div class="header">
  77. <div class="headertitle">
  78. <div class="title">gRPC (Core) Compression Cookbook </div> </div>
  79. </div><!--header-->
  80. <div class="contents">
  81. <div class="textblock"><h2>Introduction</h2>
  82. <p>This document describes compression as implemented by the gRPC C core. See <a class="el" href="compression_8md.html">the</a>full compression specification" for details.</p>
  83. <h3>Intended Audience</h3>
  84. <p>Wrapped languages developers, for the purposes of supporting compression by interacting with the C core.</p>
  85. <h2>Criteria for GA readiness</h2>
  86. <ol type="1">
  87. <li>Be able to set compression at <a href="#per-channel-settings">channel</a>, <a href="#per-call-settings">call</a> and <a href="#per-message-settings">message</a> level. In principle this API should be based on <em>compression levels</em> as opposed to algorithms. See the discussion <a href="#level-vs-algorithms">below</a>.</li>
  88. </ol>
  89. <ol type="1">
  90. <li>Have unit tests covering <a href="https://github.com/grpc/grpc/blob/master/doc/compression.md#test-cases">the cases from the spec</a>.</li>
  91. </ol>
  92. <ol type="1">
  93. <li>Interop tests implemented and passing on Jenkins. The two relevant interop test cases are <a href="https://github.com/grpc/grpc/blob/master/doc/interop-test-descriptions.md#large_compressed_unary">large_compressed_unary</a> and <a href="https://github.com/grpc/grpc/blob/master/doc/interop-test-descriptions.md#server_compressed_streaming">server_compressed_streaming</a>.</li>
  94. </ol>
  95. <h2>Summary Flowcharts</h2>
  96. <p>The following flowcharts depict the evolution of a message, both <em>incoming</em> and <em>outgoing</em>, irrespective of the client/server character of the call. Aspects still not symmetric between clients and servers (e.g. the <a href="https://github.com/grpc/grpc/blob/master/doc/compression.md#compression-levels-and-algorithms">use of compression levels</a>) are explicitly marked. The in-detail textual description for the different scenarios is described in subsequent sections.</p>
  97. <h2>Incoming Messages</h2>
  98. <div class="image">
  99. <img src="images/compression_cookbook_incoming.png" alt="image"/>
  100. </div>
  101. <h2>Outgoing Messages</h2>
  102. <div class="image">
  103. <img src="images/compression_cookbook_outgoing.png" alt="image"/>
  104. </div>
  105. <h2>Levels vs Algorithms</h2>
  106. <p>As mentioned in <a href="https://github.com/grpc/grpc/blob/master/doc/compression.md#compression-levels-and-algorithms">the relevant discussion on the spec document</a>, compression <em>levels</em> are the primary mechanism for compression selection <em>at the server side</em>. In the future, it'll also be at the client side. The use of levels abstracts away the intricacies of selecting a concrete algorithm supported by a peer, on top of removing the burden of choice from the developer. As of this writing (Q2 2016), clients can only specify compression <em>algorithms</em>. Clients will support levels as soon as an automatic retry/negotiation mechanism is in place.</p>
  107. <h2>Per Channel Settings</h2>
  108. <p>Compression may be configured at channel creation. This is a convenience to avoid having to repeatedly configure compression for every call. Note that any compression setting on individual <a href="#per-call-settings">calls</a> or <a href="#per-message-settings">messages</a> overrides channel settings.</p>
  109. <p>The following aspects can be configured at channel-creation time via channel arguments:</p>
  110. <h4>Disable Compression <em>Algorithms</em></h4>
  111. <p>Use the channel argument key <code>GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET</code> (from <a href="https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/compression_types.h">`grpc/impl/codegen/compression_types.h`</a>), takes a 32 bit bitset value. A set bit means the algorithm with that enum value according to <code>grpc_compression_algorithm</code> is <em>enabled</em>. For example, <code>GRPC_COMPRESS_GZIP</code> currently has a numeric value of 2. To enable/disable GZIP for a channel, one would set/clear the 3rd LSB (eg, 0b100 = 0x4). Note that setting/clearing 0th position, that corresponding to <code>GRPC_COMPRESS_NONE</code>, has no effect, as no-compression (a.k.a. <em>identity</em>) is always supported. Incoming messages compressed (ie, encoded) with a disabled algorithm will result in the call being closed with <code>GRPC_STATUS_UNIMPLEMENTED</code>.</p>
  112. <h4>Default Compression <em>Level</em></h4>
  113. <p>**(currently, Q2 2016, only applicable for server side channels. It's ignored for clients.)** Use the channel argument key <code>GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL</code> (from <a href="https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/compression_types.h">`grpc/impl/codegen/compression_types.h`</a>), valued by an integer corresponding to a value from the <code>grpc_compression_level</code> enum.</p>
  114. <h4>Default Compression <em>Algorithm</em></h4>
  115. <p>Use the channel argument key <code>GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM</code> (from <a href="https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/compression_types.h">`grpc/impl/codegen/compression_types.h`</a>), valued by an integer corresponding to a value from the <code>grpc_compression_level</code> enum.</p>
  116. <h2>Per Call Settings</h2>
  117. <h3>Compression <b>Level</b> in Call Responses</h3>
  118. <p>The server requests a compression level via initial metadata. The <code>send_initial_metadata</code> <code><a class="el" href="structgrpc__op.html" title="Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...">grpc_op</a></code> contains a <code>maybe_compression_level</code> field with two fields, <code>is_set</code> and <code>compression_level</code>. The former must be set when actively choosing a level to disambiguate the default value of zero (no compression) from the proactive selection of no compression.</p>
  119. <p>The core will receive the request for the compression level and automatically choose a compression algorithm based on its knowledge about the peer (communicated by the client via the <code>grpc-accept-encoding</code> header. Note that the absence of this header means no compression is supported by the client/peer).</p>
  120. <h3>Compression <b>Algorithm</b> in Call Responses</h3>
  121. <p><b>Server should avoid setting the compression algorithm directly</b>. Prefer setting compression levels unless there's a <em>very</em> compelling reason to choose specific algorithms (benchmarking, testing).</p>
  122. <p>Selection of concrete compression algorithms is performed by adding a <code>(GRPC_COMPRESS_REQUEST_ALGORITHM_KEY, &lt;algorithm-name&gt;)</code> key-value pair to the initial metadata, where <code>GRPC_COMPRESS_REQUEST_ALGORITHM_KEY</code> is defined in <a href="https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/compression_types.h">`grpc/impl/codegen/compression_types.h`</a>), and <code>&lt;algorithm-name&gt;</code> is the human readable name of the algorithm as given in https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md "the HTTP2 spec" for <code>Message-Encoding</code> (e.g. gzip, identity, etc.). See <a href="https://github.com/grpc/grpc/blob/master/src/core/lib/compression/compression.c">`grpc_compression_algorithm_name`</a> for the mapping between the <code>grpc_compression_algorithm</code> enum values and their textual representation.</p>
  123. <h2>Per Message Settings</h2>
  124. <p>To disable compression for a specific message, the <code>flags</code> field of <code><a class="el" href="structgrpc__op.html" title="Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...">grpc_op</a></code> instances of type <code>GRPC_OP_SEND_MESSAGE</code> must have its <code>GRPC_WRITE_NO_COMPRESS</code> bit set. Refer to <a href="https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/compression_types.h">`grpc/impl/codegen/compression_types.h`</a>), </p>
  125. </div></div><!-- contents -->
  126. <!-- start footer part -->
  127. <hr class="footer"/><address class="footer"><small>
  128. Generated on Wed Jun 21 2017 14:13:07 for GRPC Core by &#160;<a href="http://www.doxygen.org/index.html">
  129. <img class="footer" src="doxygen.png" alt="doxygen"/>
  130. </a> 1.8.6
  131. </small></address>
  132. </body>
  133. </html>