GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pubsub: Provide callback capabilities to publishAsync · Issue #1223 · googleapis/google-cloud-java

Pubsub: Provide callback capabilities to publishAsync #1223

New issue
Copy link
New issue
Copy link
Closed
Closed
Pubsub: Provide callback capabilities to publishAsync#1223
Copy link
Assignees
garrettjonesgoogle
Labels
api: pubsubIssues related to the Pub/Sub API.performance

Description

@viniciusccarvalho
viniciusccarvalho
opened on Sep 2, 2016
Issue body actions

It would be nice if publishAsync could offer something like Guava's ListenableFuture, so we could add non blocking callbacks to the results of the operation.

Activity

Next
  1. mziccard
    added
    api: pubsubIssues related to the Pub/Sub API.
    on Sep 2, 2016
  2. mziccard commented on Sep 2, 2016

    @mziccard
    mziccard
    on Sep 2, 2016
    Contributor
    More actions

    Hi @viniciusccarvalho, thanks for your interest!

    We decided not to expose Guava's ListenableFuture in our API. Mainly due to the fact that as soon as we switch to Java8 we would have to get rid of them in favor of CompletableFuture.

    However, the futures we return are actually a ListenableFuture. So, if you are using Guava and are really in need for non blocking callbacks on publishAsync you can use JdkFutureAdapters.listenInPoolThread without paying the price for any additional thread. Please keep in mind that this might be subject to change, in particular when we switch to Java8, but as soon as we do that you will have a native method to register callbacks.

    Out of curiosity, what is your use case for registering callbacks on publishAsync?

  3. viniciusccarvalho commented on Sep 2, 2016

    @viniciusccarvalho
    viniciusccarvalho
    on Sep 2, 2016
    Author
    More actions

    Got it, I was hoping for CompletableFuture but I thought it was asking too much :)

    Mainly to be able to return immediately and attach a listener in case of errors for example. One thing we are struggling is with the overall throughput of pubsub. We thought on using the spotify client, but since gRPC is becoming active we gave it a try.

    Initial tests are showing gRPC a bit slower than the traditional REST client, which is a bit weird, we may not be setting the right knobs. But as a general rule, sending single messages it usually takes ~50ms per 128byte message with REST but its taking ~70ms with gRPC. Those numbers drop by half usually when running from GCE, but it's still a lot compared to other systems such as kafka or even rabbitMQ.

    Batching makes wonders, we are able to easily reach peaks of 18k messages/sec per thread when batching them, but it adds some overhead on our end to process the batch and we loose any acks received if clients want to get a guarantee. It's a tradeoff we understand, but we are trying to find better ways to scale out the throughput of a single client.

    Regards

  4. mziccard commented on Sep 5, 2016

    @mziccard
    mziccard
    on Sep 5, 2016
    Contributor
    More actions

    Initial tests are showing gRPC a bit slower than the traditional REST client, which is a bit weird, we may not be setting the right knobs.

    This is strange. Which REST client are you using? I assume that to test gRPC you are using this library, is this the case?

  5. viniciusccarvalho commented on Sep 6, 2016

    @viniciusccarvalho
    viniciusccarvalho
    on Sep 6, 2016
    Author
    More actions

    I thought so as well. I'm using google's own REST API.

    <dependency>
                <groupId>com.google.apis</groupId>
                <artifactId>google-api-services-pubsub</artifactId>
                <version>v1-rev11-1.22.0</version>
            </dependency>

    To be more precise. I can come up with two sample projects to demo this. I pretty much created two simple apps that have an endpoint where one express : how many messages, payload size and batch (if any) size. One using REST and other gRPC. And I then just yield the time it took to get the ack back. To my surprise the gRPC version of this library (0.3.0) is having a much higher response time.

  6. viniciusccarvalho commented on Sep 6, 2016

    @viniciusccarvalho
    viniciusccarvalho
    on Sep 6, 2016
    Author
    More actions

    Hi Marco, I created this project : https://github.com/viniciusccarvalho/spring-pubsub
    that has two implementations (REST & gRCP) and you could simply test it. Let me know if you see something really horrific .

    Regards

  7. garrettjonesgoogle commented on Nov 22, 2016

    @garrettjonesgoogle
    garrettjonesgoogle
    on Nov 22, 2016
    Contributor
    More actions

    The latency problem was also observed in #1338 .

  8. garrettjonesgoogle commented on Nov 23, 2016

    @garrettjonesgoogle
    garrettjonesgoogle
    on Nov 23, 2016
    Contributor
    More actions

    After some internal discussion, I propose that we go ahead with switching from Future to ListenableFuture throughout google-cloud-java. Motivation:

    1. gRPC has already set a precedent for exposing ListenableFuture.
    2. This doesn't mean we will open the floodgates for Guava types; we will set a policy of considering them on a case-by-case basis.
    3. We aren't moving to Java 8 in the short term due to concerns around Android and various companies potentially still needing to vet it. Even when we do move to Java 8, we don't necessarily have to switch to CompletableFuture - we have the option of continuing to use ListenableFuture for a while after that.
    4. The performance impacts of not exposing ListenableFuture are big enough that certain use cases would completely avoid using the library because of it (Pub/Sub).

    Tagging some people for visibility and discussion if there is disagreement: @anthmgoogle @aozarov @kluever @cpovirk @lesv @davidtorres

    Reacted by Les Vogel and Chris Povirk
  9. garrettjonesgoogle
    added
    performance
    on Nov 23, 2016
  10. cpovirk commented on Nov 29, 2016

    @cpovirk
    cpovirk
    on Nov 29, 2016
    More actions

    That sounds good to me on the Guava side.

    A couple further notes:

    • If you are interested in CompletableFuture for its more convenient chaining API, you may be interested in our proposed FluentFuture, which would extend ListenableFuture and provide instance methods like transform. However, this won't be in Guava for another release or two (best case, by the end of the year; worst case, months more). Additionally, we're not 100% sure that we'll be adding it at all. If adding it would be important to you, please let us know. (Even if you return ListenableFuture today, you could change your APIs to return FluentFuture later, though doing so in a compatible way is a little subtle. Even if you don't, we'll probably be changing our common ListenableFuture implementations to extend FluentFuture, so users can cast or cheaply convert the returned values to FluentFuture instances.)

    • The maintainers of java.util.concurrent have spoken of CompletableFuture as "a common underlying implementation... for others creating or reworking higher-level APIs" rather than as a type that most end users will interact directly with. Now, I get the impression that they're OK with people who use CompletableFuture directly, and of course people do. But I at least think they would say "You don't need to migrate to CompletableFuture if you're happy with something else." Hopefully we can make you happy with ListenableFuture :)

  11. davidtorres commented on Nov 29, 2016

    @davidtorres
    davidtorres
    on Nov 29, 2016
    More actions

    Just for the record, this sound good to me from the Pub/Sub side.

  12. garrettjonesgoogle commented on Jan 26, 2017

    @garrettjonesgoogle
    garrettjonesgoogle
    on Jan 26, 2017
    Contributor
    More actions

    So things have changed since my last comment on this thread. It turns out that Guava is a pretty problematic dependency for certain consumers. So for now, we are going to introduce our own type that wraps ListenableFuture, called RpcFuture. @pongad is implementing this in the high-performance rewrite of Pub/Sub.

  13. garrettjonesgoogle
    assigned
    pongad
    on Jan 26, 2017
  14. garrettjonesgoogle
    added
    blocking beta
    on Jan 26, 2017
  15. viniciusccarvalho commented on Jan 26, 2017

    @viniciusccarvalho
    viniciusccarvalho
    on Jan 26, 2017
    Author
    More actions

    Thanks for looking into that @garrettjonesgoogle. We found ourselves having this issue when integrating with Spring Boot starters on start.spring.io, boot brings it's own version of guava that would require users to manually update the pom of our google-pubsub binder.

  16. 2 remaining items

  17. garrettjonesgoogle commented on Feb 23, 2017

    @garrettjonesgoogle
    garrettjonesgoogle
    on Feb 23, 2017
    Contributor
    More actions

    We have done a rewrite of Pub/Sub, and the publish() call now has callback capabilities. The type is not ListenableFuture though, it is an RpcFuture type from gax-java that wraps ListenableFuture.

    https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/Publisher.java#L205

  18. garrettjonesgoogle
    closed this as completedon Feb 23, 2017
  19. theacodes
    unassigned
    pongad
    on Sep 28, 2018
  20. JustinBeckwith
    assigned
    garrettjonesgoogle
    on Feb 1, 2021
  21. github-actions
    added a commit that references this issue on Aug 25, 2022

    chore(deps): update dependency com.google.cloud:google-cloud-automl t…

    e12a0e4
  22. meltsufin
    added a commit that references this issue on Dec 22, 2025

    chore(deps): update dependency com.google.cloud:google-cloud-logging …

    f4c346e
  23. chingor13
    added a commit that references this issue on Jan 6, 2026

    chore(deps): update dependency com.google.cloud:google-cloud-logging-…

    b646cb2
  24. chingor13
    added a commit that references this issue on Jan 22, 2026

    chore: bump urllib3 from 2.0.6 to 2.0.7 in /docker/owlbot/java/src (#…

    4fc9693
  25. suztomo
    added a commit that references this issue on Mar 11, 2026

    chore(deps): update dependency com.google.cloud:google-cloud-logging …

    61243c8
  26. suztomo
    added a commit that references this issue on Mar 23, 2026

    chore(deps): update ghcr.io/graalvm/graalvm-ce docker tag to v22.3.2 (g…

    43698ca
  27. suztomo
    added a commit that references this issue on Mar 30, 2026

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    4467381
  28. lqiu96
    added a commit that references this issue on Apr 1, 2026

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    226b82f
  29. meltsufin
    added 2 commits that reference this issue on Apr 29, 2026

    chore(main): release 1.120.8 (#1223)

    0ad83c3

    chore(main): release 1.120.8 (#1223)

    c7a2a55
  30. benjaminp
    added a commit that references this issue on Jul 13, 2026

    chore(main): release 2.6.2 (googleapis#1223)

    0a13593
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @garrettjonesgoogle
    garrettjonesgoogle

Labels

api: pubsubIssues related to the Pub/Sub API.performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.