首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >linux|性能参数测试

linux|性能参数测试

作者头像
heidsoft
发布于 2023-03-18 09:45:23
发布于 2023-03-18 09:45:23
2.4K00
代码可运行
举报
运行总次数:0
代码可运行

ommand

Description

echo "1" > /proc/sys/net/ipv4/tcp_window_scaling

Activate window scaling according to RFC 1323

echo "1" > /proc/sys/net/ipv4/tcp_timestamps

Activate timestamps according to RFC 1323

echo [wmax] > /proc/sys/net/core/rmem_max

Set maximum size of TCP receive window.

echo [wmax] > /proc/sys/net/core/wmem_max

Set maximum size of TCP transmit window.

echo [wmax] > /proc/sys/net/core/rmem_default

Set default size of TCP receive window.

echo [wmax] > /proc/sys/net/core/wmem_default

Set default size of TCP transmit window.

echo "[wmin] [wstd] [wmax]" > /proc/sys/net/ipv4/tcp_rmem

Set min, default, max receive window. Used by the autotuning function.

echo "[wmin] [wstd] [wmax]" > /proc/sys/net/ipv4/tcp_wmem

Set min, default, max transmit window. Used by the autotuning function.

echo "bmin bdef bmax" > /proc/sys/net/ipv4/tcp_mem

Set maximum total TCP buffer-space allocatable. Used by the autotuning function.

ifconfig eth? txqueuelen 1000

Define length of transmit queue. Replace "?" with actual interface number.

/proc/sys/net/ipv4/tcp_wmem

为自动调优定义socket使用的内存。第一个值是为socket发送缓冲区分配的最少字节数;第二个值是默认值(该值会被wmem_default覆盖),缓冲区在系统负载不重的情况下可以增长到这个值;第三个值是发送缓冲区空间的最大字节数(该值会被wmem_max覆盖)。

/proc/sys/net/ipv4/tcp_rmem

为自动调优定义socket使用的内存。第一个值是为socket接收缓冲区分配的最少字节数;第二个值是默认值(该值会被rmem_default覆盖),缓冲区在系统负载不重的情况下可以增长到这个值;第三个值是接收缓冲区空间的最大字节数(该值会被rmem_max覆盖)。

大文件制作

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#kilobytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200K

#megabytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200M

#gigabytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200G

#terabytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200T

未限速情况文件下载

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
heidsoft@heidsoft-dev:~$ wget --no-proxy http://172.16.59.20/bigfile
--2023-02-25 21:48:04--  http://172.16.59.20/bigfile
Connecting to 172.16.59.20:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10737418240 (10G) [application/octet-stream]
Saving to: ‘bigfile’

bigfile                     2%[                                    ] 239.71M  54.6MB/s    eta 3m 4s  ^C

增加带宽限速

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  tc  [ OPTIONS ] qdisc [ add | change | replace | link | delete ] dev DEV [ parent qdisc-id |
       root ] [ handle qdisc-id ] [ ingress_block BLOCK_INDEX ] [ egress_block BLOCK_INDEX ]  qdisc
       [ qdisc specific parameters ]

       tc  [  OPTIONS ] class [ add | change | replace | delete ] dev DEV parent qdisc-id [ classid
       class-id ] qdisc [ qdisc specific parameters ]

       tc [ OPTIONS ] filter [ add | change | replace | delete | get ] dev DEV [ parent qdisc-id  |
       root ] [ handle filter-id ] protocol protocol prio priority filtertype [ filtertype specific
       parameters ] flowid flow-id

       tc [ OPTIONS ] filter [ add | change | replace | delete | get ] block BLOCK_INDEX  [  handle
       filter-id  ]  protocol  protocol prio priority filtertype [ filtertype specific parameters ]
       flowid flow-id
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
cat htb.sh 
#!/bin/bash
tc qd del dev ens33 root
tc qd add dev ens33 root handle 1: htb default 100
tc cl add dev ens33 parent 1: classid 1:1 htb rate 20000mbit burst 20k
tc cl add dev ens33 parent 1:1 classid 1:10 htb rate 1000mbit burst 20k
tc cl add dev ens33 parent 1:1 classid 1:100 htb rate 20000mbit burst 20k
tc qd add dev ens33 parent 1:10 handle 10: netem delay 200ms
tc qd add dev ens33 parent 1:100 handle 100: fq_codel
tc fi add dev ens33 protocol ip parent 1:0 prio 1 u32 match ip sport 80 0xffff flowid 1:10
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
heidsoft@heidsoft-dev:~$ httping 172.16.59.20
PING 172.16.59.20:80 (/):
connected to 172.16.59.20:80 (239 bytes), seq=0 time=439.90 ms 
connected to 172.16.59.20:80 (239 bytes), seq=1 time=433.06 ms 
connected to 172.16.59.20:80 (239 bytes), seq=2 time=435.11 ms 
connected to 172.16.59.20:80 (239 bytes), seq=3 time=434.99 ms 
connected to 172.16.59.20:80 (239 bytes), seq=4 time=436.19 ms 
connected to 172.16.59.20:80 (239 bytes), seq=5 time=432.37 ms
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#!/bin/bash  
# Full path to tc binary 

