Skip to content

[MySQL] BinLog Processing Queue backpressure handling #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 2, 2025

Conversation

Rentacookie
Copy link
Contributor

@Rentacookie Rentacookie commented May 21, 2025

Sometimes when a large number of MySQL binlog events were received in a short timeframe, the bucket storage could not persist the events fast enough, causing a backlog in the processing queue. This could lead to out of memory errors because the queue size itself was unbounded.

We now monitor the queue memory footprint, and if it is found to have reached the configured maximum, we pause the binlog listener until all the events currently in the queue have been processed, or after a certain amount of time has passed. Streaming is then immediately resumed.
This effectively limits the number of in flight events that are in memory at any given point when replicating.

To accomplish the above a big chunk of the binlog listening logic was moved to its own class. This cleans up the BinLogStream a bit and made for easier testing.

Additionally, the interim types declared for the Zongji listener were moved to the Zongji repository in this pull request:
powersync-ja/powersync-mysql-zongji#3

The binlog listener config has been updated to include the port, which solves the issue reported here:
#238

…kage directly

Added check for tablemap events
…tener class.

Introduced a mechanism to limit the maximum size of the binlog processing queue, thus also limiting memory usage.
This maximum processing queue size is configurable
# Conflicts:
#	modules/module-mysql/package.json
Copy link

changeset-bot bot commented May 21, 2025

🦋 Changeset detected

Latest commit: cce00b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@powersync/service-module-mysql Minor
@powersync/service-schema Patch
@powersync/service-image Patch
@powersync/service-core Patch
@powersync/service-core-tests Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
test-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rentacookie Rentacookie marked this pull request as ready for review May 27, 2025 11:51
@Rentacookie Rentacookie changed the title Mysql BinLog Processing Queue backpressure handling [MySQL] BinLog Processing Queue backpressure handling May 28, 2025
… memory usage rather than number of events.

Introduced a maximum timeout that the binlog processing queue can be paused before auto-resuming. This is to prevent the replication connection timing out.
@Rentacookie Rentacookie requested a review from rkistner May 29, 2025 14:37
rkistner
rkistner previously approved these changes Jun 2, 2025
@Rentacookie Rentacookie merged commit e11754d into main Jun 2, 2025
48 of 51 checks passed
@Rentacookie Rentacookie deleted the mysql-binlog-backpressure-handling branch June 2, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants