Linux TCP参数——tcp_allowed_congestion_control

tcp_allowed_congestion_control

设置允许普通进程使用的拥塞控制算法。这个参数的值阈是tcp_available_congestion_control参数的子集。默认值为"reno"加上tcp_congestion_control参数设置的算法。

reno

慢启动阶段:在开始的时候,cwnd按指数增长(即每次翻倍),因为TCP试图估计网络的承载能力,这个阶段持续直到遇到第一个数据包丢失,如图中第一次垂直下降所示。

拥塞避免:在慢启动阶段达到ssthresh (慢启动阈值) 后,进入拥塞避免阶段,cwnd以线性方式逐渐增加,这可以看作是在探索网络容量的保守方式。

快速重传与快速恢复:当检测到数据包丢失时(一般通过重复的ACKs识别),TCP Reno 会执行一个"快速重传",并且进入"快速恢复"算法。在 Reno 中,cwnd 被设定为 ssthresh 的一半(图中的水平虚线表示),然后开始线性增长(拥塞避免),而不是像 Tahoe 一样重新开始慢启动。

TCP Tahoe的反应:当发生超时时,Tahoe 将cwnd重置为1,并重新开始慢启动。这可以在图中的第一次和第二次陡峭下降中看到。

TCP_CONGESTION

可以通过该参数设置拥塞控制算法

c 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main()
{
    int sockfd;
    struct sockaddr_in servaddr;
    char buffer[1024];

    // 创建TCP套接字
    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
    {
        perror("Socket creation failed");
        exit(EXIT_FAILURE);
    }
    
	// 获取当前的拥塞控制算法
	char current_algorithm[32];
	socklen_t len = sizeof(current_algorithm);
	if (getsockopt(sockfd, IPPROTO_TCP, TCP_CONGESTION, current_algorithm, &len) < 0) {
	    perror("Getsockopt TCP_CONGESTION failed");
	    exit(EXIT_FAILURE);
	}
	printf("Current congestion control algorithm: %s\n", current_algorithm);

	// 设置拥塞控制算法为cubic
	const char *congestion_algorithm = "cubic";
	if (setsockopt(sockfd, IPPROTO_TCP, TCP_CONGESTION, congestion_algorithm, strlen(congestion_algorithm)) < 0) 
	{
	    perror("Setsockopt TCP_CONGESTION failed");
	    exit(EXIT_FAILURE);
	}
	printf("New congestion control algorithm: %s\n", congestion_algorithm);

    // 连接到服务器
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(8080);
    servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");

    if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) 
    {
        perror("Connection failed");
        exit(EXIT_FAILURE);
    }

    // 在此处可以进行数据传输操作
    while(1);
    // 关闭套接字
    close(sockfd);

    return 0;
}

总结

tcp_allowed_congestion_control设置普通进程所能使用的拥塞算法。

相关推荐
用户1129361121912 小时前
npm 都提示成功了,node_modules 为什么还占着 370M?
linux·前端·后端
如夏倾城15 小时前
大模型(Large Model)解析:从数据类型、模型架构到任务选型
服务器·网络·数据库·语言模型·架构·audiolm
女神下凡17 小时前
芯易选(133):建荣(AppoTech)_开发指南
linux·arm开发·stm32·单片机·嵌入式硬件
JWIPC18 小时前
MyClaw 3.0 自动化数据采集实战指南
linux·运维·笔记·科技·深度学习·物联网·自动化
Risehuxyc19 小时前
MTU 和 MSS 详解
网络·智能路由器
Flynt19 小时前
自托管重开实录:照 HN 419 分热帖让 AI 从零搭一遍,15 分钟踩了三个真坑
linux·开源·ai编程
ikgy19 小时前
JAVA EE:7.网络初识
网络
AlanAshley21 小时前
移动端省流方案:压缩+缓存
网络·缓存
EmbeddedChen21 小时前
Linux 怎么查看 IP 地址和网络状态?常用网络命令入门
linux·网络·ip·route·ping
FakeOccupational21 小时前
fpga系列 HDL : 选择RAM IP(Two Port IP核) 乒乓缓冲(Ping-Pong Buffer)工作流程
网络协议·tcp/ip·fpga开发