Skip to content
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

conn: reuse memory in Receive() #213

Closed
wants to merge 1 commit into from

Conversation

florianl
Copy link
Sponsor Contributor

@florianl florianl commented Jun 11, 2024

Use sync.Pool to reuse memory to receive messages.

// on current master
$ go test -memprofile mem.orig.out .
// on this PR
$ go test  -memprofile mem.new.out .
$  go tool pprof -base=mem.orig.out mem.new.out
File: netlink.test
Type: alloc_space
Time: Jun 12, 2024 at 5:46pm (CEST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for -1285.91MB, 53.01% of 2425.69MB total
Dropped 45 nodes (cum <= 12.13MB)
Showing top 10 nodes out of 24
      flat  flat%   sum%        cum   cum%
-1263.47MB 52.09% 52.09% -1263.40MB 52.08%  github.com/mdlayher/netlink.(*conn).Receive
   15.06MB  0.62% 51.47%    15.06MB  0.62%  github.com/mdlayher/netlink.newConn.func1
     -15MB  0.62% 52.08%      -15MB  0.62%  github.com/mdlayher/socket.rwT[go.shape.int]
  -14.50MB   0.6% 52.68%      -20MB  0.82%  github.com/mdlayher/socket.(*Conn).Recvmsg
  -10.50MB  0.43% 53.12%    -6.50MB  0.27%  golang.org/x/sys/unix.Recvmsg
    2.50MB   0.1% 53.01%   -12.50MB  0.52%  github.com/mdlayher/socket.(*Conn).Sendmsg
      -2MB 0.082% 53.09% -1265.40MB 52.17%  github.com/mdlayher/netlink.(*Conn).receive
       2MB 0.082% 53.01%    -6.50MB  0.27%  github.com/mdlayher/netlink.(*conn).Send
         0     0% 53.01%  -637.94MB 26.30%  github.com/mdlayher/netlink.(*Conn).Execute
         0     0% 53.01%  -634.47MB 26.16%  github.com/mdlayher/netlink.(*Conn).Receive

syncPoolReceive

Use sync.Pool to reuse memory to receive messages

Signed-off-by: Florian Lehner <[email protected]>
@florianl
Copy link
Sponsor Contributor Author

Closing in favor of #215 or #207. The implementation of both alternatives are less complex while achieving the reduction of the memory footprint of netlink applications.

@florianl florianl closed this Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant