Skip to content

Add group commit for PostgreSQL replicator #1631

@altmannmarcelo

Description

@altmannmarcelo

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:

  1. 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.
  2. Configurable batch size: Consider making the row event batch cap configurable and increasing the default, similar to MySQL's replication-batch-size.
  3. Metrics: Add the same REPLICATOR_GROUP_COMMIT_TXNS and REPLICATOR_GROUP_COMMIT_DURATION histograms for observability.

Reference

  • MySQL group commit: d705c21aef
  • MySQL batch: d87341c923

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions