m*t
4 楼
不是大牛,随便说两句
rate limiter,不管是哪里的,都围绕一个核心,就是limiter
数据结构上,必须设置threshold
功能上,必须设置flow control和traffic management,prevent traffic jam
还有相关的设置,比如monitoring,time interval
既然是limiter,你要guarantee每时每刻进行纠错处理,比如amount突然增加,就可以
进行routine alerts
而不能等到已经overly,才开始修复,那样效率在平均每秒上大大减低
所以,还要有个efficiency estimation和experimental的instant dual data
【在 p*****2 的大作中提到】
: 大牛说说一般怎么设计
rate limiter,不管是哪里的,都围绕一个核心,就是limiter
数据结构上,必须设置threshold
功能上,必须设置flow control和traffic management,prevent traffic jam
还有相关的设置,比如monitoring,time interval
既然是limiter,你要guarantee每时每刻进行纠错处理,比如amount突然增加,就可以
进行routine alerts
而不能等到已经overly,才开始修复,那样效率在平均每秒上大大减低
所以,还要有个efficiency estimation和experimental的instant dual data
【在 p*****2 的大作中提到】
: 大牛说说一般怎么设计
p*2
5 楼
你说的更像是需求
具体应该怎么设计呢?
比如你提到数据结构 但是到底应该用什么数据结构呢
【在 m********t 的大作中提到】
: 不是大牛,随便说两句
: rate limiter,不管是哪里的,都围绕一个核心,就是limiter
: 数据结构上,必须设置threshold
: 功能上,必须设置flow control和traffic management,prevent traffic jam
: 还有相关的设置,比如monitoring,time interval
: 既然是limiter,你要guarantee每时每刻进行纠错处理,比如amount突然增加,就可以
: 进行routine alerts
: 而不能等到已经overly,才开始修复,那样效率在平均每秒上大大减低
: 所以,还要有个efficiency estimation和experimental的instant dual data
具体应该怎么设计呢?
比如你提到数据结构 但是到底应该用什么数据结构呢
【在 m********t 的大作中提到】
: 不是大牛,随便说两句
: rate limiter,不管是哪里的,都围绕一个核心,就是limiter
: 数据结构上,必须设置threshold
: 功能上,必须设置flow control和traffic management,prevent traffic jam
: 还有相关的设置,比如monitoring,time interval
: 既然是limiter,你要guarantee每时每刻进行纠错处理,比如amount突然增加,就可以
: 进行routine alerts
: 而不能等到已经overly,才开始修复,那样效率在平均每秒上大大减低
: 所以,还要有个efficiency estimation和experimental的instant dual data
m*t
6 楼
所以 最初的prototype的functions大概建立如下:
核心是prevent reaching to limit:
alerts
maintenance
monitoring
efficiency
flow detection
flow control
instant repair
threshold detection
其他相关的数据结构围绕相应的数据采集,就很好设置了
这只是我眼下能想得到的,估计也不是很对。。。
核心是prevent reaching to limit:
alerts
maintenance
monitoring
efficiency
flow detection
flow control
instant repair
threshold detection
其他相关的数据结构围绕相应的数据采集,就很好设置了
这只是我眼下能想得到的,估计也不是很对。。。
q*c
7 楼
这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
void RateLimit() {
int minInterval = 1000/N; // N is the max rate
int current = now();
int diff = current-last;
last = current; //last would be a class private member
if(diff < minInterval) {
Thread.sleep(diff);
return ;
}
else
return ;
}
【在 r*******h 的大作中提到】
: 要求设计一个Rate Limiter。突然想起来了,供大家讨论一下吧。
void RateLimit() {
int minInterval = 1000/N; // N is the max rate
int current = now();
int diff = current-last;
last = current; //last would be a class private member
if(diff < minInterval) {
Thread.sleep(diff);
return ;
}
else
return ;
}
【在 r*******h 的大作中提到】
: 要求设计一个Rate Limiter。突然想起来了,供大家讨论一下吧。
p*2
8 楼
你这个貌似跟月光是两个极端呀
了。
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
了。
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
m*t
9 楼
这么简单? 我考虑问题总是前前后后都想个遍。。。
凭我直觉,面试的出发点是考量你的设计思路和循序渐进的一个逻辑过程
我甚至都不认为coding在这里算是重点了
project最开始的核心定位和相应参数的设置,极为关键,这个跟盖楼打地基是一样的
crucial
一开始没定位好地基的模型,后来的人没法跟,也就是上面的floors就很难reliable打
下去了
会出现半途而废,然后重头开始的低效
不过,可能你是对的,我也就是瞎说自己的感觉
了。
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
凭我直觉,面试的出发点是考量你的设计思路和循序渐进的一个逻辑过程
我甚至都不认为coding在这里算是重点了
project最开始的核心定位和相应参数的设置,极为关键,这个跟盖楼打地基是一样的
crucial
一开始没定位好地基的模型,后来的人没法跟,也就是上面的floors就很难reliable打
下去了
会出现半途而废,然后重头开始的低效
不过,可能你是对的,我也就是瞎说自己的感觉
了。
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
m*t
18 楼
现在,眼下这个时代,rate limit都要走load balancing路线,只不过方法不同,要么
并行多几条virtual lanes,要么是按时间去做queuing, 只有这样才可以避免各种
collision的发生,这只是理想状态,而真实状态,这样也还出现很多故障。
你就把这道题当成高速上的limit去考虑就行了,真到了塞车或撞车的时候,已经太晚
了,人均的前进效率也就是流量其实是很低的, 所以提前的各项措施,很有必要
这个题目我估计是跟google cloud data center的资源分布有点关系。
瞎猜的啊,不一定对
【在 N*****m 的大作中提到】
: 单就一个rate就没说清楚
: 一个机器的rate,一个系统的rate,一个account跨区的rate;
: 再说什么rate?流量,CPU,内存还是硬盘?
: 然后怎么limit?hard limit还是soft?
: 任何一个组合就是一种solution,这个题目啥都没说,设计个头。
并行多几条virtual lanes,要么是按时间去做queuing, 只有这样才可以避免各种
collision的发生,这只是理想状态,而真实状态,这样也还出现很多故障。
你就把这道题当成高速上的limit去考虑就行了,真到了塞车或撞车的时候,已经太晚
了,人均的前进效率也就是流量其实是很低的, 所以提前的各项措施,很有必要
这个题目我估计是跟google cloud data center的资源分布有点关系。
瞎猜的啊,不一定对
【在 N*****m 的大作中提到】
: 单就一个rate就没说清楚
: 一个机器的rate,一个系统的rate,一个account跨区的rate;
: 再说什么rate?流量,CPU,内存还是硬盘?
: 然后怎么limit?hard limit还是soft?
: 任何一个组合就是一种solution,这个题目啥都没说,设计个头。
y*a
21 楼
我在 Guava 里面找到了一个叫 Ratelimiter 的类。
干的是类似 lock 的事情。有点像 Semaphore,不过不是控制 Thread 的数量,
而是控制一段时间里面的流量。
干的是类似 lock 的事情。有点像 Semaphore,不过不是控制 Thread 的数量,
而是控制一段时间里面的流量。
m*t
22 楼
你还真的去找外面资料了?这里的题目,我从来没翻过书或者google过
既然是面试题目,这个前提就是你不能在现场找书和找笔记了吧?
我是根据自己对rate和limit的应用的理解来回答的,错了也没关系了
问题是,这道题你能找到,再给一道你没见过的,比如写一个电表监视的系统,那不还
是不会吗?
其实,面试是考察你的思维效率,这东西是平时长期潜移默化的training,不是一夜之
间就突飞猛进的
【在 y**********a 的大作中提到】
: 我在 Guava 里面找到了一个叫 Ratelimiter 的类。
: 干的是类似 lock 的事情。有点像 Semaphore,不过不是控制 Thread 的数量,
: 而是控制一段时间里面的流量。
既然是面试题目,这个前提就是你不能在现场找书和找笔记了吧?
我是根据自己对rate和limit的应用的理解来回答的,错了也没关系了
问题是,这道题你能找到,再给一道你没见过的,比如写一个电表监视的系统,那不还
是不会吗?
其实,面试是考察你的思维效率,这东西是平时长期潜移默化的training,不是一夜之
间就突飞猛进的
【在 y**********a 的大作中提到】
: 我在 Guava 里面找到了一个叫 Ratelimiter 的类。
: 干的是类似 lock 的事情。有点像 Semaphore,不过不是控制 Thread 的数量,
: 而是控制一段时间里面的流量。
p*y
24 楼
用sleep不妥
了。
"" ;="" :="" ...................="">
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
了。
"" ;="" :="" ...................="">
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
p*y
25 楼
貌似多了很多assumptions
【在 m********t 的大作中提到】
: 不是大牛,随便说两句
: rate limiter,不管是哪里的,都围绕一个核心,就是limiter
: 数据结构上,必须设置threshold
: 功能上,必须设置flow control和traffic management,prevent traffic jam
: 还有相关的设置,比如monitoring,time interval
: 既然是limiter,你要guarantee每时每刻进行纠错处理,比如amount突然增加,就可以
: 进行routine alerts
: 而不能等到已经overly,才开始修复,那样效率在平均每秒上大大减低
: 所以,还要有个efficiency estimation和experimental的instant dual data
【在 m********t 的大作中提到】
: 不是大牛,随便说两句
: rate limiter,不管是哪里的,都围绕一个核心,就是limiter
: 数据结构上,必须设置threshold
: 功能上,必须设置flow control和traffic management,prevent traffic jam
: 还有相关的设置,比如monitoring,time interval
: 既然是limiter,你要guarantee每时每刻进行纠错处理,比如amount突然增加,就可以
: 进行routine alerts
: 而不能等到已经overly,才开始修复,那样效率在平均每秒上大大减低
: 所以,还要有个efficiency estimation和experimental的instant dual data
m*k
28 楼
Thread.sleep(minInterval - diff); 吧?
了。
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
了。
【在 q********c 的大作中提到】
: 这是我的口德. 基本原理就这样,再讨论一下scalability, concurrency, 就差不多了。
: void RateLimit() {
: int minInterval = 1000/N; // N is the max rate
:
: int current = now();
: int diff = current-last;
: last = current; //last would be a class private member
: if(diff < minInterval) {
: Thread.sleep(diff);
: return ;
C*n
31 楼
public double acquire()
Acquires a single permit from this RateLimiter, blocking until the request
can be granted. Tells the amount of time slept, if any.
This method is equivalent to acquire(1).
Returns:
time spent sleeping to enforce rate, in seconds; 0.0 if not rate-limited
【在 p*****2 的大作中提到】
: sleep是线程阻塞的吧 除非用go
Acquires a single permit from this RateLimiter, blocking until the request
can be granted. Tells the amount of time slept, if any.
This method is equivalent to acquire(1).
Returns:
time spent sleeping to enforce rate, in seconds; 0.0 if not rate-limited
【在 p*****2 的大作中提到】
: sleep是线程阻塞的吧 除非用go
p*2
32 楼
并发性太差了
limited
【在 C*******n 的大作中提到】
: public double acquire()
: Acquires a single permit from this RateLimiter, blocking until the request
: can be granted. Tells the amount of time slept, if any.
: This method is equivalent to acquire(1).
: Returns:
: time spent sleeping to enforce rate, in seconds; 0.0 if not rate-limited
limited
【在 C*******n 的大作中提到】
: public double acquire()
: Acquires a single permit from this RateLimiter, blocking until the request
: can be granted. Tells the amount of time slept, if any.
: This method is equivalent to acquire(1).
: Returns:
: time spent sleeping to enforce rate, in seconds; 0.0 if not rate-limited
M*a
36 楼
仅仅限制间隔时间应该太简化了
应该是要考虑burst的情况的。
感觉这个题目更哪个什么过去一分钟一小时一天的request数量的题目有关系。
就是给定一段固定的时间控制这段时间里面最大可能的request数量。
如果要精确解就要保持一个request queue,不要精确解就把固定一段时间分成比如100
份记录每份时间里面的request数量。
应该是要考虑burst的情况的。
感觉这个题目更哪个什么过去一分钟一小时一天的request数量的题目有关系。
就是给定一段固定的时间控制这段时间里面最大可能的request数量。
如果要精确解就要保持一个request queue,不要精确解就把固定一段时间分成比如100
份记录每份时间里面的request数量。
g*e
38 楼
终极答案 http://en.wikipedia.org/wiki/Token_bucket
AWS不同的产品throttling的实现有差别,不过基本都是基于上面这个。所以说,本科
学的网络通信还是有用的啊...
【在 p*****2 的大作中提到】
: 好 多谢大牛
:
: limit
AWS不同的产品throttling的实现有差别,不过基本都是基于上面这个。所以说,本科
学的网络通信还是有用的啊...
【在 p*****2 的大作中提到】
: 好 多谢大牛
:
: limit
p*2
39 楼
先顶后看
【在 g**e 的大作中提到】
: 终极答案 http://en.wikipedia.org/wiki/Token_bucket
: AWS不同的产品throttling的实现有差别,不过基本都是基于上面这个。所以说,本科
: 学的网络通信还是有用的啊...
【在 g**e 的大作中提到】
: 终极答案 http://en.wikipedia.org/wiki/Token_bucket
: AWS不同的产品throttling的实现有差别,不过基本都是基于上面这个。所以说,本科
: 学的网络通信还是有用的啊...
相关阅读
关于FOLLOW UP LETTER有没有人面过CITCO FUND SERVICE请教~收到on-site interview邀请,但是不给报销路费和旅馆~Mid-west (st. paul) 的75K V.S. 加州 的10K 选那个?一个CS面试题: 一个骰子最多掷三次,求最佳策略cisco 刚收购的中小型公司该去吗?考大家一道SQL面试题硅谷6万人公司招人对USCIS无语了(呼唤满老,urgent)。。。教育专业求指点OPT没有做满20小时/星期,又何后果???about novatis不知史上最快OPT有多快,报个自己case!唯一的onsite下周该出结果了,倾尽腰包求保佑!Chase力作 信用卡首笔消费就送25000miles(无金额限制)求助,salary information是什么意思?从美国找香港的工作也散家财,也求祝福今天露马脚了请教一个问题,发两个包子。