Problem
The PostgreSQL replicator flushes immediately on every Commit WAL event, meaning each transaction is sent as a separate RPC. For autocommit workloads (many single-row transactions), this results in one RPC per transaction, limiting throughput.
The MySQL replicator recently added group commit support (d705c21aef) which coalesces multiple consecutive committed transactions into a single RPC batch within a configurable time window. This achieved a 7.6x throughput improvement for single-row autocommit workloads.
The PostgreSQL replicator does not have an equivalent mechanism.
Current behavior
In postgres_connector/connector.rs, when a Commit WAL event arrives, all buffered actions are flushed immediately:
"On commit we flush, because there is no knowing when the next commit is coming"
There is no:
- Group commit deadline / wait window
- Transaction coalescing across commits
- Configurable
group-commit-wait-us or group-commit-max-trx parameters
Additional note
The PostgreSQL replicator also uses a fixed batch cap of MAX_QUEUED_INDEPENDENT_ACTIONS = 100 for row events within a transaction, while MySQL's replication-batch-size defaults to 50,000 and is configurable. For large transactions, PostgreSQL may flush far more frequently.
Proposed solution
Port the group commit mechanism from the MySQL connector to the PostgreSQL connector:
- Group commit: After a transaction commits, wait up to
group-commit-wait-us (default 500µs) for additional transactions to arrive, coalescing up to group-commit-max-trx (default 20) transactions into a single RPC batch.
- Configurable batch size: Consider making the row event batch cap configurable and increasing the default, similar to MySQL's
replication-batch-size.
- Metrics: Add the same
REPLICATOR_GROUP_COMMIT_TXNS and REPLICATOR_GROUP_COMMIT_DURATION histograms for observability.
Reference
- MySQL group commit: d705c21aef
- MySQL batch: d87341c923
Problem
The PostgreSQL replicator flushes immediately on every
CommitWAL event, meaning each transaction is sent as a separate RPC. For autocommit workloads (many single-row transactions), this results in one RPC per transaction, limiting throughput.The MySQL replicator recently added group commit support (d705c21aef) which coalesces multiple consecutive committed transactions into a single RPC batch within a configurable time window. This achieved a 7.6x throughput improvement for single-row autocommit workloads.
The PostgreSQL replicator does not have an equivalent mechanism.
Current behavior
In
postgres_connector/connector.rs, when aCommitWAL event arrives, all buffered actions are flushed immediately:There is no:
group-commit-wait-usorgroup-commit-max-trxparametersAdditional note
The PostgreSQL replicator also uses a fixed batch cap of
MAX_QUEUED_INDEPENDENT_ACTIONS = 100for row events within a transaction, while MySQL'sreplication-batch-sizedefaults to 50,000 and is configurable. For large transactions, PostgreSQL may flush far more frequently.Proposed solution
Port the group commit mechanism from the MySQL connector to the PostgreSQL connector:
group-commit-wait-us(default 500µs) for additional transactions to arrive, coalescing up togroup-commit-max-trx(default 20) transactions into a single RPC batch.replication-batch-size.REPLICATOR_GROUP_COMMIT_TXNSandREPLICATOR_GROUP_COMMIT_DURATIONhistograms for observability.Reference