-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak on transport.newBufWriter #6761
Comments
using pprof give us aec46e609fe0:~# go tool pprof -lines http://localhost:6060/debug/pprof/heap
Fetching profile over HTTP from http://localhost:6060/debug/pprof/heap
Saved profile in /root/pprof/pprof.go-telephony-human-detector.alloc_objects.alloc_space.inuse_objects.inuse_space.001.pb.gz
File: go-telephony-human-detector
Type: inuse_space
Time: Nov 2, 2023 at 9:20pm (UTC)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 1182.59MB, 95.86% of 1233.60MB total
Dropped 98 nodes (cum <= 6.17MB)
Showing top 10 nodes out of 19
flat flat% sum% cum cum%
619.46MB 50.22% 50.22% 619.46MB 50.22% google.golang.org/grpc/internal/transport.newBufWriter /go/pkg/mod/google.golang.org/grpc@v1.59.0/internal/transport/http_util.go:315 (inline)
543.12MB 44.03% 94.24% 543.12MB 44.03% bufio.NewReaderSize /usr/local/go/src/bufio/bufio.go:57 (inline)
13.01MB 1.05% 95.30% 13.01MB 1.05% runtime.malg /usr/local/go/src/runtime/proc.go:4459
7MB 0.57% 95.86% 7MB 0.57% google.golang.org/grpc/internal/transport.NewServerTransport /go/pkg/mod/google.golang.org/grpc@v1.59.0/internal/transport/http2_server.go:246
0 0% 95.86% 8MB 0.65% gitlab.com/vozy/go-telephony-human-detector/internal/server.ServeGrpc /go/src/gitlab.com/vozy/go-telephony-human-detector/internal/server/server.go:54
0 0% 95.86% 8MB 0.65% google.golang.org/grpc.(*Server).Serve /go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:852
0 0% 95.86% 1203.59MB 97.57% google.golang.org/grpc.(*Server).Serve.func3 /go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:894
0 0% 95.86% 1203.59MB 97.57% google.golang.org/grpc.(*Server).handleRawConn /go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:910
0 0% 95.86% 1203.59MB 97.57% google.golang.org/grpc.(*Server).newHTTP2Transport /go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:954
0 0% 95.86% 1178.59MB 95.54% google.golang.org/grpc/internal/transport.NewServerTransport /go/pkg/mod/google.golang.org/grpc@v1.59.0/internal/transport/http2_server.go:168 heap file: |
Just to understand better, you are suspecting that this is a regression with go 1.21, since you're not observing this problem with go 1.20? Those buffers are allocated per connection. It would be useful to show us the associated number of connection for each test you run. If you have a number of open connections in the order of 1000s, the numbers you're showing are expected. |
Yes, ddos of ping request on server use a lot more memory compiled with 1.21 (400Mb) than 1.20 (70Mb)
Yes. However, memory with compiled on 1.21 stucks on the max used, go1.20 decrease as expected after minutes of ddos |
This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
We will try to reproduce this on our side and get back to you |
I suspect that something happens when function finish execution func (s *srv) PingPong(ctx context.Context, req *humandetector.PingPongRequest) (*humandetector.PingPongResponse, error) {
return &humandetector.PingPongResponse{
Message: "PONG!",
}, nil
} I added a 60-second |
Do we have a solution for high memory usage of grpc with transport.newBufWriter |
@krishnachaitanya1996 -- are you also seeing a spike in the memory usage when you moved between go versions? |
Ours is a newly built app on go 1.21.3 and grpc 1.57.0, and we are tuning the application wrt cpu and memory and found that grpc transport.newBufWriter consuming a good amount of memory. so investigating on this area. |
The investigation of this issue is towards the spike in memory usage while using go v1.21 vs go v1.20. @krishnachaitanya1996 -- might be different that what you are describing here |
I also found the same issue in my application~~ |
Hi @arvindbr8, I am working on this issue |
Hello! I encountered this issue and had posted some details in this thread but eventually removed it as I thought it wasn't really tied to this issue. Nonetheless, I solved it and it might help others: If you are using Google Cloud Load Balancers and HTTP2 with your LB Backend, be careful as GFEs (LB Frontends) may keep connections open for as long as 10 minutes (which is the default backend timeout). This means that when dealing with lots of clients that connect & disconnect to GFEs, you might end-up with a ton of "residual" HTTP2 connections & bear the costs associated with them (high number of go routines & memory allocations). I partially solved it by tweaking keep-alive settings to send a GOAWAY after 15 seconds of inactivity. I reckon it might not the best way to solve it though. |
The fact that grpc-go isn't terribly efficient at dealing with lots of connection is something a lot of users have run into, including myself. Sometimes it's possible to reduce the number of connections, sometimes it isn't. For your particular case, I would try This specific issue was opened for a regression in Go 1.21, not about generic per-connection memory usage. |
Hi @pablodz, sorry for the delay in response. We have been a bit thin on the ground for a couple of months. However, it seems like we are not able to repro the exact issue you are facing. I tried to do it on my side and I noticed below memory usages metrics between go versions 1.21 and 1.20. I also tried varying the number of connections made as I feel like that is an important metric to check here
fyi: I have used docker for these findings |
@arvindbr8 it looks like since go1.21.4 the memory leaks was fixed, now I'm using go.1.22, looks that was something related to GC collector after executing a grpc function according to my investigation |
That's great! Happy that it resolved for you. Thanks for bringing this to our notice. Seems like there could be other people impacted by this. |
golang/go#63335 this fixed it? |
What version of gRPC are you using?
compiled with
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o server
What version of Go are you using (
go version
)?What operating system (Linux, Windows, …) and version?
What did you do?
proto file
humandetector.proto
I have a golang grpc server like below
server.go
client.go
What did you expect to see?
low memory usage after 50k requests, stucks on that memory usage
> docker stats (EXPECTED) CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS aec46e609fe0 tender_mirzakhani 0.00% 5.105MiB / 62.72GiB 0.01% 3.21kB / 0B 0B / 0B 6
What did you see instead?
> docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS a203abc32299 intelligent_torvalds 0.00% 777MiB / 62.72GiB 1.21% 132MB / 17.4MB 0B / 325MB 32
After 50k requests of a simple stream ram is nearly 700MB
The text was updated successfully, but these errors were encountered: