Skip to main content

RGW Localized Reads on Ceph Tentacle

With crush_location and rados_replica_read_policy=localize set on the RGW, every S3 read byte is served by the local OSD: 1,006,743,283 bytes out of 1,006,743,283, against 29.2% with no setting at all. Two conditions apply: the RGW's rack must appear in every acting set, and the daemon must be restarted — the option is not applied at runtime, contrary to what ceph config help advertises.

Test bed: Ceph 20.2.4 (tentacle), single node u01h01, 3 SSD OSDs spread across 3 CRUSH racks, RGW deployed by cephadm. Seven campaigns of 120 S3 GETs = 960 MiB each.

Mechanism​

Two separate settings, both required, applied on the client side — here the RGW daemon.

OptionRoleValuesRuntime-updatable
crush_locationWhere the client sits in the CRUSH treee.g. root=default rack=rack1 host=u01h01-r1no, as advertised and verified
rados_replica_read_policyRead routing policydefault, balance, localizeadvertised yes, false in practice

On every read, if the policy is localize, the Objecter walks the PG's acting set and computes each OSD's common-ancestor distance to the client's crush_location (CrushWrapper::get_common_ancestor_distance). That distance is the id of the finest bucket type where client and OSD coincide: osd=0, host=1, chassis=2, rack=3, … root=10. The OSD with the smallest distance wins; on a tie the primary is kept.

Direct consequence: a local read is only possible if the PG's acting set contains an OSD close to the client. Otherwise the read falls back to the primary. The mechanism exists for replication only — under erasure coding the primary must reconstruct the data from the shards, so no replica can answer on its own.

Related option: rados_replica_read_policy_on_objclass (default false) is meant to extend the policy to objclass operations, i.e. RADOS class calls — rgw.bucket_list on the bucket index, but also rgw.gc_list, timeindex.list, fifo.get_meta, cls_user, and outside RGW cls_rbd. Measured with no observable effect, see below.

Test bed and protocol​

The cluster is a single node, so rack buckets plus fake host buckets, one per rack, give each OSD a distinct CRUSH location.

Three racks for size=3: CRUSH must take all three, so every acting set holds all three OSDs. Verified on the data pool — 64 PGs out of 64 and 48 RADOS objects out of 48 have osd.0 in their acting set. That is the precondition for 100% locality.

The RGW sits in rack1, facing osd.0. Rule rep3_rack (chooseleaf firstn 0 type rack), size=3, min_size=2, inherited by every RGW pool. On a single node, osd_crush_update_on_start=false is mandatory: without it each OSD moves back under host=u01h01 on restart and the topology collapses.

Measurement protocol:

  • 24 S3 objects of 8 MiB, i.e. 48 RADOS objects of 4 MiB in default.rgw.buckets.data (head + tail, rgw_obj_stripe_size = 4 MiB). Pool pinned to pg_num=64, autoscaler off to freeze the mapping.
  • Read load: 5 passes × 24 GETs = 120 GETs = 960 MiB, i.e. exactly 240 RADOS reads of 4 MiB.
  • Metric: delta of osd.op_r and osd.op_r_out_bytes sampled on each OSD through ceph tell osd.N perf dump. op_r_out_bytes discriminates best — background traffic is measured in bytes, the payload in hundreds of MiB.
  • noscrub and nodeep-scrub set for the duration of the campaigns.

Consistency check: each of the seven campaigns served exactly 960.1 MiB.

Results​

Campaigns 01 and 03 bracket the result: 29.2% versus 100.0% of bytes served by osd.0, the local OSD.

Three things to read here:

  1. Campaign 02 is byte-for-byte identical to the baseline: crush_location on its own localizes nothing.
  2. Campaign 04 shows that changing the policy without a restart does nothing — it stays at 100%.
  3. Campaign 07, with osd.0 stopped, serves all 120 GETs without a single error from the two remaining OSDs.

Why locality is total​

Three racks for size=3: CRUSH must take all three, so every acting set holds all three OSDs and osd.0 is always available locally. Object-by-object check — all 48 RADOS objects in the data pool have osd.0 in their acting set.

The measurement leaves no ambiguity: 1,006,743,283 bytes out of 1,006,743,283 served by osd.0, i.e. 100.000%. The counters on osd.1 and osd.2 record 12 residual operations, but 0 bytes of data — background traffic.

