Re^2: changing tcp parameters when establishing connection
by iThunder (Beadle) on Dec 03, 2015 at 15:25 UTC
|
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);
| [reply] |
|
|
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.
| [reply] [d/l] [select] |
|
|
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.)
| [reply] [d/l] [select] |
|
|
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.
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
|
|
|
|
Re^2: changing tcp parameters when establishing connection
by BrowserUk (Patriarch) on Dec 02, 2015 at 20:20 UTC
|
| [reply] |
|
|
Update:
It turns out I was slightly mistaken below when I implied there's no way to tune window-scaling per-socket; ref tcp(7) (at least on my Linux and the link here) that indicates with kernel-level window-scaling enabled, tuning of the socket buffers do in fact impact the window scaling. As always, refer to your specific distro's system pages for particulars. /Update
No, at least not that I've seen; this said, maybe some exotic distro does support these specific features on a per-socket basis rather than per-host. I was focusing on the "etc" part of OP's inquiry, suggesting an interest in tuning any socket-level options.
The answer to such questions can only be found the OS-level manpages and resources for the target platform; these frequently reference additional resources, frequently noting the system-level knobs to which you referenced earlier.
Perl's only as functional as the underlying OS, so sometimes use of advanced features in Perl require getting a bit "dirty" by digging into the system or C APIs.
| [reply] |