Architecting Sharded Workloads on Oracle RAC: Eliminating GC Waits at the Application Tier
Attempting to resolve Oracle RAC interconnect bottlenecks through database-level parameter tuning is an architectural dead end; eliminating Cache Fusion contention requires restructuring workload affinity at the application and connection routing tiers.
TL;DR
- Problem: Round-robin connection routing across Oracle RAC nodes forces concurrent DML on the same 8 KB data and index leaf blocks to ping-pong over the private interconnect via Cache Fusion, turning local memory writes into multi-node network waits.
- Answer: Implement Cell-Based Application Affinity by hashing tenant or account keys in the application router to dedicated connection pools bound to single-preferred-instance Oracle services (
srvctl), paired withCACHE ... NOORDERsequences and hash-partitioned or reverse-key indexes.- Watch out: Pinning workloads trades Cache Fusion contention for hot-tenant CPU skew, cold-cache read spikes after instance failover, and connection churn on abrupt failback.
Situation
Multi-node Oracle Real Application Clusters (RAC) deployments cluster multiple compute instances over a private interconnect—typically bonded 25 GbE, 100 GbE, or RDMA over Converged Ethernet (RoCE) on engineered systems such as Exadata—sharing a single storage tier managed by Oracle Automatic Storage Management (ASM).
The default deployment pattern treats the RAC cluster as a homogeneous compute pool. Connection pools such as Oracle Universal Connection Pool (UCP) or HikariCP connect through a Single Client Access Name (SCAN) listener with LOAD_BALANCE=ON against a cluster-wide database service:
(DESCRIPTION=
(ADDRESS_LIST=
(LOAD_BALANCE=ON)
(FAILOVER=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=rac-scan.corp.internal)(PORT=1521))
)
(CONNECT_DATA=(SERVICE_NAME=oltp_generic_service))
)
Under round-robin or least-loaded connection distribution, consecutive transactions for the same customer or tenant land on different instances. A checkout request updating a customer ledger row executes on Instance 1; milliseconds later, a fulfillment worker updating a sibling order row in the same 8 KB block executes on Instance 3; simultaneously, a balance check runs on Instance 2. Because all instances share the same underlying datafiles in ASM, Oracle must coordinate block ownership in memory across every node touching that block.
The Problem
Oracle RAC maintains single-image cache coherency across instance System Global Areas (SGAs) using Cache Fusion, coordinated by the Global Cache Service (GCS, backed by LMS background processes) and the Global Enqueue Service (GES, backed by LMD and LMON). Only one instance can hold an exclusive lock to modify an 8 KB data block at any instant.
When Instance 3 needs to modify a dirty block currently cached in Instance 1’s SGA, it cannot read the stale copy on ASM storage. Instead, Cache Fusion executes a multi-hop protocol:
- Instance 3 requests an exclusive current-mode block from the block’s GCS resource master (for example, Instance 2).
- The GCS master forwards the request to Instance 1, the current holder.
- Instance 1 records a Past Image (PI) in its local buffer cache, downgrades its lock, and ships the 8 KB block over the private interconnect to Instance 3.
- Instance 3 receives the block, applies its redo-protected change, and notifies the GCS master.
Four physical constraints govern this path:
- Block-Transfer Bandwidth and Packet Rate: Each cross-node current-block transfer ships at least an 8 KB block payload plus GCS lock and acknowledgement messages. Even if an application only mutates a 60-byte row, Cache Fusion moves the entire 8,192-byte block—a 136x payload amplification. At 50,000 cross-node block transfers per second across a cluster, the interconnect must move
50,000 * 8,192 bytes = 409.6 MB/s(~3.28 Gbps) of raw block data alone before packet headers, Past Image acknowledgements, and consistent-read (CR) block clones. - LMS CPU and Scheduling Latency: Every block grant and transfer passes through
LMSbackground processes. When interconnect packet rates rise,LMSprocesses compete for CPU cycles with foreground sessions, inflatinggc current block 2-way,gc current block 3-way,gc cr block 2-way, andgc buffer busy acquirewait events in Active Session History (ASH). - Monotonic Sequence and Index Leaf Hotspots: Default Oracle sequences created with
ORDERor smallCACHEsizes serialize across instances onenq: SQ - contentionandDFS lock handle. Worse, monotonic primary keys and timestamp indexes insert every new row into the exact same right-hand B-Tree leaf block. All cluster instances fight for exclusive ownership of that single leaf block, causingenq: TX - index contentionalongsidegc current block busywaits. - Ineffectiveness of Local Storage Tuning: Raising
PCTFREEto spread rows across more blocks or increasingDB_CACHE_SIZEdoes not stop two instances from modifying the same logical tenant’s rows or the same right-hand index leaf. As long as routing is uncoordinated, adding RAC nodes increases the probability that the next transaction for a given entity lands on a remote instance.
How do platform architects eliminate cross-node Cache Fusion ping-ponging across a RAC cluster without rewriting relational schemas or abandoning shared-storage high availability?
Options Considered
When AWR and ASH reports show gc buffer busy acquire, gc current block busy, or enq: TX - index contention dominating database time, teams evaluate four architectural responses.
| Option | Mechanism | What It Solves | Where It Breaks | Decision |
|---|---|---|---|---|
| Database-Level Tuning | Raise PCTFREE, increase sequence CACHE, add LMS processes | Reduces row density per block and sequence metadata waits | Does not stop concurrent cross-node DML on the same logical entity or index leaf | Rejected as primary fix; sequence and index fixes kept as prerequisites |
| Active Data Guard Offload | Route read-only reporting queries to a physical standby | Isolates analytical table scans from OLTP SGA caches and gc cr waits | Does nothing for OLTP write-write contention on the primary cluster | Partial; adopted only for reporting isolation |
| Cell-Based Application Affinity | Hash tenant/entity ID at router to pinned pools and single-preferred-instance services | Keeps an entity’s working set in one instance’s SGA while retaining ASM failover | Introduces hot-tenant skew and cold-cache failover behavior | Chosen for OLTP workloads |
| Oracle Sharding | Split data into independent databases with a shard catalog | Eliminates shared cache coherency completely across shards | Requires shard-key schema redesign and restricts cross-shard joins | Deferred until single-cluster storage or redo limits are hit |
Database-level tuning fails because PCTFREE only reduces the chance that unrelated rows share an 8 KB block; it cannot prevent two transactions for the same customer or order from colliding across instances, nor does it stop right-hand B-Tree leaf contention on monotonic keys unless the index itself is altered. Active Data Guard is necessary to keep reporting scans from evicting OLTP buffers and generating gc cr transfers, but standby replicas are read-only and cannot absorb OLTP DML. Oracle Sharding provides true shared-nothing isolation, yet migrating an existing monolithic schema to sharded tables and rewritten cross-shard queries is a multi-quarter effort. Cell-Based Application Affinity delivers SGA locality with zero table schema changes and preserves ASM-backed failover.
The Cell-Based Application Affinity Architecture
Cell-Based Application Affinity decouples cluster compute capacity from homogeneous load balancing. Every RAC instance still mounts the same ASM diskgroups so any node can take over during an outage, but steady-state read/write traffic for a given data domain (tenant, geographic region, or account hash bucket) is deterministically routed to a designated home instance.
The design relies on three coordinated layers:
- Deterministic Hash Routing at the Application Tier: The API gateway or data-access layer computes a deterministic hash over the partition key—typically
tenant_idoraccount_id—and maps it to a logical shard (SHARD_ALPHA,SHARD_BETA, etc.). All requests for that key borrow connections from the pool bound to that shard. - Single-Preferred-Instance Oracle Services: Instead of one cluster-wide service, administrators create one Oracle service per shard via
srvctl, assigning a single instance as-preferredand a peer instance as-available. Under normal operation, the service runs only on its preferred instance, guaranteeing that all blocks for that shard’s tenants stay hot in one SGA. - Sequence and Index Dispersion: Even with tenant affinity, globally shared sequences and monotonic global indexes can still span shards. Sequences must use
CACHE ... NOORDER(or application-side UUIDv7/Snowflake IDs), and global monotonic indexes must be converted toREVERSE(for equality lookups) orGLOBAL PARTITION BY HASH(for range scans).
1. Provisioning Dedicated Affinity Services (srvctl)
Create separate services for each shard with Application Continuity (-failovertype TRANSACTION and -commit_outcome TRUE for Transaction Guard) so in-flight work can drain or replay cleanly during planned maintenance or node failure:
# Shard Alpha: Instance 1 Preferred, Instance 2 Available
srvctl add service -db PRODRAC \
-service svc_shard_alpha \
-preferred PRODRAC1 \
-available PRODRAC2 \
-failovertype TRANSACTION \
-failover_restore LEVEL1 \
-failoverretry 30 \
-failoverdelay 1 \
-commit_outcome TRUE
# Shard Beta: Instance 2 Preferred, Instance 1 Available
srvctl add service -db PRODRAC \
-service svc_shard_beta \
-preferred PRODRAC2 \
-available PRODRAC1 \
-failovertype TRANSACTION \
-failover_restore LEVEL1 \
-failoverretry 30 \
-failoverdelay 1 \
-commit_outcome TRUE
srvctl start service -db PRODRAC -service svc_shard_alpha
srvctl start service -db PRODRAC -service svc_shard_beta
2. Eliminating Sequence and Index Leaf Contention
Remove cross-instance sequence ordering and disperse right-hand index leaf inserts across multiple blocks:
-- Preallocate 10,000 sequence values per instance SGA; NOORDER avoids cross-node sync
ALTER SEQUENCE payments.order_seq CACHE 10000 NOORDER;
ALTER SEQUENCE payments.txn_seq CACHE 10000 NOORDER;
-- Disperse monotonic primary-key inserts when only equality lookups (=) are used
ALTER INDEX payments.pk_orders REBUILD REVERSE;
-- Use hash-partitioned global indexes when range scans (BETWEEN, >, <) are required
CREATE INDEX payments.idx_order_ts_hash ON payments.orders(order_timestamp)
GLOBAL PARTITION BY HASH(order_timestamp)
PARTITIONS 16
TABLESPACE USERS_INDEX;
3. Application Connection Pool Routing (Java / HikariCP)
Maintain isolated connection pools per shard service so tenant traffic never leaks onto the wrong instance. Use explicit unit suffixes (ms) on Oracle JDBC timeout properties (supported since Oracle JDBC 18.1+) to prevent seconds-versus-milliseconds misconfiguration:
public class ShardedConnectionManager {
private static final Map<String, HikariDataSource> dataSources = new ConcurrentHashMap<>();
static {
dataSources.put("SHARD_ALPHA", createPool(
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac-scan.corp.internal)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=svc_shard_alpha)))",
"pool-alpha", 40
));
dataSources.put("SHARD_BETA", createPool(
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac-scan.corp.internal)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=svc_shard_beta)))",
"pool-beta", 40
));
}
private static HikariDataSource createPool(String jdbcUrl, String poolName, int maxPoolSize) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(jdbcUrl);
config.setUsername("app_user");
config.setPassword(System.getenv("DB_CREDENTIAL"));
config.setMaximumPoolSize(maxPoolSize);
config.setMinimumIdle(10);
config.setPoolName(poolName);
config.addDataSourceProperty("oracle.jdbc.ReadTimeout", "5000ms");
config.addDataSourceProperty("oracle.net.CONNECT_TIMEOUT", "3000ms");
return new HikariDataSource(config);
}
public static Connection getConnectionForTenant(String tenantId) throws SQLException {
int bucket = Math.floorMod(tenantId.hashCode(), 2);
String targetShard = (bucket == 0) ? "SHARD_ALPHA" : "SHARD_BETA";
return dataSources.get(targetShard).getConnection();
}
}
Note the use of Math.floorMod instead of Math.abs(hashCode()) % 2: in Java, Math.abs(Integer.MIN_VALUE) remains negative, which would break modulo indexing on edge-case tenant IDs.
How It Rolls Out
Migrating an active RAC cluster from a generic service to cell-based affinity must happen in four reversible phases so a misconfigured pool or index never causes an outage.
- Phase 1 — Sequence and Global Index Dispersion: Alter hot sequences to
CACHE 10000 NOORDERand rebuild monotonic indexes asGLOBAL PARTITION BY HASH(orREVERSEonly after auditing SQL plans for range scans).- Validation gate: Verify
enq: SQ - contentionandenq: TX - index contentiondrop inV$SYSTEM_EVENT/ ASH without regressions in range-scan SQL elapsed times. - Rollback: Revert sequence attributes with
ALTER SEQUENCEor rebuild the index withoutREVERSE/ hash partitioning (ONLINErebuilds avoid table locks).
- Validation gate: Verify
- Phase 2 — Dedicated Service Provisioning: Create
svc_shard_alphaandsvc_shard_betaviasrvctlwith one-preferredinstance and one-availableinstance each, leaving the legacy generic service running.- Validation gate: Confirm
srvctl status service -db PRODRACshows each service active exclusively on its intended preferred node, and verify SCAN listener registration vialsnrctl status. - Rollback: Stop and remove the new services with
srvctl stop serviceandsrvctl remove service; existing traffic is unaffected.
- Validation gate: Confirm
- Phase 3 — Feature-Flagged Application Routing: Deploy the dual-pool
ShardedConnectionManagerbehind a runtime feature flag. Shift traffic incrementally (for example, 10% of tenants, then 50%, then 100%) from the generic pool to the tenant-hashed pools.- Validation gate: Monitor ASH for
gc buffer busy acquire,gc current block 2-way, andgc cr block 2-waywaits alongsideGV$INSTANCE_PING(AVERAGE_8KandCURRENT_8Kmicrosecond latency). Confirm each instance’s CPU and buffer cache hit ratio remain balanced. - Rollback: Flip the feature flag back to the generic service pool; connections drain without database DDL changes.
- Validation gate: Monitor ASH for
- Phase 4 — Cross-Tenant Reporting Offload: Repoint batch analytics and cross-tenant reporting jobs to an Active Data Guard physical standby service.
- Validation gate: Confirm
gc crblock transfers triggered by full-table scans disappear from the primary RAC AWR report. - Rollback: Repoint the reporting TNS alias back to a dedicated primary service if standby lag exceeds SLA.
- Validation gate: Confirm
In Practice
Based on how Oracle RAC’s Cache Fusion, Global Cache Service, and Clusterware service placement operate:
- Cache Fusion is strictly block-oriented: Oracle’s GCS tracks ownership at the 8 KB data block level, not the row level. When two instances modify different rows that happen to reside in the same data block—or different keys in the same B-Tree index leaf—
LMSmust still ship the 8 KB block and maintain Past Images across the interconnect. Pinning all writes for a given tenant to one preferred instance ensures that both the table blocks and the tenant’s working set stay local to one SGA. - Service relocation uses FAN draining: When an operator balances load across nodes using
srvctl relocate service -db PRODRAC -service svc_shard_alpha -oldinst PRODRAC1 -newinst PRODRAC2 -drain_timeout 60 -stopoption IMMEDIATE, Clusterware emits a Fast Application Notification (FAN) event. FAN-aware pools (such as Oracle UCP) stop routing new borrows to Instance 1 and allow in-flight transactions up to 60 seconds to commit before terminating stragglers. Standard pools without FAN support (such as default HikariCP without ONS integration) only discover the move on connection failure or max-lifetime expiry, making explicit-drain_timeoutbounds essential to prevent hung relocations. - Interconnect health is measured in
GV$INSTANCE_PING: Oracle’s backgroundPINGprocess periodically probes every peer instance with 500-byte and 8 KB messages and records round-trip latency in microseconds inGV$INSTANCE_PING(CURRENT_500B,AVERAGE_500B,CURRENT_8K,AVERAGE_8K). Interface binding and private-vs-public classification are verified inGV$CLUSTER_INTERCONNECTS.
Where It Breaks
Pinning workloads eliminates steady-state Cache Fusion contention, but it concentrates risk around skew, failover, and index semantics.
| Condition | Breaks how | Detect | Mitigate |
|---|---|---|---|
| Hot tenant skew | One high-volume tenant saturates its preferred node’s CPU while peer instances sit underutilized. | Per-instance CPU utilization and ASH active session imbalance across GV$ACTIVE_SESSION_HISTORY. | Split the hot tenant into its own dedicated service and relocate it with srvctl relocate service -drain_timeout. |
| Unplanned node failover | Service shifts to its -available peer whose SGA has none of that shard’s blocks cached, causing a burst of physical reads. | Spike in db file sequential read and db file scattered read waits immediately after failover. | Size ASM storage IOPS for cold-cache bursts; enable Application Continuity (-failovertype TRANSACTION) to replay interrupted work. |
| Abrupt failback on reboot | Recovering instance pulls its preferred service back immediately, severing active connections on the surviving node. | Sudden surge in connection errors and ORA-03113 / socket resets after node restart. | Keep failback manual or drain gradually with -drain_timeout during an off-peak maintenance window. |
Range scan on REVERSE index | Queries using BETWEEN, >, or < cannot use a REVERSE index range scan and fall back to full table scans. | Plan regression in V$SQL_PLAN showing TABLE ACCESS FULL on indexed columns. | Restrict REVERSE to equality-only PKs; use GLOBAL PARTITION BY HASH for range-scanned columns. |
| Cross-shard reporting on primary | Multi-tenant analytical queries scan blocks owned by multiple instances, triggering gc cr block shipping and evicting OLTP buffers. | Rise in gc cr multi block request and buffer cache misses during batch windows. | Route all cross-tenant reporting and BI queries to an Active Data Guard standby service. |
| Sequence cache loss on crash | Instance crash discards up to CACHE (e.g., 10,000) preallocated sequence values held in the local SGA. | Gaps in primary key sequence IDs after an instance restart. | Treat database sequences strictly as uniqueness generators; never rely on them for gap-free audit numbering. |
Key Takeaways
- Cache Fusion obeys network physics, not SQL tuning: Adding RAC nodes under round-robin routing increases cross-instance block ownership transfers; only deterministic routing at the application or service tier keeps hot blocks in a single SGA.
- Single-preferred-instance services preserve shared-storage HA: Defining one
-preferredand one-availableinstance per service withsrvctleliminates steady-state interconnect ping-ponging while keeping automatic ASM-backed failover intact. - Sequences and monotonic indexes are shared-cluster traps: Even with tenant-pinned services,
ORDERsequences and unpartitioned ascending indexes reintroduce cluster-wide contention unless converted toCACHE ... NOORDER,REVERSE(equality only), orGLOBAL PARTITION BY HASH. - Affinity trades interconnect waits for skew and cold-cache risk: Plan for hot-tenant service splitting, cold-SGA IOPS headroom after failover, and FAN-drained relocations (
-drain_timeout) before cutting over production traffic. - Measure interconnect health with the right views: Use
GV$CLUSTER_INTERCONNECTSto verify private network binding andGV$INSTANCE_PING(500B and 8 KB microsecond latencies) alongside ASHgcwait events to validate every rollout phase.
What to Do Next
- Problem: Round-robin connection routing across Oracle RAC turns local row mutations into cross-node 8 KB block transfers, saturating
LMSprocesses and the private interconnect. - Solution: Hash tenant or account keys at the application connection-pool tier to dedicated single-preferred-instance Oracle services, backed by
CACHE ... NOORDERsequences and hash-partitioned or reverse-key indexes. - Proof: In ASH and
V$SYSTEM_EVENT,gc buffer busy acquire,gc current block 2-way,gc cr block 2-way, andenq: SQ - contentiondrop sharply after Phase 1 and Phase 3 cutover whileGV$INSTANCE_PINGlatency stabilizes. - Action: Query
GV$ACTIVE_SESSION_HISTORYand your latest AWR “Top 10 Foreground Events” section this week; ifgcwaits andenq: TX - index contentionsit near the top, audit yoursrvctlservice topology and introduce a tenant-keyed pool behind a feature flag.
Interactive tools for this topic