Skip to content

Read from kafka very slow! #306

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

Closed
magnum-ferox opened this issue Dec 30, 2017 · 5 comments · Fixed by #313
Closed

Read from kafka very slow! #306

magnum-ferox opened this issue Dec 30, 2017 · 5 comments · Fixed by #313
Labels

Comments

@magnum-ferox
Copy link

More than 1 second for each message!
arnaud-lb/php-rdkafka read over 1000 messager per second!
Ping to server ~ 50ms

@makasim
Copy link
Member

makasim commented Jan 3, 2018

  • What command do you use to consume messages?
  • Do you consume from a single queue or several ones at once?
  • What wait time do you use?

@makasim
Copy link
Member

makasim commented Jan 4, 2018

arnaud-lb/php-rdkafka read over 1000 messager per second!

@magnum-ferox Do you use low level or high level consumer?

@makasim
Copy link
Member

makasim commented Jan 4, 2018

Default consumer:

  • Produce 1000 messages 0.057 sec
  • Consume 1000 messages 60 sec

Consumer async commit true:

  • Produce 1000 messages 0.037 sec
  • Consume 1000 messages 2 sec

To enabled async commit do:

<?php
$context = (new RdKafkaConnectionFactory($config))->createContext();

$topic = $context->createTopic('a_topic');

$consumer = $context->createConsumer($topic);
$consumer->setCommitAsync(true);

@makasim makasim closed this as completed Jan 4, 2018
@makasim makasim reopened this Jan 4, 2018
@makasim
Copy link
Member

makasim commented Jan 4, 2018

Script to test:

<?php

use Enqueue\RdKafka\RdKafkaConnectionFactory;

include_once __DIR__.'/vendor/autoload.php';

$config = [
    'global' => [
        'group.id' => uniqid('', true),
        'metadata.broker.list' => getenv('RDKAFKA_HOST').':'.getenv('RDKAFKA_PORT'),
        'enable.auto.commit' => 'false',
    ],
    'topic' => [
        'auto.offset.reset' => 'beginning',
    ],
];

$context = (new RdKafkaConnectionFactory($config))->createContext();

sleep(3);


$topic = $context->createTopic(uniqid('', true));

$consumer = $context->createConsumer($topic);
$consumer->setCommitAsync(true);

$expectedBody = __CLASS__.time();

$time = microtime(true);
foreach (range(1, 1010) as $index) {
    $context->createProducer()->send($topic, $context->createMessage($index));
}
var_dump(microtime(true) - $time);

$index = 0;
$time = microtime(true);
while ($index < 1000) {
    if ($message = $consumer->receive(2000)) {
        $consumer->acknowledge($message);

        $index++;
    }
}

var_dump(microtime(true) - $time);

$context->close();

@magnum-ferox
Copy link
Author

magnum-ferox commented Jan 4, 2018

No. I try your script:
consume 20 messages without setCommitAsync(true) - double(16.388971090317)
consume 20 messages with setCommitAsync(true) - double(21.263849020004) !!!

and without $consumer->acknowledge($message);
20 messages without setCommitAsync(true) - double(15.642835140228)
20 messages with setCommitAsync(true) - double(15.63699388504)

librdkafka-0.11.1-1.el7.x86_64
php-pecl-rdkafka-3.0.5-1.el7.remi.7.1.x86_64
kafka_2.11-0.11.0.2
PHP 7.1.12

queue-interop/queue-interop (0.6.1)
enqueue/rdkafka (0.8.11)

ping to kafka server:
16 packets transmitted, 16 received, 0% packet loss, time 15014ms
rtt min/avg/max/mdev = 53.163/53.248/53.321/0.149 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants