Skip to content

Conversation

@scottf
Copy link
Contributor

@scottf scottf commented Sep 24, 2025

! MAY OVERRIDE THE UNDERLYING JAVA SOCKET IMPLEMENTATION - USE AT YOUR OWN RISK

Socket Buffer Sizes

The default socket buffer sizes in Java depend on the underlying operating system, not Java itself. Java doesn't set explicit defaults - it uses the OS defaults.

Typical Default Values:

Linux:

  • Receive Buffer (SO_RCVBUF): ~87,380 bytes (85 KB)
  • Send Buffer (SO_SNDBUF): ~16,384 bytes (16 KB)

Windows:

  • Receive Buffer: ~8,192 bytes (8 KB)
  • Send Buffer: ~8,192 bytes (8 KB)

macOS:

  • Receive Buffer: ~131,072 bytes (128 KB)
  • Send Buffer: ~131,072 bytes (128 KB)

How to Check Current Values:

import java.net.*;

public class SocketBufferSize {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket();
        System.out.println("TCP Socket Defaults:");
        System.out.println("  Receive Buffer: " + 
            socket.getReceiveBufferSize() + " bytes");
        System.out.println("  Send Buffer: " + 
            socket.getSendBufferSize() + " bytes");
        socket.close();
    }
}

Miscellaneous Configuration:

Linux:

Check /proc/sys/net/core/rmem_default and /proc/sys/net/core/wmem_default
Can be modified via sysctl settings

…VBUF

! MAY OVERRIDE THE UNDERLYING JAVA SOCKET IMPLEMENTATION - USE AT YOUR OWN RISK
Copy link
Member

@MauriceVanVeen MauriceVanVeen left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@jnmoyne jnmoyne left a comment

Choose a reason for hiding this comment

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

LGTM

@scottf scottf merged commit 04541cc into main Sep 25, 2025
5 checks passed
@scottf scottf deleted the socket-danger branch September 25, 2025 13:31
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.

4 participants