Skip to content

Commit df9d0ba

Browse files
hongalexnoahdietz
authored andcommitted
doc(pubsub): clarify behavior of ack deadlines (#6301)
* doc(pubsub): clarify behavior of ack deadlines * add 99th percentile documentation
1 parent e85f025 commit df9d0ba

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

pubsub/doc.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ The callback is invoked concurrently by multiple goroutines, maximizing
7474
throughput. To terminate a call to Receive, cancel its context.
7575
7676
Once client code has processed the message, it must call Message.Ack or
77-
Message.Nack, otherwise the message will eventually be redelivered. Ack/Nack
77+
Message.Nack; otherwise the message will eventually be redelivered. Ack/Nack
7878
MUST be called within the Receive handler function, and not from a goroutine.
7979
Otherwise, flow control (e.g. ReceiveSettings.MaxOutstandingMessages) will
8080
not be respected, and messages can get orphaned when cancelling Receive.
8181
8282
If the client cannot or doesn't want to process the message, it can call Message.Nack
8383
to speed redelivery. For more information and configuration options, see
84-
"Deadlines" below.
84+
"Ack Deadlines" below.
8585
86-
Note: It is possible for Messages to be redelivered, even if Message.Ack has
86+
Note: It is possible for Messages to be redelivered even if Message.Ack has
8787
been called. Client code must be robust to multiple deliveries of messages.
8888
89-
Note: This uses pubsub's streaming pull feature. This feature properties that
89+
Note: This uses pubsub's streaming pull feature. This feature has properties that
9090
may be surprising. Please take a look at https://cloud.google.com/pubsub/docs/pull#streamingpull
9191
for more details on how streaming pull behaves compared to the synchronous
9292
pull method.
@@ -106,40 +106,44 @@ If you want to have more open streams (such as for low CPU core machines), you s
106106
client, err := pubsub.NewClient(ctx, projID, opts...)
107107
108108
109-
Deadlines
109+
Ack Deadlines
110110
111111
The default pubsub deadlines are suitable for most use cases, but may be
112112
overridden. This section describes the tradeoffs that should be considered
113113
when overriding the defaults.
114114
115115
Behind the scenes, each message returned by the Pub/Sub server has an
116-
associated lease, known as an "ACK deadline". Unless a message is
117-
acknowledged within the ACK deadline, or the client requests that
118-
the ACK deadline be extended, the message will become eligible for redelivery.
116+
associated lease, known as an "ack deadline". Unless a message is
117+
acknowledged within the ack deadline, or the client requests that
118+
the ack deadline be extended, the message will become eligible for redelivery.
119119
120120
As a convenience, the pubsub client will automatically extend deadlines until
121121
either:
122-
* Message.Ack or Message.Nack is called, or
123-
* The "MaxExtension" period elapses from the time the message is fetched from the server.
124-
125-
ACK deadlines are extended periodically by the client. The initial ACK
126-
deadline given to messages is 10s. The period between extensions, as well as the
127-
length of the extension, automatically adjust depending on the time it takes to ack
128-
messages, up to 10m. This has the effect that subscribers that process messages
129-
quickly have their message ack deadlines extended for a short amount, whereas
122+
- Message.Ack or Message.Nack is called, or
123+
- The "MaxExtension" duration elapses from the time the message is fetched from
124+
the server. This defaults to 60m.
125+
126+
Ack deadlines are extended periodically by the client. The initial ack
127+
deadline given to messages is based on the subscription's AckDeadline property,
128+
which defaults to 10s. The period between extensions, as well as the
129+
length of the extension, automatically adjusts based on the time it takes the
130+
subscriber application to ack messages (based on the 99th percentile of ack latency).
131+
By default, this extension period is capped at 10m, but this limit can be configured
132+
by the "MaxExtensionPeriod" setting. This has the effect that subscribers that process
133+
messages quickly have their message ack deadlines extended for a short amount, whereas
130134
subscribers that process message slowly have their message ack deadlines extended
131135
for a large amount. The net effect is fewer RPCs sent from the client library.
132136
133137
For example, consider a subscriber that takes 3 minutes to process each message.
134-
Since the library has already recorded several 3 minute "time to ack"s in a
138+
Since the library has already recorded several 3-minute "ack latencies"s in a
135139
percentile distribution, future message extensions are sent with a value of 3
136140
minutes, every 3 minutes. Suppose the application crashes 5 seconds after the
137141
library sends such an extension: the Pub/Sub server would wait the remaining
138142
2m55s before re-sending the messages out to other subscribers.
139143
140-
Please note that the client library does not use the subscription's AckDeadline
141-
by default. To enforce the subscription AckDeadline, set MaxExtension to the
142-
subscription's AckDeadline:
144+
Please note that by default, the client library does not use the subscription's
145+
AckDeadline for the MaxExtension value. To enforce the subscription's AckDeadline,
146+
set MaxExtension to the subscription's AckDeadline:
143147
144148
cfg, err := sub.Config(ctx)
145149
if err != nil {

0 commit comments

Comments
 (0)