Skip to content

first call to KafkaConsumer.poll() takes a long time #690

@cwelton

Description

@cwelton

Based on #673 I am polling quickly on the consumer to set the high water mark once it is created. But that first poll(), which has the sole purpose of setting the high water mark can take up to 20 seconds to complete, regardless of what the timeout is set to:

from __future__ import absolute_import, division, print_function
from kafka import KafkaConsumer
import time

timeout = 100

consumer = KafkaConsumer('test', bootstrap_servers='localhost:9093')

def poll():
    start = time.time()
    print("polling for %d ms" % timeout)
    partitions = consumer.poll(timeout)
    end = time.time()
    print("poll found %d partitions in %d ms" % (len(partitions), (end-start)*1000))

poll()
poll()

===============
bash$ python consumer.py 
polling for 100 ms
poll found 0 partitions in 26619 ms
polling for 100 ms
poll found 0 partitions in 100 ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions