Kafka
  1. Kafka
  2. KAFKA-1071

The random partition selected in DefaultEventHandler is not random across producer instances

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.8.0
    • Fix Version/s: 0.8.0
    • Component/s: core
    • Labels:
      None

      Description

      In DefaultEventHandler, partitionCounter is initialized to 0. If multiple producers start at about the same time, they likely will always select the same partition.

      1. KAFKA-1071.v1.patch
        1 kB
        Guozhang Wang
      2. KAFKA-1071.v2.patch
        2 kB
        Guozhang Wang

        Activity

        Hide
        Guozhang Wang added a comment -

        Use random int as init value.

        Show
        Guozhang Wang added a comment - Use random int as init value.
        Hide
        Jun Rao added a comment -

        Thanks for the patch. Would it be better to just get a random int in getPartition()? In the current approach, if the multiple producer instances somehow get into the lock-step mode, they will never get out of that mode, if partitions are always available.

        Show
        Jun Rao added a comment - Thanks for the patch. Would it be better to just get a random int in getPartition()? In the current approach, if the multiple producer instances somehow get into the lock-step mode, they will never get out of that mode, if partitions are always available.
        Hide
        Guozhang Wang added a comment -

        Good point. Attached v2 for that, also tested that Random.nextInt will not return the same numbers even being called at roughly the same time.

        Show
        Guozhang Wang added a comment - Good point. Attached v2 for that, also tested that Random.nextInt will not return the same numbers even being called at roughly the same time.
        Hide
        Neha Narkhede added a comment -

        It might work better if we seed the random with the current timestamp - http://docs.oracle.com/javase/6/docs/api/java/util/Random.html#Random(long)

        Not sure how good Scala's Random implementation is, I tend to trust Java more on that.

        Show
        Neha Narkhede added a comment - It might work better if we seed the random with the current timestamp - http://docs.oracle.com/javase/6/docs/api/java/util/Random.html#Random(long ) Not sure how good Scala's Random implementation is, I tend to trust Java more on that.
        Hide
        Guozhang Wang added a comment -

        I tested the Random implementation a bit and the results look good. One thing of using timestamp is that producer clients may start at roughly the same time, and I do not know if there is a correlation between numeric difference of seed values and the numeric difference between the generated values.

        Show
        Guozhang Wang added a comment - I tested the Random implementation a bit and the results look good. One thing of using timestamp is that producer clients may start at roughly the same time, and I do not know if there is a correlation between numeric difference of seed values and the numeric difference between the generated values.
        Hide
        Neha Narkhede added a comment -

        Though it is unlikely that the nanosecond timestamp across producer instances would match, I don't feel strongly about the change.

        +1

        Show
        Neha Narkhede added a comment - Though it is unlikely that the nanosecond timestamp across producer instances would match, I don't feel strongly about the change. +1
        Hide
        Jun Rao added a comment -

        Thanks for patch v2. +1. Committed to 0.8.

        Show
        Jun Rao added a comment - Thanks for patch v2. +1. Committed to 0.8.

          People

          • Assignee:
            Guozhang Wang
            Reporter:
            Jun Rao
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development