<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title><![CDATA[Sherry Ger - Elasticsearch Labs]]></title>
    <description><![CDATA[Articles and tutorials from the Search team at Elastic]]></description>
    <copyright><![CDATA[© 2026. Elasticsearch B.V. All Rights Reserved]]></copyright>
    <image>
      <title><![CDATA[Sherry Ger - Elasticsearch Labs]]></title>
      <url>https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt1121c0bf0e8a6e65/6a88da6340a1841030ef456f/search-labs-thumbnail.png</url>
      <link>https://www.elastic.co/cn/search-labs/author/sherry-ger</link>
    </image>
    <link>https://www.elastic.co/cn/search-labs/author/sherry-ger</link>
    <atom:link href="https://www.elastic.co/cn/search-labs/rss/author/sherry-ger.xml" rel="self" type="application/rss+xml"/>
    <language><![CDATA[cn]]></language>
    <lastBuildDate>Mon, 21 Sep 2026 13:43:50 GMT</lastBuildDate>
  <item>
    <title><![CDATA[通过 best_compression 提升搜索性能]]></title>
    <description><![CDATA[虽然 best_compression 通常被视为 Elastic Observability 和 Elastic Security 用例的存储节省功能，但本篇博客将展示其作为搜索性能调优工具的有效性。]]></description>
    <content:encoded><![CDATA[<p></p><p>在为高并发工作负载调优 Elasticsearch 时，标准方法是最大限度地增加 RAM，将工作文档集保存在内存中，以实现低搜索延迟。因此，<a href="https://www.elastic.co/docs/reference/elasticsearch/index-settings/index-modules"><code>best_compression</code></a> 很少被考虑用于搜索工作负载，因为它主要被视为 Elastic Observability 和 Elastic Security 用例中优先考虑存储效率的节省存储措施。</p><p>在本博客中，我们证明当数据集大小显著超出操作系统页面缓存时，<code>best_compression</code>通过减少 I/O 瓶颈来提升搜索性能和资源效率。</p><h2><strong>设置</strong></h2><p>我们的用例是一个运行在 <a href="https://www.elastic.co/docs/deploy-manage/deploy/elastic-cloud/ec-change-hardware-profile#ec-profiles-compute-optimized-arm">Elastic Cloud CPU 优化实例</a>上的高并发搜索应用程序。</p><ul><li><p>数据量：约 5 亿份文档</p></li><li><p>基础架构：6 个 Elastic Cloud（Elasticsearch 服务）实例（每个实例：1.76 TB 存储 | 60 GB 内存 | 31.9 个 vCPU）</p></li><li><p>内存与存储比率：约 5% 的总数据集可存储在 RAM 中</p></li></ul><h2><strong>症状：高延迟</strong></h2><p>我们观察到，当当前请求数在 19:00 左右激增时，搜索延迟显著恶化。如图 1 和图 2 所示，尽管每个 Elasticsearch 实例的流量峰值约为每分钟 400 个请求，但平均查询服务时间仍恶化至超过 60 毫秒。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltf8ab7de934d6b410/6a170440c1e8a58db3f881c1/f9c6cc1882e7db24336c65c54bbc1d38dcdb7fa3-697x311.png" alt="每个 Elasticsearch 实例的每分钟请求数达到峰值" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt32de2bed0afbacd5/6a1704422b835fa5ddf4b0e2/bbb705ae2fcd14c81d335bf322346caf3bf33765-996x618.png" alt="Elasticsearch 平均查询服务时间" /><p>在完成初始连接处理后，CPU 使用率保持相对较低，表明计算并非瓶颈。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blta5b45d4a1ff48f54/6a17044447d49cd7252d88af/cec15a28d2d22e9adedd2951bb2334b3717890a1-1494x730.png" alt="Elasticsearch CPU 使用率" /><p>查询量与页面错误之间出现了强相关性。随着请求增加，我们观察到页面错误比例上升，峰值约为每分钟 40 万次。这表明活跃数据集无法完全放入页面缓存。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltd0a3d0c610700bdb/6a17044560084b6f403c4459/511f2f10300a9d10ba3d7a82b9a8c8d567ac5636-1492x678.png" alt="Elasticsearch 性能的页面错误次数" /><p>同时，JVM 堆使用率也显示正常且平稳。这排除了垃圾回收问题，并确认瓶颈在于 I/O。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt3f888a03ce78eb04/6a170448964cea401008ba59/336bbad638f866304358dba1d06ee987de0f23cf-1490x568.png" alt="Elasticsearch 中的堆使用率" /><h2><strong>诊断：I/O 瓶颈</strong></h2><p>系统存在 I/O 瓶颈。<a href="https://www.elastic.co/blog/elasticsearch-caching-deep-dive-boosting-query-speed-one-cache-at-a-time">Elasticsearch 依赖操作系统页面缓存从内存提供索引数据</a>。当索引过大而无法放入缓存时，查询会触发开销很大的磁盘读取。虽然典型的解决方案是水平扩展（添加节点/RAM），但我们希望先充分利用现有资源的效率改进。</p><h2><strong>解决方案</strong></h2><p>默认情况下，Elasticsearch 对其索引段使用 <a href="https://en.wikipedia.org/wiki/LZ4_(compression_algorithm)">LZ4</a> 压缩，在速度和大小之间取得平衡。我们假设，改用 <code>best_compression</code> （使用 <a href="https://en.wikipedia.org/wiki/Zstd">zstd</a>）会减少索引的大小。更小的占用空间使得更大比例的索引能够放入页面缓存，以微不足道的 CPU 增加（用于解压缩）换取磁盘 I/O 的减少。</p><p>为了启用 <code>best_compression</code>，我们使用索引设置 <code>index.codec: best_compression</code> 重新索引了数据。或者，也可以通过关闭索引、将索引编解码器重置为 <code>best_compression</code>，然后进行段合并，也可实现相同的结果。</p>POST my-index/_close
PUT my-index/_settings
{
    "codec": "best_compression"
}
  
POST my-index/_open  
POST my-index/_forcemerge?max_num_segments=1<h2><strong>结果</strong></h2><p>结果证实了我们的假设：存储效率的提高直接转化为搜索性能的大幅提升，而 CPU 利用率并未相应增加。</p><p>应用 <code>best_compression</code> 后，索引大小减少了约 25%。虽然低于在重复日志数据中观察到的减少幅度，但这 25% 的减少实际上将我们的页面缓存容量提升了相同的比例。</p><p>在下一次负载测试期间（从 17:00 开始），流量甚至更高，每个 Elasticsearch 节点的请求峰值达到每分钟 500 次。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blta61ab3bd5ded5716/6a170449a6c2b9f711e795dd/fc1902f396cb2115c0013155ad07f6eb87389c60-660x309.png" alt="Elaticserach 的负载测试" /><p>尽管负载更高，但 CPU 利用率仍低于上一次运行。先前测试中较高的使用率可能是由于过多的页面错误处理和磁盘 I/O 管理开销所致。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt9fd1a44b02a4f787/6a17044b2b835ff996f4b0e6/15699ef4c65b3f0a9f8a3e1bae8bb18f7b647025-819x352.png" alt="通过 best_compression 提升 Elasticsearch CPU 利用率性能" /><p>至关重要的是，页面错误显著下降。即使在更高的吞吐量下，错误次数也稳定维持在每分钟低于 20 万次，而基准测试中的错误次数则超过 30 万次。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltef0c621d76767115/6a17044c2b835fe49ef4b0ea/f76ca967976d740af88a9359b66041701abb46fc-764x340.png" alt="通过 best_compression 提升 Elasticsearch 性能，降低页面错误次数" /><p>尽管页面错误结果仍然不太理想，但查询服务时间却减少了约 50%，即使在负载更重的情况下也保持在 30 毫秒以下。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt6579b3d005d04101/6a17044e66c4f9179cf8bf13/750ec1c59b8eb5069aed4c066d856ecea82d5bca-620x311.png" alt="使用 best_compression 后，Elasticsearch 平均查询服务时间性能提升" /><p></p><h2><strong>结论：为搜索启用 best_compression</strong></h2><p>对于搜索用例中数据量超过可用物理内存的情况，<code>best_compression</code> 是一个强大的性能调优工具。</p><p>应对缓存未命中的常规解决方案是通过扩展来增加 RAM。然而，通过减少索引占用空间，我们实现了相同的目标：最大化页面缓存中的文档数量。我们的下一步是探索<a href="https://www.elastic.co/blog/space-savings-a-lesser-known-benefit-of-index-sorting-in-elasticsearch"><strong>索引排序</strong></a>，以进一步优化存储并从现有资源中获得更多性能。</p>]]></content:encoded>
    <link>https://www.elastic.co/search-labs/blog/improve-elasticsearch-performance-best-compression</link>
    <guid isPermaLink="true">https://www.elastic.co/search-labs/blog/improve-elasticsearch-performance-best-compression</guid>
    <category><![CDATA[在 Elastic 内部]]></category>
    <dc:creator><![CDATA[Sherry Ger,Ryan Eno]]></dc:creator>
    <enclosure url="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt4ff57fbb95c04412/6a17044fab7f081490db9d66/5141a8c2618337207d848ce16b258a86885955b2-1600x1034.jpg" length="0" type="image/jpeg"/>
    <pubDate>Fri, 23 Jan 2026 00:00:00 GMT</pubDate>
  </item>
  </channel>
</rss>