Fair Bandwidth Sharing for simple queues
Z Wiki UnArt Slavičín
- Script name: "Fair Bandwidth Sharing" for simple queues
- Author: Tomas Dulik
- Date: Feb 2008
- Description: This script distributes the value of limit-at of a parent queue equally among all its children
- Tuto promennou nastav - misto "Ostatni" napis jmeno primo nadrazene (parent) fronty vsech uzivatelu!
- local usersParent "Ostatni"
- nasledujici 2 promenne definuji hodnotu "max-limit", ktera se nastavi vsem uzivatelum
- Pokud je promenna $userDownloadMaxLimit nebo $userUploadLimit = 0, pouzijeme hodnotu max-limit rodicovske fronty
- (hodnoty muzes ale zadat (v bits/sekundu) tak jak na nasledujicich radcich:
- local userDownloadMaxLimit 0
- local userUploadMaxLimit 512000
- Tady zacina skript - pokud tomu nerozumis, radsi do ne nerypej
- set usersParentMaxLimit [/queue simple get $usersParent max-limit]
- set slashPosition [:find $usersParentMaxLimit /]
- Pokud neni nastavena promenna $userDownloadMaxLimit, nastavime ji na max-limit rodicovske fronty
- if ($userDownloadMaxLimit=0) do={
:log info "max-limit for users' download was not set, using the max-limit of their parent queue..."
- z usersParentMaxLimit musime pomoci ":pick" vysekat max-limit pro download
:set userDownloadMaxLimit [:pick $usersParentMaxLimit ($slashPosition+1) [:len $usersParentMaxLimit]]
}
- Pokud neni nastavena promenna $userUploadMaxLimit, nastavime ji na max-limit rodicovske fronty
- if ($userUploadMaxLimit=0) do={
:log info "max-limit for users' upload was not set, using the max-limit of their parent queue..." :set userUploadMaxLimit [:pick $usersParentMaxLimit 0 $slashPosition]
}
- usersParentLimitAt bude retezec napr. 1000000/4000000 (tj. upload/download)
- set usersParentLimitAt [/queue simple get $usersParent limit-at]
- z usersParentLimitAt musime vysekat limit-at pro upload:
- set slashPosition [:find $usersParentLimitAt /]
- set usersParentUploadLimitAt [:pick $usersParentLimitAt 0 $slashPosition]
- a take limit-at pro download:
- set usersParentDownloadLimitAt [:pick $usersParentLimitAt ($slashPosition+1) [:len $usersParentLimitAt]]
- A ted uz zbyva nastavit spravne limit-at a max-limit pro vsechny uzivatele:
- Sestavime si seznam front vsech uzivatelu (maji parent-a zadaneho prvnim radkem tohoto skriptu]
- set usersQueues [/queue simple find parent=$usersParent]
- spocitame, kolik tech uzivatelu mame:
- set usersCount [:len $usersQueues]
- a vypocitame, jak velky ma byt limit-at pro jednotlive uzivatele:
- set userDownloadLimitAt ($usersParentDownloadLimitAt/$usersCount)
- set userUploadLimitAt ($usersParentUploadLimitAt/$usersCount)
- a tady uz to vsem uzivatelum nastavime:
- foreach queue in=$usersQueues do={
/queue simple set $queue limit-at ($userUploadLimitAt . "/" . $userDownloadLimitAt) max-limit ($userUploadMaxLimit . "/" . $userDownloadMaxLimit) direction both
}