T086ѧϰ�� | վ��ѧԺ | �����ĵ� | ���� | Ъ���� | IP��ַ��ѯ | �������� | ���ջ��� | �����ֵ� | ���ù��� | ������Ϣ��ѯ

nginx limit_req��������

�� ���ߣ�hemono ����ʱ�䣺2013-04-04 | ���壺�� �� С��
[����]WIKI��http://wiki.nginx.org/HttpLimitReqModule©Ͱԭ����leaky bucket����http://en.wikipedia.org/wiki/Leaky_bucket#���û�������IP��ַ����������©Ͱ����������1-3req/sec��Ͱ�ռ�1m��1M�ܱ��ִ�Լ16000��(IP...

WIKI��

http://wiki.nginx.org/HttpLimitReqModule

©Ͱԭ����leaky bucket����

http://en.wikipedia.org/wiki/Leaky_bucket

#���û�������IP��ַ����������©Ͱ����������1-3req/sec��Ͱ�ռ�1m��1M�ܱ��ִ�Լ16000��(IP)״̬
limit_req_zone  $binary_remote_addr  zone=qps1:1m   rate=1r/s;
limit_req_zone  $binary_remote_addr  zone=qps2:1m   rate=2r/s;
limit_req_zone  $binary_remote_addr  zone=qps3:1m   rate=3r/s;

server {

#����qps=1����ֵburst=5���ӳ�����
#�ϸ�����©Ͱ����qps=1����ÿ������
#�ڷ�ֵburst=5���ڵIJ������󣬻ᱻ�������ӳٴ���
#����������������ֱ�ӷ���503
#�ͻ���ֻҪ���Ʋ����ڷ�ֵ[burst]�ڣ��Ͳ��ᴥ��limit_req_error_log
# ��1������һ����������=6���ܾ�1��������1���������ӳٶ���4����
#time    request    refuse    sucess    delay
#00:01        6        1        1            4
#00:02        0        0        1            3
#00:03        0        0        1            2
#00:04        0        0        1            1
#00:05        0        0        1            0
location /delay {
    limit_req   zone=qps1  burst=5;
}

#����qps=1����ֵburst=5�����ӳ�����
#����nodelay֮����©Ͱ����һ��ʱ���ڵ�ƽ��qps = ©Ͱ���ʣ�����˲ʱ�ķ�ֵqps > ©Ͱqps
#���Է�ֵʱ������qps=(brust+qps-1)=5
#���󲻻ᱻdelay��Ҫô������Ҫôֱ�ӷ���503
#�ͻ�����Ҫ����qpsÿ�����������Ų��ᴥ��limit_req_error_log
# ��2��ÿ��5�뷢��һ�δﵽ��ֵ�IJ�������������ʱ������ƽ��qps=1 ������Ȼ����©Ͱ���ʣ�
#time    request     refuse    sucess
#00:01         5         0          5
#00:05         5         0          5
#00:10         5         0          5
# ��3������ÿ�뷢�𲢷�����=5������ʱ������ƽ��qps>>1�����������󱻾ܾ���
#time    request     refuse     sucess
#00:01         5         0           5
#00:02         5         4           1
#00:03         5         4           1

location /nodelay {
    limit_req   zone=qps1  burst=5 nodelay;
}

}

ԭ�ģ�http://www.hemono.com/?p=673

  • ת����ע����Դ��ITѧϰ�� ��ַ��http://www.t086.com/ �����������Ƽ�������
  • �ر������� ��վ�������ر�������ֹת�ص�ר�������������¿�������ת�أ���������ע��������ԭʼ���ߡ����°�Ȩ������ԭʼ�������С����ڱ���վת�����µĸ��˺���վ�����DZ�ʾ������л�⡣������վת�ص������а�Ȩ��������ϵ���ǣ����ǻᾡ�����Ը�����
������ѯ Health Check Gulangyu
© 2017 T086ѧϰ�� - T086.com(ԭitlearner.com)
RunTime:13.26ms QueryTime:7