电商课题I:集群环境下业务限流
@郑昀汇总?
创建日期:20120925
????????????????????????????????????????????????????????????????????实现:Rate limiting with memcached代码实现:https://github.com/simonw/ratelimitcache/blob/master/ratelimitcache.py 它明确提出了防字典攻击防扫号的目的。既可限制住ip,也可限制住其他字段如 username 。?var RateLimiter = require('limiter').RateLimiter;// Allow 150 requests per hour (the Twitter search limit). Also understands// 'second', 'minute', 'day', or a number of millisecondsvar limiter = new RateLimiter(150, 'hour');// Throttle requestslimiter.removeTokens(1, function(err, remainingRequests) { // err will only be set if we request more than the maximum number of // requests we set in the constructor // remainingRequests tells us how many additional requests could be sent // right this moment callMyRequestSendingFunction(...);});What’s a good rate limiting algorithm?Best way to implement request throttling in ASP.NET MVC?var BURST_RATE = 1024 * 1024 * 150; // 150KB/sec burst ratevar FILL_RATE = 1024 * 1024 * 50; // 50KB/sec sustained ratevar TokenBucket = require('limiter').TokenBucket;// We could also pass a parent token bucket in as the last parameter to// create a hierarchical token bucketvar bucket = new TokenBucket(BURST_RATE, FILL_RATE, 'second', null);bucket.removeTokens(myData.byteLength, function() { sendMyData(myData);});