Linux的NetLimiterlike带宽限制和QoS

traffictoll的Python项目详细描述


交通费

Linux网络限制器的带宽限制和QoS

说明

TrafficToll允许您全局限制下载和上载带宽(每个接口) 以及每个进程,甚至在进程运行时。此外,它还允许您 为不同的进程使用QoS流量优先级。在

配置可以很容易地调整和新的限制和优先权应用在任何地方 点,而类似的工具只能应用固定的全局限制 接口、某些端口或要求您通过它们启动进程(因此 重新启动目标进程以更改限制)。在

使用

# tt device config

其中device是要限制的接口(通常是 连接到internet)。例如:

  • # tt enp3s0 night.yaml --delay 0.5(常规接口,检查间隔 半秒钟用于网络化流程的更改)
  • # tt tun0 day.yaml --logging-level DEBUG(VPN接口,调整 要调试的日志记录级别)

目前,TrafficToll是基于YAML配置文件工作的。配置文件 最好用例子来解释:

# The rate limits for the specified interface. Specifying these values is useful for two# things: 1) you want to limit the used bandwidth for the entire interface or 2) you# want to make use of traffic prioritization.# If you want to 1) limit the used bandwidth for the entire interface, simply specify# values below your actual speed: the traffic will be shaped in such a way, that it does# not exceed the specified numbers.# If you want to 2) make use of the traffic prioritization feature, these values must be# as close as possible to your real speed: if they are too low, traffic prioritization# will work, but you are losing part of your bandwidth; if they are too high, traffic# prioritization won't work as well as it could. I recommend you use some internet speed# test you can find online to get an approximation for the correct values.# If you don't want to do 1) or 2), you can omit these values. Bandwidth limiting per# application will still work, just traffic prioritization won't work as well or# entirely.download:5mbpsupload:1mbps# Guaranteed download and upload rates for all global traffic that is not shaped as part# of a matched process by TrafficToll. The idea here is to leave enough "guaranteed"# bandwidth to all applications not defined in "processes", so that they are not starved# to a bandwidth, by processes with higher priority, that would cause the other IP to# drop the connection. These are the default values, if omitted. Keep in mind that this# doesn't reserve the bandwidth -- if this traffic is not made use of, it's available# to processes with higher priority.download-minimum:100kbpsupload-minimum:10kbps# The global download and upload priority. This will be the priority for traffic that is# not created by any of the processes. By default it will always be the lowest priority# if any of the processes specify a download or upload priority explicitly, otherwise# all traffic will have the same priority.#download-priority: 0#upload-priority: 0# A list of processes you want to match and their respective settingsprocesses:# You can name the process what you want, it is only used to identify it on the CLI# output"PathofExile":# Adjust the traffic priority to 0 (highest possible, higher integers mean _lower_# priority) to prevent lag and high pings in the game even when we create heavy# traffic otherwise. If these priorities are omitted, they will default to 0: the# same priority for all the traffic on the interface. As soon as you explicitly# specify a priority for a process, the other traffic on the interface will get a# lower priority, so will other processes where you did not explicitly specify# another priority. In this case "Path of Exile" traffic will have a priority of 0,# the highest, and the interface traffic and other processes will have a priority of# 1.download-priority:0upload-priority:0# Download and upload rate limits can be entirely omitted if you don't want to apply# any, in this case traffic will only be prioritized like specified.#download:#upload:# The match section. A process is selected when all predicates in the match section# match. Every attribute psutil.Process# (https://psutil.readthedocs.io/en/latest/index.html#psutil.Process) provides on# Linux can be matched on, using regular expressions. Integer attributes will be# treated as strings and list attributes will be joined using shlex.join() before# matching. If you want to, you can also specify a regular expression with an OR# operator and match many processes which will all share the specified bandwidth# limit or traffic priority.# If you do not see a line starting with "Shaping traffic for..." with your process# name in it, while it is clearly causing traffic, your match section is failing.# Please make sure it works correctly.match:-name:"PathOfExile_x64"Vivaldi:# Additionally specify fixed bandwidth limits for the browser. Setting bandwidth# limits higher than the interface limits will not work. Different processes# borrow available traffic from the interface limits using their specified priority.download:2500kbpsupload:500kbps# Explicitly set a lower download and upload priority to Path of Exile so our# browsing does not cause the game's ping to spike. This would have happened# automatically if we omitted it, because we specified a priority for "Path of# Exile" -- we are just doing it here for clarity.download-priority:1upload-priority:1match:-exe:/opt/vivaldi/vivaldi-binDiscord:# Set Discord's traffic priority to the lowest: this means if we create traffic via# either "Path of Exile" or "Vivaldi" it will get priority and Discord's latency and# traffic will slow down accordinglydownload-priority:2upload-priority:2# Additionally specify fixed bandwidth limits for Discord. Please note that just# because we specified 50% of the interface bandwidth for "Vivaldi" and "Discord"# each, does not mean "Path of Exile" or other processes will be starved for# traffic: Because we omitted download and upload limits for "Path of Exile" 100% of# the interface rate is automatically assumed for that process, in this case# 5mbps/1mbps. Additionally, because "Path of Exile" has a higher priority than# either of the two, in the extreme case that Vivaldi and Discord utilize their# bandwidth limits fully (and thus the entire interface's speed), "Path of Exile"# traffic will get priority and traffic for Vivaldi and Discord will be# appropriately reduced.download:2500kbpsupload:500kbpsmatch:-exe:/opt/discord/DiscordRiot:download-priority:2upload-priority:2# The process that actually creates network traffic for electron-based applications# is not uniquely identifiable. Instead we match a uniquely identifiable parent# process, in this case "riot-desktop", and set recursive to True. This instructs# TrafficToll to traffic shape the connections of the matched process and all its# descendantsrecursive:Truematch:-name:riot-desktopJDownloader 2:download:300kbps# The download-priority and upload-priority if omitted while another process# explicitly specifies them will automatically be the lowest: in this case 2, the# same as "Discord", our lowest priority process.# Since the download and upload priority of this process is the lowest, make sure# that its connections don't starve when processes with higher priority use up all# the available bandwidth. These are the default values for each process and will be# applied if omitted.download-minimum:10kbpsupload-minimum:1kbps# JDownloader 2 obviously has its own bandwidth limiting, this is just here as an# example to show that matching on something else than the executable's name and# path is possiblematch:-cmdline:.* JDownloader.jar

