Skip to content

maxPendingMessagesAcrossPartitions not respected #230

Closed

Description

@rkaw92

(NOTE: This was previously named "await flush() does not actually flush" - leaving this here in case it helps somebody's search)

Hi,

I have a problem with the Producer where I do this in a loop:

  • send() a given number of messages
  • await flush(), so that the send queue is empty
  • send() more messages... (loop)

I'd expect the following to hold true: as long as the number of messages I send between flushes is lower than maxPendingMessages, I should be able to send. But, this assumption is broken: when I send immediately after flush has resolved, I get a ProducerQueueIsFull error.

I think that, when flush() resolves, the messages haven't actually been flushed. This, or there exists another, hidden limit that triggers ProducerQueueIsFull.

I've patched the benchmark client to demonstrate this: https://gist.github.com/rkaw92/32ac9ecaa4a5a1fa0d80ba4c4dec19bc

The only differences from the "normal" perf_producer.js are:

  • the ProducerConfig (maxPendingMessages: 10000 - ten thousand - and some other options)
  • the removal of delay(1000) in each iteration.

Note that, to run the producer perf test, you may need to downgrade hdr-histogram-js - this is currently bugged in this repo:

npm install hdr-histogram-js@1

With the no-delay version, it's easy to trigger a ProducerQueueIsFull error:

$ node perf/perf_producer.js -m 10000 -i 10 -u pulsar://mycluster.url --topic persistent://rkaw-test/benchmark/perf_producer
----------------------
size: 1024
url: pulsar://mycluster.url
topic: persistent://rkaw-test/benchmark/perf_producer
iteration: 10
messages: 10000
----------------------
Throughput produced: 84717.558  msg/s --- 661.856 Mbit/s --- Latency: mean: 0 ms - med: 0 - 95pct: 0 - 99pct: 0 - 99.9pct: 0 - 99.99pct: 0 - Max: 0
node:internal/process/promises:265
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: Failed to send message: ProducerQueueIsFull]

It's even possible to do this with lower message counts: m 5000 -i 10 also produces the error ProducerQueueIsFull.

I believe I'm using flush() correctly by awaiting it. Is there a problem with operation ordering between send() and flush()? This happens regardless of batchingEnabled - setting it to false changes nothing.

Also, this seems rather troubling: if I change to blockIfQueueFull, and re-run perf_producer.js, I get this at the very end:

[Error: Failed to send message: AlreadyClosed]

Since the code does an orderly await producer.flush() at the end of every iteration, and the producer.close() only takes place at the end after the last iteration, is there an ordering issue between flush() and the rest?

(This is all on the newest code from master, so after the refactoring from worker threads to async)

Activity

  1. Matt-Esch commented on Sep 7, 2022

    @Matt-Esch
    Contributor

    If the async flush method isn't flushing correctly, this is likely to be an issue in the underlying pulsar library. I don't doubt that it's possible for the library to not flush correctly, but I don't see any issue in the calling code in the node wrapper. https://github.com/apache/pulsar-client-node/blob/master/src/Producer.cc#L136

    It's also possible that async publish increases the throughput making it easier to fill the queue. The problem with the sync methods with the async worker threads is that they are limited in concurrency so it might be enough back pressure to prevent you running into the queue full issue. There was also an issue with calling send because unless you waited for each send to complete, they could happen out of order, further reducing the throughput.

    It looks like the issue you referenced comes to similar conclusions about the underlying behavior of the flush api in the C++ library. You didn't mention which specific version you are using, it was necessary to upgrade the client library to make all async methods work correctly.

    Personally if I was in your position I would either be looking to debug the C++ client library or I would be wrapping the publish code to backoff if the queue is full, i.e. handle the error with some backoff.

  2. rkaw92 commented on Sep 8, 2022

    @rkaw92
    ContributorAuthor

    I currently rely on back-off, but it's not optimal. As for filling the queue, I'd think that issuing exactly as many send() operations as should fit in the buffer (exactly equal to maxPendingMessages) and then flushing should get rid of them all, so that the new pending messages = 0.

    The code is running the latest master version from this repository. As for the C++ counterpart, it's 2.9.1 from a .deb.

    I'll try to debug the C++ library - clearly, there's something going on with flush unreliability. I'll also check if the behavior is the same between the normal Producer and the PartitionedProducer.

  3. rkaw92 commented on Sep 8, 2022

    @rkaw92
    ContributorAuthor

    Aha!

    https://github.com/apache/pulsar-client-node/blob/master/src/ProducerConfig.cc#L103

    Setting maxPendingMessagesAcrossPartitions actually calls pulsar_producer_configuration_set_max_pending_messages, not pulsar_producer_configuration_set_max_pending_messages_across_partitions.

    So the default stays the same at 50k: https://github.com/apache/pulsar/blob/bff34000385f6faf6dbff4385d0dc562602ac623/pulsar-client-cpp/lib/ProducerConfigurationImpl.h#L36

    And indeed, I'm only able to reproduce this error on a partitioned topic. Let's see:

    • I set maxPendingMessages to 10000 (ten thousand) in code
    • I set maxPendingMessagesAcrossPartitions to some really high value like 1 million
    • I'm writing to a topic with 16 partitions

    So, by my logic, the maximum number I can actually fit between flush() calls is 50000 (the default from C++), divided by the partition count. 50000 / 16 = 3125. This is regardless of my settings. Let's see if this is true!

    node perf/perf_producer.js -m 3125 -i 10 -u pulsar://mycluster.url --topic persistent://rkaw-test/benchmark/perf_producer
    # this completes perfectly
    

    and...

    node perf/perf_producer.js -m 3126 -i 10 -u pulsar://mycluster.url --topic persistent://rkaw-test/benchmark/perf_producer
    [...]
    [Error: Failed to send message: ProducerQueueIsFull]
    

    So yeah, it's the configuration not making it to the actual client. I think flush() works, after all. Some caveats:

    • It only works with batchEnabled: true - flushing seems to have no effect if you disable batches (by design?), so you can still get ProducerQueueIsFull in non-batch mode
    • This problem only affects publishing to a partitioned topic
    • I'm not sure why the Producer is erroring out so easily, i.e. if you exceed the real maxPendingMessages by 1. I'd expect the messages to go to different partitions - maybe batching is causing them to bunch up in one underlying Producer for 1 partition.

    I'll try a local fix that actually propagates pulsar_producer_configuration_set_max_pending_messages_across_partitions and see if that alleviates the problem. (EDIT: It did. ✔️ )

  4. changed the title [-]await flush() does not actually flush[/-] [+]maxPendingMessagesAcrossPartitions not respected[/+] on Sep 8, 2022
  5. added a commit that references this issue on Sep 8, 2022
    07bbe31
  6. added a commit that references this issue on Sep 17, 2022
    ca54275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions