-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
Force Init Connection #520
Comments
That's interesting, i am pretty sure connection is being established when you create the producer. Could be that some other things (topic metadata) is only being loaded when you produce the first message to that topic. Only thing that comes to mind, you could try to call poll first (this is getting producer events) |
I had tried $rk->poll(0);
sleep(1);
$topic->produce(...);
$rk->flush(); To see if the async $rk->poll(10_000);
$topic->produce(...);
$rk->flush(); And in both cases there was no latency improvement on the first |
I see. Then i am not sure what you could do to improve this. |
So i tried to reproduce this, but i have flush times around 300 - 400ms regardless of how many messages i produce 1,2 even 100. |
I didn't play with the number of messages, just noticed that if something has been Example: dump_time(function () use ($topic, $rk) {
$topic->produce(RD_KAFKA_PARTITION_UA, 0, "message");
$rk->flush(1000);
}); // 297ms
dump_time(function () use ($topic, $rk) {
$topic->produce(RD_KAFKA_PARTITION_UA, 0, "message");
$rk->flush(1000);
}); // 53ms |
Ah i see, so you shouldn't flush after every message, only after the last one 😄 |
I get that. The first call to |
Description
I wonder if either there is and I didn't find or if we could add a way to force initialize the connection.
context
I receive data in an HTTP request, based on that data, I have some amount of processing to do and a couple services to contact. Once that's done, I get a couple messages that I need to push to a kafka topic.
Because the kafka cluster I'm talking to is in a separate datacenter, I quite feel the pain of the lack of persistent connections and a call to
->produce()
followed by->flush()
takes roughly 300ms to complete.However if I call
->produce()
with a bogus message early on in the process, before I do my local processing / call on to other services, then when I'm ready to produce my actual messages, the connection is already properly established and it only takes 50ms.Because calls to
->produce()
pass the message to a separate thread, my main program isn't blocked at any point in time by this and no time is spent waiting here.The only way I've found to make this happen is to produce a message early on, but that means having a bunch of bogus messages on my topic. Was wondering if there are any other way to prep the connection in the background, without blocking the php program, so that it's fully available when needed.
thanks
No matter the result of this discussion, wanted to thank you for the hard work put in this extension and enabling kafka in PHP. I appreciate it very much.
The text was updated successfully, but these errors were encountered: