Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Optimize produce request handler #466

Conversation

BewareMyPower
Copy link
Collaborator

Motivation

There're some problems with produce performance.

The main problem is the pending produce queue. It holds multiple pending produce requests (PendingProduce), which wait until PersistentTopic is ready and the MemoryRecords is encoded. First, PendingProduces wait for different futures of PersistentTopic. Second, encoding MemoryRecords is fast so that putting it to another thread is not necessary and could cause some performance overhead.

Modifications

  1. Encoding MemoryRecords in the same thread of handleProduceRequest.
  2. Check if the CompletableFuture<PersistentTopic> is done.
    • If it's done, just publish the messages directly without pushing the pending produce requests to the queue.
    • Otherwise, reuse the previous CompletableFuture<PersistentTopic>. This trick is performed by PendingTopicFutures, which uses the previous CompletableFuture<PersistentTopic> by thenApply or exceptionally.
  3. Add tests for PendingTopicFutures.
  4. Use a map of partition and response instead of a map of partition and response future in handleProduceRequest.

@BewareMyPower BewareMyPower requested a review from jiazhai as a code owner May 5, 2021 08:40
@BewareMyPower
Copy link
Collaborator Author

BewareMyPower commented May 5, 2021

Here's a performance compare with 200 MB/s throughput on a topic with 16 partitions.

image

The blue line is the result of this PR. Though there're still some jitters, the result is much better than before.

@BewareMyPower
Copy link
Collaborator Author

The Codacy check failed because the original code that is removed in this PR can't pass the check, just ignore it.

image

@BewareMyPower BewareMyPower changed the title Optimize produce request handler [WIP] Optimize produce request handler May 5, 2021
@BewareMyPower
Copy link
Collaborator Author

The DistributedClusterTest may fail, I'll take a look.

@BewareMyPower BewareMyPower changed the title [WIP] Optimize produce request handler Optimize produce request handler May 6, 2021
@BewareMyPower BewareMyPower self-assigned this May 7, 2021
@BewareMyPower BewareMyPower merged commit 808b969 into streamnative:master May 7, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/optimize-produce-queue branch May 7, 2021 12:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants