Skip to content

Conversation

felixschlegel
Copy link
Contributor

@felixschlegel felixschlegel commented Jul 20, 2023

Motivation:

With our own flushing implementation we were flushing until rd_kakfa_outq_len
reached 0. However rd_kakfa_outq_len also takes other events such
as statistics into account which led to a race where we were flushing
for a very long time because more and more other events were produced to
the queue while we were flushing.

Modifications:

  • KafkaClient:
    • remove var outgoingQueueSize
    • add new method flush(timeoutMilliseconds:) that executes the
      blocking rd_kafka_flush call on a DispatchQueue but vends this
      as an async func
  • KafkaProducer:
    • rename KafkaProducer.StateMachine.State.flushing to
      KafkaProducer.StateMachine.State.finishing
    • invoke KafkaClient.flush before terminating poll loop

@felixschlegel
Copy link
Contributor Author

@FranzBusch : how shall we go about vending the flush timeout to the user?

@FranzBusch
Copy link
Contributor

how shall we go about vending the flush timeout to the user?

We should put it into our configuration struct.

@felixschlegel felixschlegel force-pushed the fs-kafka-producer-refactor-flush branch 2 times, most recently from c90ba5a to b20104e Compare July 20, 2023 13:15
/// Flush any outstanding produce requests.
///
/// Parameters:
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///

/// Default: `10000`
public var flushTimeoutMilliseconds: Int = 10000 {
didSet {
precondition(0...Int(Int32.max) ~= self.flushTimeoutMilliseconds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we provide a message here as well when we fail the precondition please

Motivation:

With our own flushing implementation we were flushing until `rd_kakfa_outq_len`
reached ``0`. However `rd_kakfa_outq_len` also takes other events such
as statistics into account which led to a race where we were flushing
for a very long time because more and more other events were produced to
the queue while we were flushing.

Modifications:

* `KafkaClient`:
    * remove `var outgoingQueueSize`
    * add new method `flush(timeoutMilliseconds:)` that executes the
      blocking `rd_kafka_flush` call on a `DispatchQueue` but vends this
      as an `async func`
* `KafkaProducer`:
    * rename `KafkaProducer.StateMachine.State.flushing` to
      `KafkaProducer.StateMachine.State.finishing`
    * invoke `KafkaClient.flush` before terminating poll loop
Modifications:

* add messages to `preconditions`
* remove extra line in `RDKafkaClient.flush`'s parameter documentation
@felixschlegel felixschlegel force-pushed the fs-kafka-producer-refactor-flush branch from 6d43007 to 6aa35f5 Compare July 21, 2023 08:53
@felixschlegel felixschlegel requested a review from FranzBusch July 21, 2023 16:37
@FranzBusch FranzBusch merged commit 5b07fe2 into swift-server:main Jul 21, 2023
@FranzBusch FranzBusch deleted the fs-kafka-producer-refactor-flush branch July 21, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants