Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: changing tcp parameters when establishing connection

by iThunder (Beadle)
on Dec 03, 2015 at 15:25 UTC ( [id://1149315]=note: print w/replies, xml ) Need Help??


in reply to Re: changing tcp parameters when establishing connection
in thread changing tcp parameters when establishing connection

i used code on fedora, centos and windows but it doesn't seem to change the window size #!/usr/bin/perl use warnings; use IO::Socket::INET; use Socket qw(SOL_SOCKET SO_RCVBUF IPPROTO_IP IP_TTL); my $socket = IO::Socket::INET->new(LocalPort => "2525", Proto => 'tcp', PeerHost => "192.168.147.1", PeerPort => "23"); $socket->setsockopt(SOL_SOCKET, SO_RCVBUF, 512000);
  • Comment on Re^2: changing tcp parameters when establishing connection

Replies are listed 'Best First'.
Re^3: changing tcp parameters when establishing connection
by Anonymous Monk on Dec 04, 2015 at 13:14 UTC

    You haven't told us the purpose behind the tweak. Do you intend to increase, decrease or clamp the window size? Why?

    On linux, setting socket buffers is subject to global net.core.rmem_max and wmem_max sysctl's.

    If you do not specify (and therefore lock) the per-socket values via SO_RCVBUF, then linux tcp implementation will dynamically adjust the buffer size within the limits of net.ipv4.tcp_rmem and tcp_wmem. On my system, the tcp_rmem[2] is substantially higher than rmem_max...

    The tcp window and buffer allocation should follow the actual need, depending on misc. factors such as memory pressure, link characteristics, remote behavior and so on. Linux kernel is open source. Go on and take a look at net/core/sock.c, net/ipv4/tcp{,_input,_output}.c, etc.

    Again, is this to maximize single connection throughput? You could have other issues that prevent full link utilization. Linux supports multiple congestion control algorithms, so that's another thing to play with.

Re^3: changing tcp parameters when establishing connection
by Apero (Scribe) on Dec 03, 2015 at 16:59 UTC

    This depends very much on your OS defaults and any distro-level or admin-level tuning. The actual definition of buffer window and receive size are frequently set to the maximum possible size by implementations, but you can adjust this in the application level. I merely said this has an impact on the TCP-window size, per the manpage reference I gave earlier.

    Remember, the stock Linux or BSD kernel defaults can be adjusted by kernel maintainers (changing official upstream options,) by an admin who uses knobs like sysctl tuning to adjust defaults, or by applications that have some say over userland tooling (such as the socket-level options we're discussing here.) I can't tell you exactly what impact your change to the SO_RECVBUF size will have since I do not know the defaults on your current system. Use the above resources to find out, or learn more about them. Remember, sometimes you get a bit "dirty" learning how all the layers in an modern system interact. Test and see what the impact is for you.

    Finally, note that the definitive reference for Window Scaling is RFC-1323. Specifically, section 2.1 talks about the need for buffer sizes large enough to make window-scaling effective. This is probably why the API documentation for tcp on various platforms frequently mentions this fact. It's quite possible your kernel/sysctl/userland is already using the "largest possible" buffers, in which case the behavior your noted may be quite correct. This may not be the case on someone else's OS, distro, or configuration.

    FYI, your code is a bit hard to read; use <code> tags to increase readability by printing the code as you wrote it (markup docs are helpful too.)

      but you can adjust this in the application level.

      Sorry, but that is wrong. The tcp window size & scaling parameters are tcp-stack-wide parameters.

      If one application causes them to change dynamically -- only possible if it has admin privileges; if then -- then that change would affect all applications -- system and user -- using tcpip.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Update2: I'm not sure why this is getting downvotes, but my technical information is very much correct. I have included a script that can impact the TCP Window size scaling factor at the end of this comment. Not sure why correct technical information is being downvoted, but at the possibility of getting more negative votes, I'm including full demonstration code that shows this is accurate at the end of this post. /Update2

        Sorry, but that is clearly not what the RFC I linked to said. Quoting here:

        The maximum receive window, and therefore the scale factor, is determined by the maximum receive buffer space. In a typical modern implementation, this maximum buffer space is set by default but can be overridden by a user program before a TCP connection is opened. This determines the scale factor, and therefore no user interface is needed for window scaling.

        Update: So, breaking this down, the above quote says "the scaling factor is determined by the buffer space, which the application has access do. Thus we do not need to give the userland API additional control over further tuning on top of kernel support." /Update

        Notice the one important piece here: userland applications can take advantage of window-scaling (again, provided the administrator and kernel are configured for such support, which I have mentioned several times now,) without needing any additional API.

        Perhaps I am mis-understanding the point of contention for you, but you seem to be suggesting that there is no API that can control this. The RFC, and system-documentation, says otherwise. Obviously if the feature is disabled in the kernel or by the admin, one cannot have it. However, reading the RFC, it's possible for an application to avoid window-scaling by setting the buffers small enough that the kernel will not enable that feature.

        I never said an application got to set kernel-wide params. I point out last comment and again here that they have an impact on it. It is very possible to change the buffers (which are socket-level options) which do have an impact on the window-scaling. Again, reference the quote above and the tcp manpage, referenced earlier in the thread.

        Part of Update2: Code follows that shows you can impact the window-scaling factor from userland follows. If nothing else, this should help others understand how socket code works and what control userland has over the process.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1149315]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-26 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found