trickA variant of token bucket implementation
Posted albumcover
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了trickA variant of token bucket implementation相关的知识,希望对你有一定的参考价值。
1 struct TokenBucket 2 { 3 double fill_interval_; 4 double gen_interval_; 5 double reset_time_; 6 // reset_time_ is equivalent to last_consume_time + token_num and 7 // the calculated token num is auto renormalized on limit change. 8 9 TokenBucket() 10 : fill_interval_(0.0) 11 , gen_interval_(0.0) 12 , reset_time_(0.0) {} 13 14 // eg, for 10req/30s, capacity=10, period=30 15 void set_limit(double capacity, double period) 16 { 17 fill_interval_ = period; 18 gen_interval_ = period / capacity; 19 } 20 21 bool consume(unsigned num) 22 { 23 double curr_time = get_monotonic_time(); 24 double new_reset_time = std::max(reset_time_, curr_time - fill_interval_) + gen_interval_ * num; 25 if (curr_time >= new_reset_time) 26 { 27 reset_time_ = new_reset_time; // reset_time_ is monotonic increasing 28 return true; 29 } 30 return false; 31 } 32 };
以上是关于trickA variant of token bucket implementation的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 QDBus 解析 String, Dict of String, Variant 的字典?
On a variant of Wiener's lemma
MAGENTA: Meta-Analysis Gene-set Enrichment of variaNT Associations
OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'l
Predicting effects of noncoding variants with deep learning–based sequence model | 基于深度学习的序列模型预测非编码区
我的Android进阶之旅解决:The currently selected variant “debug“ uses split APKs, but none of the 1 split...