TC=$(which tc)

#
# NETWORK CONFIGURATION
# interface - name of your interface device
# interface_speed - speed in mbit of your $interface
# ip - IP address of your server, change this if you don't want to use
#      the default catch all filters.
#
interface=eth0
interface_speed=100mbit
ip=4.1.2.3 # The IP address bound to the interface

# Define the upload and download speed limit, follow units can be 
# passed as a parameter:
# kbps: Kilobytes per second
# mbps: Megabytes per second
# kbit: kilobits per second
# mbit: megabits per second
# bps: Bytes per second
download_limit=512kbit
upload_limit=10mbit    


# Filter options for limiting the intended interface.
FILTER="$TC filter add dev $interface protocol ip parent 1: prio 1 u32"

#
# This function starts the TC rules and limits the upload and download speed
# per already configured earlier.
# 

function start_tc { 
    tc qdisc show dev $interface | grep -q "qdisc pfifo_fast 0"  
    [ "$?" -gt "0" ] && tc qdisc del dev $interface root; sleep 1  

    # start the tc configuration
    $TC qdisc add dev $interface root handle 1: htb default 30
    $TC class add dev $interface parent 1: classid 1:1 htb rate $interface_speed burst 15k

    $TC class add dev $interface parent 1:1 classid 1:10 htb rate $download_limit burst 15k
    $TC class add dev $interface parent 1:1 classid 1:20 htb rate $upload_limit burst 15k

    $TC qdisc add dev $interface parent 1:10 handle 10: sfq perturb 10
    $TC qdisc add dev $interface parent 1:20 handle 20: sfq perturb 10

    # Apply the filter rules
    
    # Catch-all IP rules, which will set global limit on the server
    # for all IP addresses on the server. 
    $FILTER match ip dst 0.0.0.0/0 flowid 1:10
    $FILTER match ip src 0.0.0.0/0 flowid 1:20

    # If you want to limit the upload/download limit based on specific IP address
    # you can comment the above catch-all filter and uncomment these:
    #
    # $FILTER match ip dst $ip/32 flowid 1:10
    # $FILTER match ip src $ip/32 flowid 1:20
}

#
# Removes the network speed limiting and restores the default TC configuration
#
function stop_tc {
    tc qdisc show dev $interface | grep -q "qdisc pfifo_fast 0"
    [ "$?" -gt "0" ] && tc qdisc del dev $interface root
}

function show_status {
        $TC -s qdisc ls dev $interface
}
#
# Display help 
#
function display_help {
        echo "Usage: tc [OPTION]"
        echo -e "\tstart - Apply the tc limit"
        echo -e "\tstop - Remove the tc limit"
        echo -e "\tstatus - Show status"
}

# Start
if [ -z "$1" ]; then
        display_help
elif [ "$1" == "start" ]; then
        start_tc
elif [ "$1" == "stop" ]; then
        stop_tc
elif [ "$1" == "status" ]; then
        show_status
fi

调整tcp_wmem

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@MANAGER ~]# echo 52428800 52428800 52428800 >/proc/sys/net/ipv4/tcp_wmem

文件下载状态

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
heidsoft@heidsoft-dev:~$ wget --no-proxy http://172.16.59.20/bigfile
--2023-02-25 21:54:40--  http://172.16.59.20/bigfile
Connecting to 172.16.59.20:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10737418240 (10G) [application/octet-stream]
Saving to: ‘bigfile.1’

bigfile.1                   3%[>                                   ] 334.96M  18.6MB/s    eta 16m 58s^
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
How To: Network / TCP / UDP Tuning
This is a very basic step by step description of how to improve the performance networking (TCP & UDP) on Linux 2.4+ for high-bandwidth applications. These settings are especially important for GigE links. Jump to Quick Step or All The Steps.
Assumptions
This howto assumes that the machine being tuned is involved in supporting high-bandwidth applications. Making these modifications on a machine that supports multiple users and/or multiple connections is not recommended – it may cause the machine to deny connections because of a lack of memory allocation.
The Steps
1. Make sure that you have root privleges.
2. Type: sysctl -p | grep mem
This will display your current buffer settings. Save These! You may want to roll-back these changes
3. Type: sysctl -w net.core.rmem_max=8388608
This sets the max OS receive buffer size for all types of connections.
4. Type: sysctl -w net.core.wmem_max=8388608
This sets the max OS send buffer size for all types of connections.
5. Type: sysctl -w net.core.rmem_default=65536
This sets the default OS receive buffer size for all types of connections.
6. Type: sysctl -w net.core.wmem_default=65536
This sets the default OS send buffer size for all types of connections.
7. Type: sysctl -w net.ipv4.tcp_mem=8388608 8388608 8388608TCP Autotuning setting. “The tcp_mem variable defines how the TCP stack should behave when it comes to memory usage. … The first value specified in the tcp_mem variable tells the kernel the low threshold. Below this point, the TCP stack do not bother at all about putting any pressure on the memory usage by different TCP sockets. … The second value tells the kernel at which point to start pressuring memory usage down. … The final value tells the kernel how many memory pages it may use maximally. If this value is reached, TCP streams and packets start getting dropped until we reach a lower memory usage again. This value includes all TCP sockets currently in use.8. Type: sysctl -w net.ipv4.tcp_rmem=4096 87380 8388608TCP Autotuning setting. “The first value tells the kernel the minimum receive buffer for each TCP connection, and this buffer is always allocated to a TCP socket, even under high pressure on the system. … The second value specified tells the kernel the default receive buffer allocated for each TCP socket. This value overrides the /proc/sys/net/core/rmem_default value used by other protocols. … The third and last value specified in this variable specifies the maximum receive buffer that can be allocated for a TCP socket.9. Type: sysctl -w net.ipv4.tcp_wmem=4096 65536 8388608TCP Autotuning setting. “This variable takes 3 different values which holds information on how much TCP sendbuffer memory space each TCP socket has to use. Every TCP socket has this much buffer space to use before the buffer is filled up. Each of the three values are used under different conditions. … The first value in this variable tells the minimum TCP send buffer space available for a single TCP socket. … The second value in the variable tells us the default buffer space allowed for a single TCP socket to use. … The third value tells the kernel the maximum TCP send buffer space.10. Type:sysctl -w net.ipv4.route.flush=1
This will enusre that immediatly subsequent connections use these values.
Quick Step
Cut and paste the following into a linux shell with root privleges:
sysctl -w net.core.rmem_max=8388608
sysctl -w net.core.wmem_max=8388608
sysctl -w net.core.rmem_default=65536
sysctl -w net.core.wmem_default=65536
sysctl -w net.ipv4.tcp_rmem=4096 87380 8388608′
sysctl -w net.ipv4.tcp_wmem=4096 65536 8388608′
sysctl -w net.ipv4.tcp_mem=8388608 8388608 8388608′
sysctl -w net.ipv4.route.flush=1
Another set of parameters suggested from VMWare Communities :
net.core.wmem_max = 16777216
net.core.rmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_rmem = 4096 262144 16777216
net.ipv4.tcp_wmem = 4096 262144 16777216
net.core.optmem_max = 524288
net.core.netdev_max_backlog = 200000
  • https://www.cnblogs.com/fczjuever/archive/2013/04/17/3026694.html
  • https://github.com/leandromoreira/linux-network-performance-parameters/blob/master/README.md
  • https://github.com/cilium/pwru
  • https://www.brendangregg.com/perf.html
  • http://proj.sunet.se/E2E/tcptune.html
  • https://github.com/penberg/linux-networking
  • https://cloud.tencent.com/developer/article/1409664
  • https://gist.github.com/Lakshanz/19613830e5c6f233754e12b25408cc51
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-02-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 云数智圈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
【性能优化】Linux系统性能优化汇总
大多数Linux 发布版都定义了适当的缓冲区和其他 Transmission Control Protocol(TCP)参数。可以修改这些参数来分配更多的内存,从而改进网络性能。设置内核参数的方法是通过 proc 接口,也就是通过读写 /proc 中的值。幸运的是,sysctl 可以读取 /etc/sysctl.conf 中的值并根据需要填充/proc,这样就能够更轻松地管理这些参数。清单2 展示在互联网服务器上应用于 Internet 服务器的一些比较激进的网络设置。
Luga Lee
2022/03/25
1.7K0
linux性能调优(整理)
为什么要性能调优? 大部分的linux发行版是为了完全兼容市场中大部分计算机而设计的。这是一个相当混杂的硬件集合(硬盘,显卡,网卡,等等)。所以Red Hat, Suse,Mandriva和其他的一些发行版厂商选择了一些保守的设置来确保安装成功。 简单地说:你的发行版运行的很好,但是它可以运行地更好! 比如,可能有一个具体一些特殊特性的高级硬盘,而这些特性在标准配置的情况下可能就没被启用。 磁盘子系统的调优 对于Linux的Ext3/4来说,几乎在所有情况下都有所帮助的一个参数是关闭文件系统访问时间,在/
小小科
2018/05/03
7.8K0
linux性能调优(整理)
Linux服务器性能评估与优化(五)--内核参数
之前文章《Linux服务器性能评估与优化(一)》太长,阅读不方便,因此拆分成系列博文:
黄规速
2022/04/14
4.4K0
Linux优化方法收集与整理
之前一直有博主要求整理下 VPS 主机优化方法,那么如果你是 VPS 主机(Linux),可以尝试一下了,尤其是 linux 系统的内核参数优化。 一、增加 SWAP 分区 VPS(Virtual Private Server 虚拟专用服务器)技术,将一部服务器分割成多个虚拟专享服务器的优质服务。每个 VPS 都可分配独立公网 IP 地址、独立操作系统、独立超大空间、独立内存、独立执行程序和独立系统配置等。 下面是配置过程中的一些笔记: VPS 只有一个根分区,没有 swap 交换分区。VPS 内存不大,于
张戈
2018/03/23
1.4K0
Linux优化方法收集与整理
Linux 下 Oracle 内核参数优化
数据库的性能优化涉及到整个数据库运行环境的方方面面,诸如操作系统,Oracle自身,存储,网络等等几个大块。而操作系统则是Oracle稳定运行与最大化性能的基石。本文主要描述基于Linux系统下 Oracle 内核参数的配置。
Leshami
2022/03/14
3.2K0
Linux 内核参数优化(for oracle)
    Oracle 不同平台的数据库安装指导为我们部署Oracle提供了一些系统参数设置的建议值,然而建议值是在通用的情况下得出的结论,并非能完全满足不同的需求。使用不同的操作系统内核参数将使得数据库性能相差甚远。本文描述了linux下几个主要内核参数的设置,供参考。
