Skip to content

FR: Port sharing with traditional HTTP services #3458

Closed

Description

@Capstan

As of v1.6.1, there appears to be no way, when using gRPC with Netty, to host traditional HTTP services side-by-side with gRPC on the same port. I am working with an existing framework that wants to support gRPC but only has one port available and expects to also serve HTTP.

At the moment, the workaround would involve rearchitecting several disparate systems to know about split fleets of services or multiple ports, followed by some careful rollouts to migrate traffic. I'd like to avoid this if at all possible.

Activity

  1. ejona86 commented on Sep 14, 2017

    @ejona86
    Member

    There is no port sharing solution currently available. The only workaround is to expose an in-process reverse proxy that forwards content to the appropriate server. But that can have performance implications.

    The long-term solution has been netty/netty#3667 . It's only just recently reached feature-parity to the point we could potentially migrate to it.

  2. added this to the Unscheduled milestone on Sep 14, 2017
  3. pmasrani commented on Apr 16, 2018

    @pmasrani

    @ejona86: Is the work on this bug in progress or do we have a timeline on this fix?

  4. ejona86 commented on Apr 17, 2018

    @ejona86
    Member

    The Netty stuff has been progressing. There was a PoC to use the new Netty API, but we've not swapped to it and it will have bitrot to a degree.

  5. prog110 commented on Jun 3, 2018

    @prog110

    @ejona86 Any luck with PoC?

  6. trustin commented on Aug 1, 2018

    @trustin
    Contributor

    Shameless plug: You can mix and match gRPC, Thrift, REST, Tomcat, Jetty and whatnot with Armeria. HTTP/1.1 fully supported. https://line.github.io/armeria/

  7. fkorotkov commented on May 28, 2019

    @fkorotkov

    I think most of the cases will be covered if Java GRPC will be able to serve regular http 200 OK requests on / or /health if GRPC service implements grpc.health.v1.Health. Unfortunately, a lot of load balancers including the GCP one require such endpoints for health checking and they can't use another port. 😪

  8. ttj4 commented on Dec 10, 2019

    @ttj4

    @ejona86 any luck with poc?

  9. ejona86 commented on Dec 10, 2019

    @ejona86
    Member

    @ttj4, one part of the netty piece is #2332. I made progress on it last year, but it still needed more work to fix the bitrot.

  10. fkorotkov commented on Jul 29, 2020

    @fkorotkov

    Just a note for future researchers. I tried Armeria from @trustin's comment before and it didn't work quite well. I've tried it once again and nowadays it worked pretty well. Posting a few caveats that I've found while migrating to Armeria under a GKE Ingress (GCP HTTP Balancer):

    1. Had to set maxRequestLength(0) so streaming of large binary files in 2Mb chunks works
    2. Had to set requestTimeoutMillis(0) for long streams to not be canceled

    Other than that all works great so far, can see better CPU utilization seems because of our use of Kotlin Coroutines and their own executors. grpc-java has a separate thread pool that we actually didn't use much because of Kotlin Coroutines and Armeria doesn't create it by default.

    My full Kotlin code snippet
    val serviceImpl = ...
    val healthService = ...  // impl of HealthGrpc.HealthImplBase
    val grpcService = GrpcService.builder()
          .addService(
            ServerInterceptors.intercept(
              serviceImpl,
              ExceptionLoggingInterceptor(),
              MonitoringServerInterceptor(rootStats.scoped("grpc"))
            )
          )
          .addService(healthService)
          // See https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md
          .addService(ProtoReflectionService.newInstance())
          .supportedSerializationFormats(GrpcSerializationFormats.values())
          .enableUnframedRequests(true)
          .build()
    
    val grpcServer = Server.builder()
          .http(port)
          .https(port)
          // self signed certificate to make GCP HTTP/2 Load Balancer happy
          // see https://cloud.google.com/load-balancing/docs/ssl-certificates#backend-encryption
          // Generated via https://devcenter.heroku.com/articles/ssl-certificate-self
          .tls(File(certificatesFolder, "server.crt"), File(certificatesFolder, "server.key"));
          .maxRequestLength(0) // unlimited
          .requestTimeoutMillis(0) // unlimited
          .service(grpcService)
          .decorator(LoggingService.newDecorator())
          .serviceUnder("/") { _, _ -> HttpResponse.of(HttpStatus.OK, MediaType.ANY_TEXT_TYPE, "Please use gRPC ;-)") }
          .service(Route.builder().exact("/healthz").build()) { _, _ ->
            val errorMessage = healthService.refreshStatus()?.second?.message
            if (errorMessage != null) {
              HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR, MediaType.ANY_TEXT_TYPE, errorMessage)
            } else {
              HttpResponse.of(HttpStatus.OK)
            }
          }
          .build()
    grpcServer.start().join()
  11. ulfjack commented on Dec 23, 2020

    @ulfjack
    Contributor

    We think that it's unacceptable for our users to have to remember different ports for our gRPC and HTTP APIs (and we also don't want to use a different library), and we have created a couple of patches that allow us to respond to HTTP requests on the same port used by gRPC. Currently, our patches only work with netty. The question is, would you be willing to merge some or all of them?

  12. ejona86 commented on Dec 23, 2020

    @ejona86
    Member

    @ulfjack, we can look at the patches, but it is highly likely they require a large or brittle API which makes them unsuitable for merging. I suggest either giving us an overview or you send us a draft PR (so it doesn't need to be clean) which would allow a low-cost pre-review.

  13. piotr-sumo commented on Jan 18, 2021

    @piotr-sumo

    @ejona86 could you elaborate more on the in-process reverse proxy? We'd like to experiment with that and run some tests in order to check wether or not we can pay the performance price.

  14. ulfjack commented on Mar 14, 2021

    @ulfjack
    Contributor
  15. mdzhigarov commented on May 10, 2023

    @mdzhigarov

    Any update on this? Is port sharing still no supported?

  16. darren-fu commented on Feb 8, 2024

    @darren-fu

    I have a draft here: https://github.com/EngFlow/grpc-java

    Any feedback is welcome.

    what about this patch code, is it a nice way ?

  17. panchenko commented on Feb 14, 2024

    @panchenko
    Contributor

    It can work in Tomcat via the grpc-servlet(-jakarta) module.

  18. ejona86 commented on Feb 15, 2024

    @ejona86
    Member

    I'm going to close this as fixed by grpc-servlet and grpc-servlet-jakarta. I wouldn't be surprised if someone wants Netty port sharing specifically. I'd suggest opening a separate issue to track that.

    Fixed by #8596

  19. modified the milestones: Unscheduled, 1.53 on Feb 15, 2024
  20. locked as resolved and limited conversation to collaborators on May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions