OpenSearch: [BUG] desc_sort_timestamp is slower with OS 3.0 index compared to OS 2.19 index on OS 3.0 server

Describe the bug

OS 3.0 * OS 2.19 indicates that the OpenSearch server was running 3.0 whereas the index used was created in OS 2.19. This was done to eliminate any suspicion of the bug arising from an indexing change in Lucene.

Metric Name Operation/Query name OS 2.19 OS 3.0 OS 3.0 * OS 2.19 Unit
50th percentile latency desc_sort_timestamp 7.93071 10.8131 7.7783 ms
90th percentile latency desc_sort_timestamp 8.45714 11.4532 8.68553 ms
99th percentile latency desc_sort_timestamp 9.68866 14.6754 10.0167 ms
100th percentile latency desc_sort_timestamp 11.1424 16.3041 10.6183 ms
50th percentile service time desc_sort_timestamp 6.51203 9.40036 6.35852 ms
90th percentile service time desc_sort_timestamp 7.07093 9.89428 7.15328 ms
99th percentile service time desc_sort_timestamp 8.42815 13.2756 8.50242 ms
100th percentile service time desc_sort_timestamp 9.56305 14.7515 9.65212 ms

As we can see something in the index layout is causing OS 3.0 server to be slower with OS 3.0 index.

Related component

Search:Performance

To Reproduce

Run desc_sort_timestamp with Big5 workload using OS 3.0 server and compare with indices created in OS 2.19 v/s OS 3.0

Expected behavior

desc_sort_timestamp should be equally faster with OS 3.0 index.

Additional Details

Meta

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

Summary

In my local tests when performing sorted searches with a timestamp field in descending order after a force merge to a single segment, Lucene 10.1.0 shows performance variance compared to Lucene 9.12.1 (and when compared to 10.0.0) with the exact same data (tested with 1 shard and 1 segment). The main cause is Document ID Reassignment after the force merge.

  • Document ID Reassignment: After force merging to a single segment, document IDs were reassigned. In 10.1.0, older documents (with older timestamps) received lower document IDs. This correlation between document IDs and sort values impacts the efficiency of BKD optimization.

  • BKD Tree Optimization Skipping: In Lucene 10.1.0, the BKD optimization that allows efficient skipping of non-competitive documents is being skipped, while it was applied in 9.12.1 (and 10.0.0).

    • After force merging to a single segment, descending timestamp sorts shows variance in Lucene 10.1.0 than in 9.12.1.
    • The BKD tree optimization that allows efficient skipping of non-competitive documents is being skipped in 10.1.0.
    • In 10.1.0, the point count estimator returns much higher values (~2.3M points vs ~300K in 9.12.1 (same case with 10.0.0)).
      [2025-03-24T17:29:53,274][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The bottomAsComparableLong is 1673553872000
      [2025-03-24T17:29:53,276][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The maxValueAsLong is 9223372036854775807 The minValueAsLong is = 1673553872001
      [2025-03-24T17:29:53,277][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The iteratorCost is 116000000 The maxDocs is = 116000000
      [2025-03-24T17:29:53,280][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The value in isEstimatedPointCountGreaterThanOrEqualTo is = 2369536
      
      [2025-03-24T17:42:00,685][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The bottomAsComparableLong is 1673572521000
      [2025-03-24T17:42:00,687][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The maxValueAsLong is 9223372036854775807 The minValueAsLong is = 1673572521001
      [2025-03-24T17:42:00,688][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The iteratorCost is 116000000 The maxDocs is = 116000000
      [2025-03-24T17:42:00,693][INFO ][stdout                   ] [ip-172-31-30-219.ec2.internal] The value in isEstimatedPointCountGreaterThanOrEqualTo is = 297472
      
    • The BKD optimization is skipped when the estimated point count exceeds the threshold (iteratorCost/8).
    • Due to document ID reassignment during force merge, older timestamps are now associated with lower document IDs.
    • This correlation between document IDs and sort values results in less efficient BKD optimization.
    • Without BKD optimization, Lucene processes documents sequentially in document ID order (Using DocValues).
    • Each document must be individually examined rather than skipping entire ranges of non-competitive docs.
    • This issue specifically impacts descending timestamp sorts; ascending sorts may actually perform better.
  • I assume the same case with Benchmark dashboards.

Image

Also, to rule out whether the regression is due to OpenSearch integration with Lucene vs certain lucene changes, have you run similar benchmarks directly against Lucene?

@prudhvigodithi Created an issue for regression with desc_sort_timestamp b/w OS 2.19 and OS 3.0