Skip to content
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

[improve][broker] Reduce the pressure from the transaction buffer in rolling restarts #32

Closed

Conversation

BewareMyPower
Copy link
Owner

Motivation

During the rolling restarts, the namespace bundle ownerships will change. Assuming there is a producer created on a single topic, and the ownership was transferred to the new broker. Assuming the namespace bundle has N topics and the namespace is tenant/ns,

  1. All N topics in the same bundle of that topic will be loaded.
  2. For each topic, the managed ledger will be initialized, when the transaction coordinator is enabled, a TopicTransactionBuffer will be created. 2.1 A Pulsar producer will be created on tenant/ns/__transaction_buffer_snapshot concurrently. 2.2 A Pulsar reader will be created on tenant/ns/__transaction_buffer_snapshot concurrently.
  3. Once all N readers are created, the owner of the snapshot topic will start dispatching messages to N readers. Each dispatcher will read messages from BookKeeper concurrently and might fail with too many requests error because BK can only have maxPendingReadRequestsPerThread pending read requests (default: 10000).

We have a numTransactionReplayThreadPoolSize config to limit the concurrency of transaction snapshot readers. However, it only limits the read loop. For example, if it's configured with 1, only 1 reader could read messages at the same time. However, N readers will be created concurrently. Each when one of these reader explicitly calls readNext, all N dispatchers at brokers side will dispatch messages to N readers.

The behaviors above brings much CPU pressure on the owner broker, especially for a small cluster with only two brokers.

Modifications

  • Synchronize the reader creation, read loop and the following process on its result.
  • Delay the snapshot producer creaton to when a message is written via LazySnapshotWriter.

…ders and writers in rolling restarts

### Motivation

During the rolling restarts, the namespace bundle ownerships will
change. Assuming there is a producer created on a single topic, and the
ownership was transferred to the new broker. Assuming the namespace
bundle has N topics and the namespace is `tenant/ns`,
1. All N topics in the same bundle of that topic will be loaded.
2. For each topic, the managed ledger will be initialized, when the
   transaction coordinator is enabled, a `TopicTransactionBuffer` will
   be created.
   2.1 A Pulsar producer will be created on
     `tenant/ns/__transaction_buffer_snapshot` concurrently.
   2.2 A Pulsar reader will be created on
     `tenant/ns/__transaction_buffer_snapshot` concurrently.
3. Once all N readers are created, the owner of the snapshot topic will
   start dispatching messages to N readers. Each dispatcher will read
   messages from BookKeeper concurrently and might fail with too many
   requests error because BK can only have
  `maxPendingReadRequestsPerThread` pending read requests (default: 10000).

We have a `numTransactionReplayThreadPoolSize` config to limit the
concurrency of transaction snapshot readers. However, it only limits the
read loop. For example, if it's configured with 1, only 1 reader could
read messages at the same time. However, N readers will be created
concurrently. Each when one of these reader explicitly calls `readNext`,
all N dispatchers at brokers side will dispatch messages to N readers.

The behaviors above brings much CPU pressure on the owner broker,
especially for a small cluster with only two brokers.

### Modifications

- Synchronize the reader creation, read loop and the following process
  on its result. Maintain only one reader for each namespace.
@BewareMyPower BewareMyPower force-pushed the bewaremypower/transaction-buffer-optimize branch from 9378fa9 to ffcc578 Compare July 23, 2024 13:43
@BewareMyPower BewareMyPower force-pushed the bewaremypower/transaction-buffer-optimize branch from ef22430 to 3b192a5 Compare July 26, 2024 07:13
@BewareMyPower BewareMyPower deleted the bewaremypower/transaction-buffer-optimize branch September 21, 2024 07:08
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.

1 participant