The baseline corroborates the mechanism from the other end. With no localization, the 48 objects have osd.0 as primary fourteen times, osd.1 fifteen times and osd.2 nineteen times, i.e. 29.17 / 31.25 / 39.58%. The measured bytes come to 293,624,191 / 314,613,620 / 398,505,472, i.e. 29.2 / 31.3 / 39.6%. The match is exact: reads follow the primary, nothing else.

This perfect locality is a property of the topology. Where racks outnumber the replication size, CRUSH takes only a subset of them: PGs with no replica in the client's rack fall back to their primary, and locality becomes partial by construction.

What does not work as advertised​

ceph config help rados_replica_read_policy reports Can update at runtime: true. That is false for an already-running RGW daemon. Demonstrated in three steps:

  1. The RGW runs with localize: 100% of bytes on osd.0 (campaign 03).
  2. Set ceph config set client.rgw.s3 rados_replica_read_policy default, with no restart. The process does see the change — its admin socket answers {"rados_replica_read_policy": "default"}.
  3. The behaviour does not change: campaign 04, still 100% of bytes on osd.0. Only after ceph orch daemon restart does campaign 05 fall back exactly onto the baseline.

Cause: the Objecter caches the policy at initialization and no config observer re-reads it. Operational consequence: any change to the read policy requires restarting the RGWs. Worth reporting upstream — either the option becomes genuinely dynamic, or the can update at runtime flag should be set to false so it stops misleading.

rados_replica_read_policy_on_objclass has no observable effect either. Its name suggests it gates localization of bucket index reads; it does not — the policy alone is enough. Load of 200 S3 LIST requests, read ops per OSD:

Configurationosd.0osd.1osd.2
localize + objclass false2,210216
localize + objclass true2,210216
default + objclass true7212,209

The default.rgw.buckets.index pool has a single PG, acting [2,1,0], primary osd.2, while the RGW faces osd.0: primary and local OSD are two different OSDs, which discriminates cleanly. Under localize, the 2,210 index reads (200 LISTs × 11 shards) go to the local OSD whether the flag is false or true — the two campaigns are byte-identical at 1,468,273 bytes. Under default, they go back to the primary.

ceph tell osd.0 dump_historic_ops confirms these are genuine class calls served by a non-primary replica, [call rgw.bucket_list in=14b] × 220, and the other objclass reads carry the flag in plain sight: [call timeindex.list], [call fifo.get_meta], [call rgw.gc_list] and [pgnls] are all marked ondisk+read+localize_reads. Writes ([call lock.lock], [call lock.unlock]) carry ondisk+write without it and go to the primary, as expected.

So in 20.2.4 the client sets CEPH_OSD_FLAG_LOCALIZE_READS on read-side class calls regardless of this setting. Nothing needs enabling to get localization on the bucket index.

Other friction encountered:

  • ceph orch daemon restart refuses to restart the only RGW ("Not enough remaining RGW daemons"). It needs --force, or a second RGW.
  • ceph config show does not accept the short name of an RGW daemon: the full entity is required, client.rgw.s3.u01h01.uwcpuu.
  • ceph tell client.rgw.<id> is rejected ("Bad target type 'client'"): go through the admin socket. Two sockets exist per RGW, and one of them refuses the connection.

Recommendations for production​

Three pieces, not one: the CRUSH topology, the client's crush_location, and the policy.

ceph config set client.rgw.<service> crush_location "root=default rack=<rack> host=<host>"
ceph config set client.rgw.<service> rados_replica_read_policy localize
ceph orch restart rgw.<service>
  • Each RGW needs its own crush_location. Target the precise section client.rgw.<service>.<host>.<suffix>, not client.rgw globally, or every RGW will believe it sits in the same place.
  • The total locality measured here is a property of the topology: 3 racks for 3 replicas, so the client's rack appears in every acting set. Where racks outnumber the replication size, CRUSH takes only a subset and locality becomes partial by construction.
  • Declaring host= on top of rack= makes an OSD on the same server (distance 1) win over one merely in the same rack (distance 3). Useful for an RGW colocated on OSD nodes.
  • Replication only, no effect under erasure coding.
  • Bucket index reads are already localized by the policy alone: nothing extra to enable, rados_replica_read_policy_on_objclass can stay false.
  • No availability risk: losing the local OSD simply sends reads back to the primary, with no errors.
  • balance remains available when the goal is to spread read load rather than shorten it: 28.3 / 40.4 / 31.2% across the acting set.

The replayable scripts and the raw counter snapshots live on u01h01 under /root/localized-reads/, with the detailed report in /root/lectures-locales-rgw.md.

53b2963 (doc/rgw: add rgw localized reads on tentacle)