Open ragaur-tibco opened 6 months ago
For the purpose of reduce the sync-api send message latency, client will flush messages to broker when you call the sync-api. And sync-api will block your app's threads, if we don't flush messages to broker but waiting until the batch is full, it may block all the threads of your app.
/cc @gaoran10 @codelipenghui
Thanks for the good issue report @ragaur-tibco !
For the purpose of reduce the sync-api send message latency, client will flush messages to broker when you call the sync-api.
@dao-jun Yes, this is reasonable, but the problem is that this doesn't seem to be documented any where.
I found the flushing logic here: https://github.com/apache/pulsar/blob/ffff639a1b73a34bbb5115503d4c7783bb2a2770/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TypedMessageBuilderImpl.java#L82-L86
I think @ragaur-tibco's issue report is great and the minimum resolution is to document the behavior. It seems that there could be a use case where one would want to achieve batching while using the synchronous API. That's not currently supported. We have 2 options for resolving this:
I'm personally in favor of option 1., but I'm open for option 2. if someone supports that and the change goes through the typical PIP process we have in Pulsar.
@lhotari I think support batch message for sync-api has potential risks, as I mentioned before, if we don't flush messages but waiting until the batch is full, it may block users' app threads for a long while. Especially there are many producers send message in batch in a single app, it may block all the threads.
I prefer option 1, and I'll fix the doc later.
Search before asking
Read release policy
Version
3.2.x
Minimal reproduce step
What did you expect to see?
number of messages should increase from 0 to 4 in a single batch(as max number of messages configured in a single batch was 5) and below are the pulsar SDK logs which should print in console
just like working in async mode
What did you see instead?
number of messages in a single batch is always 0 while using the synchronous mode
Anything else?
No response
Are you willing to submit a PR?