mem: Allocate at 4KiB boundaries in the fallback buffer pool. (#8705)

By rounding up to the nearest page, we avoid repeatedly allocating
similar sizes if requests happen to arrive in roughly increasing order.

The GCS client sends messages with 2MiB of data repeatedly when writing
a large object. Therefore it has to repeatedly allocate just over 2MiB.
This ultimately results in many, many allocations in the fallback buffer
pool. In practice rounding up yields at least a 10x reduction in RAM
when running 100 concurrent large writes. This is probably not unique to
GCS: anyone who sends large messages may be affected.

This change in simpleBufferPool seems worthwhile vs. adding a tier. We
use simpleBufferPool for any size greater than 1MiB, so this effectively
lets us discover a reasonably tight tier around any large message size
that comes in frequently. It increases infrequent allocation sizes by no
more than 0.4%.

RELEASE NOTES:
* mem: round up to nearest 4KiB for pool allocations larger than 1MiB
1 file changed
tree: 1d383827003b3fbee6a3c51194ed1552944586ac
  1. .github/
  2. admin/
  3. attributes/
  4. authz/
  5. backoff/
  6. balancer/
  7. benchmark/
  8. binarylog/
  9. channelz/
  10. cmd/
  11. codes/
  12. connectivity/
  13. credentials/
  14. Documentation/
  15. encoding/
  16. examples/
  17. experimental/
  18. gcp/
  19. grpclog/
  20. health/
  21. internal/
  22. interop/
  23. keepalive/
  24. mem/
  25. metadata/
  26. orca/
  27. peer/
  28. profiling/
  29. reflection/
  30. resolver/
  31. scripts/
  32. security/
  33. serviceconfig/
  34. stats/
  35. status/
  36. tap/
  37. test/
  38. testdata/
  39. xds/
  40. AUTHORS
  41. backoff.go
  42. balancer_wrapper.go
  43. balancer_wrapper_test.go
  44. call.go
  45. clientconn.go
  46. clientconn_authority_test.go
  47. clientconn_parsed_target_test.go
  48. clientconn_test.go
  49. CODE-OF-CONDUCT.md
  50. codec.go
  51. codec_test.go
  52. CONTRIBUTING.md
  53. default_dial_option_server_option_test.go
  54. dial_test.go
  55. dialoptions.go
  56. doc.go
  57. go.mod
  58. go.sum
  59. GOVERNANCE.md
  60. grpc_test.go
  61. interceptor.go
  62. LICENSE
  63. MAINTAINERS.md
  64. Makefile
  65. NOTICE.txt
  66. picker_wrapper.go
  67. picker_wrapper_test.go
  68. preloader.go
  69. producer_ext_test.go
  70. README.md
  71. resolver_balancer_ext_test.go
  72. resolver_test.go
  73. resolver_wrapper.go
  74. rpc_util.go
  75. rpc_util_test.go
  76. SECURITY.md
  77. server.go
  78. server_ext_test.go
  79. server_test.go
  80. service_config.go
  81. service_config_test.go
  82. stream.go
  83. stream_interfaces.go
  84. stream_test.go
  85. trace.go
  86. trace_notrace.go
  87. trace_test.go
  88. trace_withtrace.go
  89. version.go
README.md

gRPC-Go

GoDoc GoReportCard codecov

The Go implementation of gRPC: A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the Go gRPC docs, or jump directly into the quick start.

Prerequisites

Installation

Simply add the following import to your code, and then go [build|run|test] will automatically fetch the necessary dependencies:

import "google.golang.org/grpc"

Note: If you are trying to access grpc-go from China, see the FAQ below.

Learn more

FAQ

I/O Timeout Errors

The golang.org domain may be blocked from some countries. go get usually produces an error like the following when this happens:

$ go get -u google.golang.org/grpc
package google.golang.org/grpc: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

To build Go code, there are several options:

  • Set up a VPN and access google.golang.org through that.

  • With Go module support: it is possible to use the replace feature of go mod to create aliases for golang.org packages. In your project's directory:

    go mod edit -replace=google.golang.org/grpc=github.com/grpc/grpc-go@latest
    go mod tidy
    go mod vendor
    go build -mod=vendor
    

    Again, this will need to be done for all transitive dependencies hosted on golang.org as well. For details, refer to golang/go issue #28652.

Compiling error, undefined: grpc.SupportPackageIsVersion

Please update to the latest version of gRPC-Go using go get google.golang.org/grpc.

How to turn on logging

The default logger is controlled by environment variables. Turn everything on like this:

$ export GRPC_GO_LOG_VERBOSITY_LEVEL=99
$ export GRPC_GO_LOG_SEVERITY_LEVEL=info

The RPC failed with error "code = Unavailable desc = transport is closing"

This error means the connection the RPC is using was closed, and there are many possible reasons, including:

  1. mis-configured transport credentials, connection failed on handshaking
  2. bytes disrupted, possibly by a proxy in between
  3. server shutdown
  4. Keepalive parameters caused connection shutdown, for example if you have configured your server to terminate connections regularly to trigger DNS lookups. If this is the case, you may want to increase your MaxConnectionAgeGrace, to allow longer RPC calls to finish.

It can be tricky to debug this because the error happens on the client side but the root cause of the connection being closed is on the server side. Turn on logging on both client and server, and see if there are any transport errors.