Difference between revisions of "Manual:HTB-Token Bucket Algorithm"

From MikroTik Wiki
Jump to: navigation, search
Line 4: Line 4:
  
 
This part of the wiki will concentrate on "Token Bucket" part of '''Hierarchical Token Bucket'''(HTB) - an algorithm inside the single queue.   
 
This part of the wiki will concentrate on "Token Bucket" part of '''Hierarchical Token Bucket'''(HTB) - an algorithm inside the single queue.   
"Hierarchical" part of '''Hierarchical Token Bucket'''(HTB) queuing method are covered here:
+
"Hierarchical" part of '''Hierarchical Token Bucket'''(HTB) queuing method is covered here:
 
http://wiki.mikrotik.com/wiki/Manual:HTB
 
http://wiki.mikrotik.com/wiki/Manual:HTB
  
 
==Token Bucket algorithm (Red part of Diagram)==
 
==Token Bucket algorithm (Red part of Diagram)==
  
The Token Bucket algorithm is based on an analogy to a bucket where tokens, representing in bytes, are added at specific rate.
+
The Token Bucket algorithm is based on an analogy to a bucket where tokens, represented in bytes, are added at specific rate.
 
The bucket itself has a specified capacity.  
 
The bucket itself has a specified capacity.  
  
Line 18: Line 18:
 
'''Bucket capacity = bucket-size * max-limit '''  
 
'''Bucket capacity = bucket-size * max-limit '''  
  
*'''bucket size''' (0..10, Default:0.1) - queue option added in RouterOS v6.35, before that it had value ""0.1" that was impossible to change.
+
*'''bucket size''' (0..10, Default:0.1) - queue option added in RouterOS v6.35, before that it had value was hard-coded to "0.1".
  
 
Before letting any packet pass through queue, the bucket is inspected to see if it contains sufficient tokens at that moment.
 
Before letting any packet pass through queue, the bucket is inspected to see if it contains sufficient tokens at that moment.
Line 28: Line 28:
 
==Packet queue (Blue part of Diagram)==
 
==Packet queue (Blue part of Diagram)==
  
Size of this packet queue,sequence how packets are added to this queue, and when packets are discarded, are determined by:
+
Size of this packet queue, sequence, how packets are added to this queue, and when packets are discarded, is determined by:
 
*'''queue-type''' - http://wiki.mikrotik.com/wiki/Manual:Queue#Kinds
 
*'''queue-type''' - http://wiki.mikrotik.com/wiki/Manual:Queue#Kinds
 
*'''queue-size''' - http://wiki.mikrotik.com/wiki/Manual:Queue_Size
 
*'''queue-size''' - http://wiki.mikrotik.com/wiki/Manual:Queue_Size
Line 37: Line 37:
 
Maximal token rate at any given time is equal to highest active of these values:
 
Maximal token rate at any given time is equal to highest active of these values:
  
* '''limit-at''' (''NUMBER/NUMBER'') : normal upload/download data rate that is guaranteed to a target  
+
* '''limit-at''' (''NUMBER/NUMBER'') : guaranteed upload/download data rate to a target  
* '''max-limit''' (''NUMBER/NUMBER'') : maximal upload/download data rate that is allowed for a target to reach {{{...|to reach what}}}
+
* '''max-limit''' (''NUMBER/NUMBER'') : maximal upload/download data rate that is allowed for a target
* '''burst-limit''' (''NUMBER/NUMBER'') : maximal upload/download data rate which can be reached while the burst is active
+
* '''burst-limit''' (''NUMBER/NUMBER'') : maximal upload/download data rate that is allowed for a target while the burst is active
  
 
'''burst-limit''' is active only when burst is in allowed state - more info here: http://wiki.mikrotik.com/index.php?title=Manual:Queues_-_Burst
 
'''burst-limit''' is active only when burst is in allowed state - more info here: http://wiki.mikrotik.com/index.php?title=Manual:Queues_-_Burst

Revision as of 15:07, 10 May 2016

Version.png

Applies to RouterOS: v6.33+

Overview

This part of the wiki will concentrate on "Token Bucket" part of Hierarchical Token Bucket(HTB) - an algorithm inside the single queue. "Hierarchical" part of Hierarchical Token Bucket(HTB) queuing method is covered here: http://wiki.mikrotik.com/wiki/Manual:HTB

Token Bucket algorithm (Red part of Diagram)

The Token Bucket algorithm is based on an analogy to a bucket where tokens, represented in bytes, are added at specific rate. The bucket itself has a specified capacity.

Queue gets tokens from parent queue, at a rate determined by parent queue.

If the bucket fills to capacity, newly arriving tokens are dropped

Bucket capacity = bucket-size * max-limit

  • bucket size (0..10, Default:0.1) - queue option added in RouterOS v6.35, before that it had value was hard-coded to "0.1".

Before letting any packet pass through queue, the bucket is inspected to see if it contains sufficient tokens at that moment.

If, yes, the appropriate number of tokens, are removed ("cashed in") and packet can pass the queue.

If, no, packets stays in the beginning of packet waiting queue until the appropriate amount of tokens are available.

Packet queue (Blue part of Diagram)

Size of this packet queue, sequence, how packets are added to this queue, and when packets are discarded, is determined by:


Token rate selection (Black part of Diagram)

Maximal token rate at any given time is equal to highest active of these values:

  • limit-at (NUMBER/NUMBER) : guaranteed upload/download data rate to a target
  • max-limit (NUMBER/NUMBER) : maximal upload/download data rate that is allowed for a target
  • burst-limit (NUMBER/NUMBER) : maximal upload/download data rate that is allowed for a target while the burst is active

burst-limit is active only when burst is in allowed state - more info here: http://wiki.mikrotik.com/index.php?title=Manual:Queues_-_Burst

In case limit-at was highest "Extra tokens" were issued to bypass parent queue max-limit limitation.

Diagram

Bucket size.png