Leshami
2018/08/14
4.8K0
Linux TCP队列相关参数的总结
在Linux上做网络应用的性能优化时,一般都会对TCP相关的内核参数进行调节,特别是和缓冲、队列有关的参数。网上搜到的文章会告诉你需要修改哪些参数,但我们经常是知其然而不知其所以然,每次照抄过来后,可能很快就忘记或混淆了它们的含义。本文尝试总结TCP队列缓冲相关的内核参数,从协议栈的角度梳理它们,希望可以更容易的理解和记忆。注意,本文内容均来源于参考文档,没有去读相关的内核源码做验证,不能保证内容严谨正确。作为Java程序员没读过内核源码是硬伤。
mazhen
2023/11/23
7700
Linux TCP队列相关参数的总结
Linux内核参数使用与优化介绍
Tips : OOM(Out Of Memory) killer机制是指Linux操作系统发现可用内存不足时,强制杀死一些用户进程(非内核进程),来保证系统有足够的可用内存进行分配。 Tips : swappiness参数在Linux 3.5版本前后的表现并不完全相同,Redis运维人员在设置这个值需要关注当前操作系统的内核版本。
全栈工程师修炼指南
2022/09/29
3.8K0
wrk|小而强的性能测试工具
Nginx的最大连接数算法:worker_processes * worker_connections = 16,384
Python研究所
2022/06/17
6950
wrk|小而强的性能测试工具
tc--流控 转
如果你对 Linux 流控感兴趣,如果你需要搭建高性能的 Linux 网关 , 本文将会使你受益颇多。
阿dai学长
2019/04/03
3.7K0
tc--流控
                                                                            转
