Giter Club home page Giter Club logo

Comments (1)

lowzj avatar lowzj commented on May 22, 2024

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任务按此新值来限速。

from dragonfly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.