Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

[question] dragonfly 主机级别限速问题 #95

Closed
U201114227 opened this issue Jun 29, 2018 · 1 comment
Closed

[question] dragonfly 主机级别限速问题 #95

U201114227 opened this issue Jun 29, 2018 · 1 comment

Comments

@U201114227
Copy link

您好,我是华中科技大学的一名研究生,我在github上看到了阿里巴巴开源的文件分发系统的源码draonfly,该系统中提到提供主机级别限速的功能,我对这方面很感兴趣,在阅读源码的过程中,有一些地方不太理解,源码的gettet模块是客户端处理文件分发和共享的模块,其中有一个componnet中有一个ratelimiter的类是用来限速的,其中有几个关键变量token和window是具体代表什么呢?没有特别弄明白。
另外,我想问一下您的主机限速的逻辑是什么呢?是怎么保证该主机的速度不超过其设置的运行速度的呢?

@lowzj
Copy link
Member

lowzj commented Jun 29, 2018

tokenwindow代表什么?

dfget里实现里一个简单的令牌桶算法(token-bucket)来限流,关于限流的一些文章可以参考这里

关于令牌桶算法,下面节选自Wikipedia:

The token bucket algorithm can be conceptually understood as follows:

1. A token is added to the bucket every 1/r seconds.
2. The bucket can hold at the most b tokens. If a token arrives when the bucket is full, it is discarded.
3. When a packet (network layer PDU) of n bytes arrives, n tokens are removed from the bucket, and the packet is sent to the network.
4. If fewer than n tokens are available, no tokens are removed from the bucket, and the packet is considered to be non-conformant.

代码里的token跟这里的token完全一致。window是维基里说的1/r seconds,表示产生令牌的间隔,window期间产生的令牌数由rate指定。


主机限速的逻辑

同一台机器上,第一个dfget进程启动时,会同时启动一个server进程用来做p2p里的上传服务,端口会保存在本地的meta文件里;当其他dfget启动时,会检查是否有server已经启动了,有的话,上报自己的限速参数,由server计算出各个dfget任务的速率比例,再按此比例重新分配totallimit值,各个dfget任务按此新值来限速。

@lowzj lowzj added the question label Jun 29, 2018
@lowzj lowzj changed the title dragonfly 主机级别限速问题 [question] dragonfly 主机级别限速问题 Jun 29, 2018
@lowzj lowzj closed this as completed Sep 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants