Skip to content

Producer respects Context passed to Send() and SendAsync() when appying backpressure - #534

Merged
cckellogg merged 1 commit into
apache:masterfrom
dferstay:producer-respects-ctx-under-backpressure
Jun 25, 2021
Merged

cckellogg merged 1 commit into
apache:masterfrom
dferstay:producer-respects-ctx-under-backpressure

Conversation

@dferstay

@dferstay dferstay commented Jun 7, 2021

Copy link
Copy Markdown
Contributor

Previously, the Producer ignored the context passed to Send() and
SendAsync().

Now, the Producer respects the context in the case where the
ProducerOptions.MaxPendingMessages limit is breached. In this case, the
producer will block until a permit for sending the message is available or
until the context expires, whichever comes first.

Failures to send messages due to context expiration are communicated to
callers via the existing TimeoutError error code.

Signed-off-by: Daniel Ferstay [email protected]

Motivation

When the Producer is applying backpressure to the caller it will block attempting to acquire a send permit.

Before this change change, the producer would block indefinitely as a send permit must be acquired before the send timeout can be checked by the internal runEventsLoop go-routine.

With this change, callers can control the duration they are willing to wait for a send permit by using the context passed to the Send() and SendAsync() methods.

Modifications

  • Modify Semaphore.Acquire() to accept a context and block until acquisition is complete or the passed context is expired, whichever comes first
  • Modify partitionProducer.internalSendAsync() to propagate the calling context when attempting to acquire the publish semaphore, and fail the request if the acquire is unsuccessful.

Verifying this change

  • additional unit tests for the Sempahore
  • additional producer_test that verifies publish on context expiration while applying backpressure

@dferstay
dferstay force-pushed the producer-respects-ctx-under-backpressure branch from 3d97416 to 3444609 Compare June 7, 2021 20:07
@merlimat merlimat added this to the 0.6.0 milestone Jun 7, 2021
@dferstay
dferstay force-pushed the producer-respects-ctx-under-backpressure branch 5 times, most recently from b409f8f to 9d50186 Compare June 7, 2021 22:59
@cckellogg

Copy link
Copy Markdown
Contributor

/pulsarbot run-failure-checks

…ing backpressure

Previously, the Producer ignored the context passed to Send() and
SendAsync().

Now, the Producer respects the context in the case where the
ProducerOptions.MaxPendingMessages limit is reached.  In this case, the
producer will block until a permit for sending the message is available or
until the context expires, whichever comes first.

Failures to send messages due to context expiration are communicated to
callers via the existing TimeoutError error code.

Signed-off-by: Daniel Ferstay <[email protected]>
@dferstay
dferstay force-pushed the producer-respects-ctx-under-backpressure branch from 9d50186 to 4b2bfbb Compare June 24, 2021 20:42
@cckellogg
cckellogg merged commit 0f3e504 into apache:master Jun 25, 2021
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 this pull request may close these issues.

3 participants