SlideShare a Scribd company logo
1 of 27
Rate limiters in modern
software systems
Sandeep Joshi
1
CMG Pune 22nd September 2016
Permit Raj
Control systems background. Traffic shaping in networking.
Two strategies:
1. Leaky bucket : A queue with constant service time. Drops packets on overflow.
2. Token bucket : Bucket holds tokens permits are acquired before transmission. Allows
burstiness in traffic.
PID controller
Backpressure
2
Congestion control
http://ecomputernotes.com/
3
Rate Limiter features
1. Enforce long term steady state rate
2. Allow short bursts to exceed limit
3. Warm-up : Gradually increase the rate after idle period
4. Allow changing the rate at run-time
5. Handle requests based on priority (fairness).
4
Rate-limiter implementations in software
1. RocksDB
2. Facebook WDT
3. Apache Kafka
4. Apache Spark (Google Guava toolkit)
5. Akka toolkit(not covering)
6. Node.js(not covering)
7. Conclusion
5
RocksDB
Key value store which uses Log-Structured Merge (LSM) trees.
It has a rate limiter to throttle disk writes done during two different workflows.
1. Flush threads which write in-memory tree to disk.
2. Compaction thread which merges trees on disk.
Throttler requires 3 parameters
1. Refill period
2. Refill bytes per period
3. Fairness which decides which of two queues to serve first
6
RocksDB
State kept by Throttler
1. Available bytes [i.e. tokens]
2. Next refill time
3. Queue [low] and Queue[high] into which new requests inserted
Workflow
1. Inserts requests into a queue
2. Leader of the queue awakes at “next refill time” and increments available bytes.
3. Sets the next refill time = now + refill period
4. Services all requests inside the queue until available bytes is exhausted.
7
RocksDB hi priority only
8
Peaks do not
rise above
average
RocksDB with 2 priorities
9
Low priority get
delayed
RocksDB
1. Enforce long term steady state rate
2. Allow short bursts to exceed rate
3. Warm-up : Gradually increase the rate after idle period
4. Allow changing the rate at run-time
5. Service requests based on priority (fairness).
10
Facebook WDT (Warp-speed Data transfer)
http://www.github.com/facebook/wdt
Open-source library which is used for file transfer between data centers. (e.g.
transmit MySQL backups to another data center)
Both sender and receiver spawn multiple threads
All threads on sender or receiver share the same “Throttler”
Throttler limits average rate as well as peak bursts.
11
Facebook WDT
12
Allows peak bursts above
average limit specified
Facebook WDT
1. Enforce long term steady state rate
2. Allow short bursts to exceed rate
3. Warm-up : Gradually increase the rate after idle period
4. Allow changing the rate at run-time
5. Service requests based on priority (fairness).
13
Apache Kafka
http://kafka.apache.org
14
Apache Kafka
Client-based quotas to limit publisher and consumer processing.
Enforces Fixed-rate in every window
Every request is inserted into into a DelayQueue from which elements can be
retrieved only after expiry (DelayQueue is part of java concurrent library)
Delay_time = (window_size) * (observed_rate - desired_rate) / observed_rate
Allows changing quota at run-time.
15
Apache Spark
Dynamic rate limiter
Two components : Driver (master) and Receiver (accepts ingest)
1. Driver (master) uses PID-based Rate estimator to recompute the desired
rate at end of every batch
2. Driver sends new rate to Receiver
3. Receiver uses Google Guava Rate limiter to throttle block generation
16
Apache Spark
https://issues.apache.org/jira/browse/SPARK-8975
17
Apache Spark
PID Controller used in the Spark Driver to estimate best rate
1. Proportional (current): correction based on current error
2. Integral gain (past): correction based on steady-state error.
3. Derivative gain (future) : prediction based on rate of change of error
18
Apache Spark before and after
19Source : Dean Wampler, Adding Backpressure to Spark Streaming
Google Guava rate limiter
https://github.com/google/guava
Used by Receiver in Apache Spark to limit the rate
Stores expected time of next request, instead of time of previous request.
Under-utilization : It stores unused permits up to a max threshold.
Warm-up period : Stored permits are given out gradually by increasing the
sleep time.
20
Google Guava rate limiter
21
Allows peak bursts while
maintaining average limit.
Allows warmup period
Rate-limiting techniques
All transmitters call some “Throttle()” function before transmission.
Some implementations push requests into a queue, others just calculate sleep time and
decrement permits.
Retain time of next estimated wakeup instead of time of previous call.
Permits are added if new epoch is detected.
Save unused permits upto some maximum limit - this handles underutilization.
While using unused permits, increase the sleep time. This increases the warmup period.
22
Comparison of implementations
rocksdb wdt guava/spark kafka
Type Leaky bucket Token Token bucket Leaky
Enforce Average rate Y Y Y Y
Allow short bursts
exceeding average
Y Y
Warm-up after idle
period
Y
Alter rate at runtime Y Y Y Y
Priority Y 23
References
1. RocksDB : util/rate_limiter.cc
2. WDT : Throttler.cpp
3. Apache Kafka : ClientQuotaManager.scala
4. Apache Spark : PIDRateEstimator.scala, RateLimiter.scala
5. Adding Back-pressure to Spark Streaming by Dean Wampler, Typesafe
(http://files.meetup.com/1634302/Backpressure%2020160112.pdf)
6. Google Guava : RateLimiter.java and SmoothRateLimiter.java
24
Facebook WDT
If (long term rate > average)
Sleep for (ideal - elapsed) time
Else If (short term rate > peak)
Add tokens based on time difference since last call
Sleep until tokens available are positive
25
Node.js
Rate limiter packages available
https://github.com/jhurliman/node-rate-limiter
express-rate
26
Akka toolkit
Look at TimerBasedThrottler.scala
27

More Related Content

What's hot

Best Practice of Compression/Decompression Codes in Apache Spark with Sophia...
 Best Practice of Compression/Decompression Codes in Apache Spark with Sophia... Best Practice of Compression/Decompression Codes in Apache Spark with Sophia...
Best Practice of Compression/Decompression Codes in Apache Spark with Sophia...
Databricks
 

What's hot (20)

Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...
 
Battle of the Stream Processing Titans – Flink versus RisingWave
Battle of the Stream Processing Titans – Flink versus RisingWaveBattle of the Stream Processing Titans – Flink versus RisingWave
Battle of the Stream Processing Titans – Flink versus RisingWave
 
Best Practice of Compression/Decompression Codes in Apache Spark with Sophia...
 Best Practice of Compression/Decompression Codes in Apache Spark with Sophia... Best Practice of Compression/Decompression Codes in Apache Spark with Sophia...
Best Practice of Compression/Decompression Codes in Apache Spark with Sophia...
 
Scylla Compaction Strategies
Scylla Compaction StrategiesScylla Compaction Strategies
Scylla Compaction Strategies
 
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
 
Apache Flink Deep Dive
Apache Flink Deep DiveApache Flink Deep Dive
Apache Flink Deep Dive
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
 
Intro to Exadata
Intro to ExadataIntro to Exadata
Intro to Exadata
 
Flink Streaming
Flink StreamingFlink Streaming
Flink Streaming
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90mins
 
Apache Ratis - In Search of a Usable Raft Library
Apache Ratis - In Search of a Usable Raft LibraryApache Ratis - In Search of a Usable Raft Library
Apache Ratis - In Search of a Usable Raft Library
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTiger
 
Data Ingest Self Service and Management using Nifi and Kafka
Data Ingest Self Service and Management using Nifi and KafkaData Ingest Self Service and Management using Nifi and Kafka
Data Ingest Self Service and Management using Nifi and Kafka
 
Performance Tuning RocksDB for Kafka Streams’ State Stores
Performance Tuning RocksDB for Kafka Streams’ State StoresPerformance Tuning RocksDB for Kafka Streams’ State Stores
Performance Tuning RocksDB for Kafka Streams’ State Stores
 
Batch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache FlinkBatch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache Flink
 
KSQL: Streaming SQL for Kafka
KSQL: Streaming SQL for KafkaKSQL: Streaming SQL for Kafka
KSQL: Streaming SQL for Kafka
 
Spark (Structured) Streaming vs. Kafka Streams
Spark (Structured) Streaming vs. Kafka StreamsSpark (Structured) Streaming vs. Kafka Streams
Spark (Structured) Streaming vs. Kafka Streams
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise Platform
 
당근마켓에서 IaC경험
당근마켓에서 IaC경험당근마켓에서 IaC경험
당근마켓에서 IaC경험
 
NATS Streaming - an alternative to Apache Kafka?
NATS Streaming - an alternative to Apache Kafka?NATS Streaming - an alternative to Apache Kafka?
NATS Streaming - an alternative to Apache Kafka?
 

Similar to Rate limiters in big data systems

Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
webhostingguy
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
webhostingguy
 
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQCluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
Shameera Rathnayaka
 

Similar to Rate limiters in big data systems (20)

Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
 
Near Real time Indexing Kafka Messages to Apache Blur using Spark Streaming
Near Real time Indexing Kafka Messages to Apache Blur using Spark StreamingNear Real time Indexing Kafka Messages to Apache Blur using Spark Streaming
Near Real time Indexing Kafka Messages to Apache Blur using Spark Streaming
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Developing Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache KafkaDeveloping Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache Kafka
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with Nginx
 
Performance_Up.ppt
Performance_Up.pptPerformance_Up.ppt
Performance_Up.ppt
 
Big data with hadoop Setup on Ubuntu 12.04
Big data with hadoop Setup on Ubuntu 12.04Big data with hadoop Setup on Ubuntu 12.04
Big data with hadoop Setup on Ubuntu 12.04
 
Kafka Deep Dive
Kafka Deep DiveKafka Deep Dive
Kafka Deep Dive
 
What no one tells you about writing a streaming app
What no one tells you about writing a streaming appWhat no one tells you about writing a streaming app
What no one tells you about writing a streaming app
 
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
 
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQCluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Typesafe spark- Zalando meetup
Typesafe spark- Zalando meetupTypesafe spark- Zalando meetup
Typesafe spark- Zalando meetup
 
Apache httpd-2.4 : Watch out cloud!
Apache httpd-2.4 : Watch out cloud!Apache httpd-2.4 : Watch out cloud!
Apache httpd-2.4 : Watch out cloud!
 
Flexible compute
Flexible computeFlexible compute
Flexible compute
 
Sanger, upcoming Openstack for Bio-informaticians
Sanger, upcoming Openstack for Bio-informaticiansSanger, upcoming Openstack for Bio-informaticians
Sanger, upcoming Openstack for Bio-informaticians
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Trend Micro Big Data Platform and Apache Bigtop
Trend Micro Big Data Platform and Apache BigtopTrend Micro Big Data Platform and Apache Bigtop
Trend Micro Big Data Platform and Apache Bigtop
 
Zookeeper Introduce
Zookeeper IntroduceZookeeper Introduce
Zookeeper Introduce
 

More from Sandeep Joshi

More from Sandeep Joshi (11)

Block ciphers
Block ciphersBlock ciphers
Block ciphers
 
Synthetic data generation
Synthetic data generationSynthetic data generation
Synthetic data generation
 
How to build a feedback loop in software
How to build a feedback loop in softwareHow to build a feedback loop in software
How to build a feedback loop in software
 
Programming workshop
Programming workshopProgramming workshop
Programming workshop
 
Hash function landscape
Hash function landscapeHash function landscape
Hash function landscape
 
Android malware presentation
Android malware presentationAndroid malware presentation
Android malware presentation
 
Doveryai, no proveryai - Introduction to tla+
Doveryai, no proveryai - Introduction to tla+Doveryai, no proveryai - Introduction to tla+
Doveryai, no proveryai - Introduction to tla+
 
Apache spark undocumented extensions
Apache spark undocumented extensionsApache spark undocumented extensions
Apache spark undocumented extensions
 
Lockless
LocklessLockless
Lockless
 
Virtualization overheads
Virtualization overheadsVirtualization overheads
Virtualization overheads
 
Data streaming algorithms
Data streaming algorithmsData streaming algorithms
Data streaming algorithms
 

Recently uploaded

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 

Rate limiters in big data systems

  • 1. Rate limiters in modern software systems Sandeep Joshi 1 CMG Pune 22nd September 2016
  • 2. Permit Raj Control systems background. Traffic shaping in networking. Two strategies: 1. Leaky bucket : A queue with constant service time. Drops packets on overflow. 2. Token bucket : Bucket holds tokens permits are acquired before transmission. Allows burstiness in traffic. PID controller Backpressure 2
  • 4. Rate Limiter features 1. Enforce long term steady state rate 2. Allow short bursts to exceed limit 3. Warm-up : Gradually increase the rate after idle period 4. Allow changing the rate at run-time 5. Handle requests based on priority (fairness). 4
  • 5. Rate-limiter implementations in software 1. RocksDB 2. Facebook WDT 3. Apache Kafka 4. Apache Spark (Google Guava toolkit) 5. Akka toolkit(not covering) 6. Node.js(not covering) 7. Conclusion 5
  • 6. RocksDB Key value store which uses Log-Structured Merge (LSM) trees. It has a rate limiter to throttle disk writes done during two different workflows. 1. Flush threads which write in-memory tree to disk. 2. Compaction thread which merges trees on disk. Throttler requires 3 parameters 1. Refill period 2. Refill bytes per period 3. Fairness which decides which of two queues to serve first 6
  • 7. RocksDB State kept by Throttler 1. Available bytes [i.e. tokens] 2. Next refill time 3. Queue [low] and Queue[high] into which new requests inserted Workflow 1. Inserts requests into a queue 2. Leader of the queue awakes at “next refill time” and increments available bytes. 3. Sets the next refill time = now + refill period 4. Services all requests inside the queue until available bytes is exhausted. 7
  • 8. RocksDB hi priority only 8 Peaks do not rise above average
  • 9. RocksDB with 2 priorities 9 Low priority get delayed
  • 10. RocksDB 1. Enforce long term steady state rate 2. Allow short bursts to exceed rate 3. Warm-up : Gradually increase the rate after idle period 4. Allow changing the rate at run-time 5. Service requests based on priority (fairness). 10
  • 11. Facebook WDT (Warp-speed Data transfer) http://www.github.com/facebook/wdt Open-source library which is used for file transfer between data centers. (e.g. transmit MySQL backups to another data center) Both sender and receiver spawn multiple threads All threads on sender or receiver share the same “Throttler” Throttler limits average rate as well as peak bursts. 11
  • 12. Facebook WDT 12 Allows peak bursts above average limit specified
  • 13. Facebook WDT 1. Enforce long term steady state rate 2. Allow short bursts to exceed rate 3. Warm-up : Gradually increase the rate after idle period 4. Allow changing the rate at run-time 5. Service requests based on priority (fairness). 13
  • 15. Apache Kafka Client-based quotas to limit publisher and consumer processing. Enforces Fixed-rate in every window Every request is inserted into into a DelayQueue from which elements can be retrieved only after expiry (DelayQueue is part of java concurrent library) Delay_time = (window_size) * (observed_rate - desired_rate) / observed_rate Allows changing quota at run-time. 15
  • 16. Apache Spark Dynamic rate limiter Two components : Driver (master) and Receiver (accepts ingest) 1. Driver (master) uses PID-based Rate estimator to recompute the desired rate at end of every batch 2. Driver sends new rate to Receiver 3. Receiver uses Google Guava Rate limiter to throttle block generation 16
  • 18. Apache Spark PID Controller used in the Spark Driver to estimate best rate 1. Proportional (current): correction based on current error 2. Integral gain (past): correction based on steady-state error. 3. Derivative gain (future) : prediction based on rate of change of error 18
  • 19. Apache Spark before and after 19Source : Dean Wampler, Adding Backpressure to Spark Streaming
  • 20. Google Guava rate limiter https://github.com/google/guava Used by Receiver in Apache Spark to limit the rate Stores expected time of next request, instead of time of previous request. Under-utilization : It stores unused permits up to a max threshold. Warm-up period : Stored permits are given out gradually by increasing the sleep time. 20
  • 21. Google Guava rate limiter 21 Allows peak bursts while maintaining average limit. Allows warmup period
  • 22. Rate-limiting techniques All transmitters call some “Throttle()” function before transmission. Some implementations push requests into a queue, others just calculate sleep time and decrement permits. Retain time of next estimated wakeup instead of time of previous call. Permits are added if new epoch is detected. Save unused permits upto some maximum limit - this handles underutilization. While using unused permits, increase the sleep time. This increases the warmup period. 22
  • 23. Comparison of implementations rocksdb wdt guava/spark kafka Type Leaky bucket Token Token bucket Leaky Enforce Average rate Y Y Y Y Allow short bursts exceeding average Y Y Warm-up after idle period Y Alter rate at runtime Y Y Y Y Priority Y 23
  • 24. References 1. RocksDB : util/rate_limiter.cc 2. WDT : Throttler.cpp 3. Apache Kafka : ClientQuotaManager.scala 4. Apache Spark : PIDRateEstimator.scala, RateLimiter.scala 5. Adding Back-pressure to Spark Streaming by Dean Wampler, Typesafe (http://files.meetup.com/1634302/Backpressure%2020160112.pdf) 6. Google Guava : RateLimiter.java and SmoothRateLimiter.java 24
  • 25. Facebook WDT If (long term rate > average) Sleep for (ideal - elapsed) time Else If (short term rate > peak) Add tokens based on time difference since last call Sleep until tokens available are positive 25
  • 26. Node.js Rate limiter packages available https://github.com/jhurliman/node-rate-limiter express-rate 26
  • 27. Akka toolkit Look at TimerBasedThrottler.scala 27