TC(Traffic Control)命令—linux自带高级流控
Linux操作系统中的流量控制器TC(Traffic Control)用于Linux内核的流量控制,主要是通过在输出端口处建立一个队列来实现流量控制。 接收包从输入接口进来后,经过流量限制丢弃不符合规定的数据包,由输入多路分配器进行判断选择:
阿dai学长
2019/04/03
71.8K2
Linux 性能调优之内核可调参数
对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
山河已无恙
2023/12/04
8130
Linux 性能调优之内核可调参数
linux下使用tc控制和模拟网络流量
netem 与 tc: netem 是 Linux 2.6 及以上内核版本提供的一个网络模拟功能模块。该功能模块可以用来在性能良好的局域网中,模拟出复杂的互联网传输性能,诸如低带宽、传输延迟、丢包等等情况。使用 Linux 2.6 (或以上) 版本内核的很多发行版 Linux 都开启了该内核功能,比如 Fedora、Ubuntu、Redhat、OpenSuse、CentOS、Debian 等等。 tc 是Linux 系统中的一个工具,全名为 traffic control(流量控制)。tc 可以用来控制 netem 的工作模式,也就是说,如果想使用 netem ,需要至少两个条件,一个是内核中的 netem 功能被包含,另一个是要有 tc 。
sunsky
2021/01/13
5K0
Linux 流量控制全攻略?看这里~
WebjxCom 友情提示: 公司一台服务器,网络环境太高,那台服务器和源服务器连接下载,就跑到 400M-500M,为了控制一下,所以研究了一下 TC. 来做流量控制。给他控制到小点,不要让这一台占了所有的网络。TC 很是强大啊,很多所谓的硬件路由器,都是基于这个做的。
用户6543014
2019/10/25
2.3K0
K8S OS 内核性能参数调优
[1] ES Configuration: https://www.elastic.co/guide/en/elasticsearch/reference/2.1/setup-configuration.html#vm-max-map-count [2] root cause kernel soft lockups · Issue #37853 · kubernetes/kubernetes (github.com): https://github.com/kubernetes/kubernetes/issues/37853 [3] service-node-port-range and ip_local_port_range collision · Issue #6342 · kubernetes/kops (github.com): https://github.com/kubernetes/kops/issues/6342 [4] Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com): https://github.com/kubernetes-retired/kube-deploy/issues/261 [5] Upgrading docker 1.13 on nodes causes outbound container traffic to stop working · Issue #40182 · kubernetes/kubernetes (github.com): https://github.com/kubernetes/kubernetes/issues/40182 [6] arp_cache: neighbor table overflow! · Issue #4533 · kubernetes/kops (github.com): https://github.com/kubernetes/kops/issues/4533
东风微鸣
2022/04/22
2.1K0
Linux 性能调优之网络内核参数优化
对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
山河已无恙
2023/11/02
2.4K0
Linux 性能调优之网络内核参数优化
服务器性能调优
  当一个系统的CPU空闲时间或者等待时间小于5%时,我们就可以认为系统的CPU资源耗尽,我们应该对CPU进行性能调优。
DevinGeng
2019/04/09
1.9K0
Linux 内核参数
对于TCP的初始接收窗口大小,linux和centos的实现是不一样的,如linux内核3.10版本的初始接收窗口定义为10mss,但centos 3.10内核中的初始窗口大小定义为TCP_INIT_CWND * 2,即20*MSS大小。(看着linux源码在centos7.4系统上测试,纠结了好久。。)
charlieroro
2020/03/23
9K0
每日一问题探索-高并发下的linux优化
Linux内核是高并发服务的关键组件之一。以下是一些可用于优化Linux内核的配置。
五分钟学SRE
2023/12/05
4600
每日一问题探索-高并发下的linux优化
linux网络参数解析
linux网络参数主要位于下面两个目录下:/proc/sys/net/core/和/proc/sys/net/ipv4/, 下面分别对这两个目录下常用的几个网络参数做下说明:
王亚昌
2018/08/03
1.7K0
相关推荐
【性能优化】Linux系统性能优化汇总
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档