单元可以指定为tc支持的所有格式,即:bit(有和没有 后缀)、kbit、mbit、gbit、tbit、bps、kbps、mbps、gbps、tbps。以IEC单位规定, 将SI前缀(k-、m-、g-、t-)替换为IEC前缀(ki-、mi-、gi-和ti-) 分别。在

所有的限制和优先级都可以忽略,在这种情况下显然没有流量整形 将应用。当匹配部分中的所有谓词匹配时,将选择一个进程。 每个属性 ^{} Linux上的提供可以在上匹配,使用正则表达式。在

当您使用Ctrl+C终止tt时,对流量计划的所有更改都将 恢复,允许您轻松更新配置和应用新的限制。在

安装

$ pip3 install traffictoll

确保使用python3安装提供的pip可执行文件。可能吧 简单地pip或{},这取决于您的系统。tt必须以根用户身份运行。在

截图

因为图片总是很好,即使对于CLI应用程序:

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在IntelliJ中导入Gradle项目?   java使用dropwizard在ContainerResponseFilter上注入HttpServletRequest HttpServletRequest   基于Java的简单规则引擎的回退实现   java无法在引号“”中获取字符串值(Android)   直接从java书籍中复制的用户界面代码不希望运行   java如何检查已安装的libevent版本?   javascript如何在CryptoJS中解密文件,由JAVA使用AES加密   如何为自制软件打包Java GUI应用程序   java IntelliJ,在调试模式下运行glassfish,未部署工件   swing重新打开以前关闭的窗口Java   带参数的java测试资源   此URL不支持java HTTP Status 405 HTTP方法GET,即使没有doget()方法   java Heroku应用程序使用s3上传图像   java使两个水平文本视图在一起小于某个宽度时保持左侧,但如果它们大于宽度,则省略左侧视图?   Thymeleaf中的java绑定列表;索引超出范围   java类型JspWriter中的print(boolean)方法不适用于参数   java安卓要么没有足够的内存用于后台任务,要么GC有问题   如何使用证书过期的旧java小程序?   java如何从事件中获取数据到主函数?