Manual:HTB-Token Bucket Algorithm

From MikroTik Wiki
Revision as of 14:09, 10 May 2016 by Megis (talk | contribs)
Jump to navigation Jump to search

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 the 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 the 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 the 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.

The Diagram