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

reduce buffer size of "unused" side of socket #4313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gregcusack
Copy link

Follow Up to PR: #3929

Problem

We allocate large send and receive buffers for all sockets. However, not all sockets read and write equally from/to their buffers. In fact, 6 sockets are primarily Read and 2 are primarily Write. Meaning we are allocating memory that is never used.

Summary of Changes

  1. TPU write side of sockets are only QUIC control traffic. Set buffer size to 4 MB
  2. Broadcast and Repair read side of sockets are only QUIC control traffic. Set buffer size to $ MB

Services/Sockets
Read/Write

Gossip
RPC - TCP
Ip_echo - TCP
Tvu
tvu_quic
Repair
Repair_quic
Serve_repair
Serve_repair_quic
Ancestor_hashes_requests_quic
Ancestor_hashes_requests
Primarily Read

Tpu
Tpu_forwards
Tpu_vote
Tpu_quic
Tpu_forwards_quic
Tpu_vote_quic
Primarily Write

Retransmitter
Broadcast

Follow Up PR:

  1. Make better sizing decisions for the sockets that don't need a full 128MB buffer

@@ -2772,8 +2790,19 @@ impl Node {
let (gossip_port, (gossip, ip_echo)) =
Self::get_gossip_port(gossip_addr, port_range, bind_ip_addr);

// TPU sockets are primarily read only
// Broadcast and Retransmit sockets are primarily write only
// Set a 4 MB buffer size for the minimally used side of the socket for QUIC control traffic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you haven't marked this PR for review yet, but seeing the repeated comments about the kernel doubling the buffer size, I'm wondering if we should make our function account for the doubling. Ie, a user passes X and we do X / 2 internally so that they actually get X

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i was thinking about that but i wanted to keep the same behavior as setsockopt syscall. thought it would be confusing to have a different behavior. then again, idk how many people are aware of what setsockopt is and how its implemented.

Copy link

@steviez steviez Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought it would be confusing to have a different behavior

Yeah, that's a fair counter. Essentially, a question of should our API make things easier OR remain consistent with the underlying API.

then again, idk how many people are aware of what setsockopt is and how its implemented.

Ha yeah, this is the other angle of it. I had to crack man open, but looking at the notes:

$ man 7 socket | grep NOTES -A 2
NOTES
       Linux assumes that half of the send/receive buffer is used for internal kernel structures;
       thus the values in the corresponding /proc files are twice what can be observed on the wire.

Based on that, the extra half that Linux takes should not be considered available for user payloads.

All that being said, maybe it's better not do any division on our side and just pass the value through as you have it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i missed that. ok so if we set 4 MB, the kernel doubles to 8 MB, but only 4 MB are usable on the wire. So ya, let's not divide but let's set to 4 MB knowing kernel will increase it but only the original/desired 4 MB is usable

@gregcusack gregcusack force-pushed the reduce-net-buffer-sizes branch from d9ae43e to 85a196a Compare January 7, 2025 21:05
@gregcusack gregcusack force-pushed the reduce-net-buffer-sizes branch from 85a196a to e62193f Compare January 7, 2025 21:09
@gregcusack gregcusack marked this pull request as ready for review January 7, 2025 22:37
@gregcusack gregcusack requested a review from steviez January 8, 2025 00:16
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.

2 participants