-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Transparent batching of ZK operations #13043
Conversation
dc7aa57
to
cb45f22
Compare
cb45f22
to
945cc28
Compare
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/batching/OpPut.java
Outdated
Show resolved
Hide resolved
...ata/src/main/java/org/apache/pulsar/metadata/impl/batching/AbstractBatchedMetadataStore.java
Outdated
Show resolved
Hide resolved
...ata/src/main/java/org/apache/pulsar/metadata/impl/batching/AbstractBatchedMetadataStore.java
Outdated
Show resolved
Hide resolved
...ata/src/main/java/org/apache/pulsar/metadata/impl/batching/AbstractBatchedMetadataStore.java
Outdated
Show resolved
Hide resolved
...ata/src/main/java/org/apache/pulsar/metadata/impl/batching/AbstractBatchedMetadataStore.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/ZKMetadataStore.java
Outdated
Show resolved
Hide resolved
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/ZKMetadataStore.java
Show resolved
Hide resolved
...ata/src/main/java/org/apache/pulsar/metadata/impl/batching/AbstractBatchedMetadataStore.java
Outdated
Show resolved
Hide resolved
import org.testng.annotations.Test; | ||
|
||
@Slf4j | ||
public class MetadataBenchmark extends MetadataStoreTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many resources does this test use? How does it take to complete?
Does it make sense to keep this running on CI?
I believe that if the test is no heavyweight we can keep it, but I wanted to double check with you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just takes a couple of seconds for each type and it doesn't take many resources, just keeping 2 threads busy.
Awesome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! One minor comment about exception handling.
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/ZKMetadataStore.java
Outdated
Show resolved
Hide resolved
batchOperation(Collections.singletonList(op)); | ||
return; | ||
} | ||
if (queue.size() > maxOperations && flushInProgress.compareAndSet(false, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will not trigger a flush if reach the size limitation? Looks like the current implementation is split into multiple batches when flushing, if we have enough data should be flush not the operations, we will wait for maxDelayMillis
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change LGTM and just left a minor comment, I think it should not be a big problem here, but will simplify implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, there are several optimizations that are still possible in the batching logic :) I'd say to continue in subsequent PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
For the doc side, I've discussed with @codelipenghui, the following changes will be made after 2.9.0 is released:
@merlimat any thoughts? Thanks |
* Transparent batching of ZK operations * Addressed comments * Handle default switch case * Fixed issues in MockZookeeper with usage of multi() * Wrap Throwable with MetadataStoreException * Fixed getChildren in MockZookeeper * Handle cases in which ZK is failing the partial request, but with error=OK * Fixed test to wait for put result * Fixed test that was not waiting on put future to complete
Motivation
It is more efficient to do operations to ZK in batch, using the
ZooKeeper.multi()
operation instead of individual calls.This reduces the RPC traffic between ZK client and servers and it also reduces the number of write transactions, since each
multi()
correspond to a single ZK transaction, containing multiple write operations.Modifications
AbstractBatchedMetadataStore
which contains the batching logicPreliminary results
This is done with the included basic benchmark, making request to the embedded ZK running on a laptop: