Segment replication

With segment replication, segment files are copied across shards instead of documents being indexed on each shard copy. This improves indexing throughput and lowers resource utilization at the expense of increased network utilization.

When the primary shard sends a checkpoint to replica shards on a refresh, a new segment replication event is triggered on replica shards. This happens:

  • When a new replica shard is added to a cluster.
  • When there are segment file changes on a primary shard refresh.
  • During peer recovery, such as replica shard recovery and shard relocation (explicit allocation using the move allocation command or automatic shard rebalancing).

Segment replication is the first feature in a series of features designed to decouple reads and writes in order to lower compute costs.

Use cases

  • Users who have high write loads but do not have high search requirements and are comfortable with longer refresh times.
  • Users with very high loads who want to add new nodes, as you do not need to index all nodes when adding a new node to the cluster.
  • OpenSearch cluster deployments with low replica counts, such as those used for log analytics.

Segment replication configuration

To set segment replication as the replication strategy, create an index with replication.type set to SEGMENT:

  1. PUT /my-index1
  2. {
  3. "settings": {
  4. "index": {
  5. "replication.type": "SEGMENT"
  6. }
  7. }
  8. }

copy

In segment replication, the primary shard is usually generating more network traffic than the replicas because it copies segment files to the replicas. Thus, it’s beneficial to distribute primary shards equally between the nodes. To ensure balanced primary shard distribution, set the dynamic cluster.routing.allocation.balance.prefer_primary setting to true. For more information, see Cluster settings.

Segment replication currently does not support the wait_for value in the refresh query parameter.

For the best performance, we recommend enabling both of the following settings:

  1. Segment replication backpressure.
  2. Balanced primary shard allocation:
  1. curl -X PUT "$host/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
  2. {
  3. "persistent": {
  4. "cluster.routing.allocation.balance.prefer_primary": true,
  5. "segrep.pressure.enabled": true
  6. }
  7. }

copy

Considerations

When using segment replication, consider the following:

  1. Enabling segment replication for an existing index requires reindexing.
  2. Rolling upgrades are not currently supported. Full cluster restarts are required when upgrading indexes using segment replication. See Issue 3881.
  3. Cross-cluster replication does not currently use segment replication to copy between clusters.
  4. Segment replication leads to increased network congestion on primary shards. See Issue - Optimize network bandwidth on primary shards.
  5. Integration with remote-backed storage as the source of replication is currently not supported.
  6. Read-after-write guarantees: The wait_until refresh policy is not compatible with segment replication. If you use the wait_until refresh policy while ingesting documents, you’ll get a response only after the primary node has refreshed and made those documents searchable. Replica shards will respond only after having written to their local translog. We are exploring other mechanisms for providing read-after-write guarantees. For more information, see the corresponding GitHub issue.
  7. System indexes will continue to use document replication internally until read-after-write guarantees are available. In this case, document replication does not hinder the overall performance because there are few system indexes.

Benchmarks

During initial benchmarks, segment replication users reported 40% higher throughput than when using document replication with the same cluster setup.

The following benchmarks were collected with OpenSearch-benchmark using the stackoverflow and nyc_taxi datasets.

The benchmarks demonstrate the effect of the following configurations on segment replication:

Your results may vary based on the cluster topology, hardware used, shard count, and merge settings.

Increasing the workload size

The following table lists benchmarking results for the nyc_taxi dataset with the following configuration:

  • 10 m5.xlarge data nodes

  • 40 primary shards, 1 replica each (80 shards total)

  • 4 primary shards and 4 replica shards per node

40 GB primary shard, 80 GB total240 GB primary shard, 480 GB total
Document ReplicationSegment ReplicationPercent differenceDocument ReplicationSegment ReplicationPercent difference
Store size85.278191.2268N/A515.726558.039N/A
Index throughput (number of requests per second)Minimum148,134185,09224.95%100,140168,33568.10%
Median160,110189,79918.54%106,642170,57359.95%
Maximum175,196190,7578.88%108,583172,50758.87%
Error rate0.00%0.00%0.00%0.00%0.00%0.00%

As the size of the workload increases, the benefits of segment replication are amplified because the replicas are not required to index the larger dataset. In general, segment replication leads to higher throughput at lower resource costs than document replication in all cluster configurations, not accounting for replication lag.

Increasing the number of primary shards

The following table lists benchmarking results for the nyc_taxi dataset for 40 and 100 primary shards.

40 primary shards, 1 replica100 primary shards, 1 replica
Document ReplicationSegment ReplicationPercent differenceDocument ReplicationSegment ReplicationPercent difference
Index throughput (number of requests per second)Minimum148,134185,09224.95%151,404167,3919.55%
Median160,110189,79918.54%154,796172,99510.52%
Maximum175,196190,7578.88%166,173174,6554.86%
Error rate0.00%0.00%0.00%0.00%0.00%0.00%

As the number of primary shards increases, the benefits of segment replication over document replication decrease. While segment replication is still beneficial with a larger number of primary shards, the difference in performance becomes less pronounced because there are more primary shards per node that must copy segment files across the cluster.

Increasing the number of replicas

The following table lists benchmarking results for the stackoverflow dataset for 1 and 9 replicas.

10 primary shards, 1 replica10 primary shards, 9 replicas
Document ReplicationSegment ReplicationPercent differenceDocument ReplicationSegment ReplicationPercent difference
Index throughput (number of requests per second)Median72,598.1090,776.1025.04%16,537.0014,429.80−12.74%
Maximum86,130.8096,471.0012.01%21,472.4038,235.0078.07%
CPU usage (%)p501718.85710.92%69.8578.833−87.36%
p907682.1338.07%9986.4−12.73%
p991001000%1001000%
p1001001000%1001000%
Memory usage (%)p503523−34.29%4240−4.76%
p905957−3.39%59636.78%
p996961−11.59%66706.06%
p1007262−13.89%69724.35%
Error rate0.00%0.00%0.00%0.00%2.30%2.30%

As the number of replicas increases, the amount of time required for primary shards to keep replicas up to date (known as the replication lag) also increases. This is because segment replication copies the segment files directly from primary shards to replicas.

The benchmarking results show a non-zero error rate as the number of replicas increases. The error rate indicates that the segment replication backpressure mechanism is initiated when replicas cannot keep up with the primary shard. However, the error rate is offset by the significant CPU and memory gains that segment replication provides.

Next steps

  1. Track future enhancements to segment replication.
  2. Read this blog post about segment replication.