GeezerVison is showing github.com — User indicates very high Pub/Sub publish average latency for gcloud-python · Issue #2301 · googleapis/google-cloud-python
User indicates very high Pub/Sub publish average latency for gcloud-python #2301Labels api: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release. DescriptionHey, Gcloud-python team,
I have a user who was left disappointed. From an extract:
"With Google’s gcloud python library, we are seeing avg latencies around 400ms publishing tiny messages. This is unacceptable so we tried the experimental RPC library in both python and go, and see average latencies around 120ms." Do we have any idea where the discrepancy might be coming from? Glad to offer some more detail -- contact me directly @google.com if possible.
Kir Activitydhermes commented on Sep 12, 2016 We have gRPC support as well, depending on what version they are using. The latency would be from the network, not from the library, but the 400ms might not all be latency.
For example, there are blocking calls that may wait longer, though we don't use any explicit sleeps, so that would indicate any blocking is due to network latency (again, not anything to do with the library). dhermes commented on Sep 12, 2016 @kir-google-cloud-pubsub Just sent an email as well. Cheers. tseaver commented on Sep 12, 2016 If the reported latency is at the point of Topic.publish: note that our GAX API helper maintains API compatibility with the JSON-over-HTTP version, returning the message ID directly to the caller It therefore disables the GAX "bundling" feature. We've discussed adding another method (e.g., Topic.publish_async) which would be available only under GAX, and which would not return message IDs, but rather the GAX event object. Users publishing multiple messages simultaneously would gain lower latency (no need to wait for message delivery) in exchange for not being able to track the message IDs at point-of-call (they would need to call even.wait() at some point to get them). kir-titievsky commented on Sep 12, 2016 Pardon the level of my ignorance here -- don't know what GAX bundling does. You mean that this is because the Topic.publish() call is blocking? That still seems odd because the 130ms the user was able to get with gRPC in python indicates that
- they used a blocking implementation because an async call would not take that long to return
- the baseline for full response is still 270ms longer in python. That seems like a lot for things that don't happen over network.
dhermes commented on Sep 13, 2016 I did some benchmarking and it seems like 200ms is the average, when sending a lot of messages, though the number of messages and the duration is only about 65-70% correlated.
It may be more interesting to run this on 50 different machines instead of re-constructing a connection 50 different times, since the OS may be keeping the socket open and making future calls faster. kir-titievsky commented on Sep 13, 2016 Summarizing some off-line discussion with @dhermes. The user shared their python implementation:
topic = pubsub_client.topic(topic_name)
with topic.batch():
for timestamp, value in data:
msg = json.dumps({
'timestamp': timestamp,
'value': value
})
topic.publish(msg)
This code sends every message in a separate request, explaining the large latency. Proper batch implementation would have been:
with topic.batch() as batch:
# redacted code
for t, v in data:
batch.publish(json.dumps({'timestamp': timestamp, 'value': v}))
The actual publish call will be executed after the for t,v in data loop finishes.
This explains the 400ms latency in the python sample but not the 130ms latency for the gRPC implementation. Working on that now. dhermes commented on Sep 13, 2016
explaining the large latency...explains the 400ms latency
It doesn't explain latency, but it explains why the block of code might take 400ms. Though if there were a lot of requests (i.e. a lot of entries in the data iterator), it'd take a lot more than 400ms. tseaver commented on Oct 12, 2016 @kir-titievsky Your update, correcting the batch usage, seems fine to me. If hand-marshalling the data using json.dumps is not a hard requirement, you might consider sending timestamp as an attribute, e.g.:
with topic.batch() as batch:
for timestamp, value in data:
batch.publish(value, timestamp=timestamp)
which ought to shave off more cycles. lukesneeringer commented on Aug 8, 2017 Hello! :-)
First, a mea culpa; I have not done as good of a job at keeping up with issues as I should have. If you are getting this (I admit it) cut and paste, it is likely because your issue sat for too long.
In this case, I have been in the process of making a radical update to the PubSub library (#3637) to add significant performance improvements and a new surface, which we hope to launch soon. As such, I am clearing out issues on the old library. It is my sincere goal to do a better job of being on top of issues in the future.
As the preceding paragraph implies, I am closing this issue. If the revamped library does not solve your issue, however, please feel free to reopen.
Thanks!
MetadataMetadataapi: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release. DevelopmentNo branches or pull requestsIssue actions
|