2013-02-14 7 views
6

Dire ho impostatoNginx # ngx_http_limit_req_module: per quanto tempo viene restituito 503 una volta superato il tasso?

limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; 

server { 
    location/{ 
     limit_req zone=one burst=5 nodelay; 
    } 

Poi per 5 secondi, mando 10 richieste al secondo.

Quale richiesta dovrebbe vedere un 200 e quale dovrebbe vedere un 503?
Sarebbe la prima di ogni 10 richieste?

o fa nginx tenere traccia di utenti cattivi inviano continuamente richieste, e in questo caso solo il primo dei 50 requets otterrebbe un 200?

risposta

9

Come indicato nella documentazione: http://nginx.org/en/docs/http/ngx_http_limit_req_module.html nginx utilizza l'algoritmo "leaky bucket" che è semplice e piuttosto comune nell'area di rete. Si può leggere su su wikipedia: http://en.wikipedia.org/wiki/Leaky_bucket

Per quanto riguarda la tua domanda (rate=1r/s burst=5 nodelay), in pratica, sarebbe qualcosa di simile:

 
Req.# | Time (sec) | Response 
    1   0   200 OK 
    2  0.1   200 OK 
    3  0.2   200 OK 
    4  0.3   200 OK 
    5  0.4   200 OK 
    6  0.5   200 OK 
    7  0.6   503 
    8  0.7   503 
    9  0.8   503 
    10  0.9   503 
    11  1.0   200 OK 
    12  1.1   503 
    13  1.2   503 
    14  1.3   503 
    15  1.4   503 
    16  1.5   503 
    17  1.6   503 
    18  1.7   503 
    19  1.8   503 
    20  1.9   503 
    21  2.0   200 OK 
    22  2.1   503 
    23  2.2   503 
    24  2.3   503 
    25  2.4   503 
    26  2.5   503 
    27  2.6   503 
    28  2.7   503 
    29  2.8   503 
    30  2.9   503 
    31  3.0   200 OK 
    32  3.1   503 
    33  3.2   503 
    34  3.3   503 
    35  3.4   503 
    36  3.5   503 
    37  3.6   503 
    38  3.7   503 
    39  3.8   503 
    40  3.9   503 
    41  4.0   200 OK 
    42  4.1   503 
    43  4.2   503 
    44  4.3   503 
    45  4.4   503 
    46  4.5   503 
    47  4.6   503 
    48  4.7   503 
    49  4.8   503 
    50  4.9   503 
+0

ho pensato che il 'burst' era priva di significato se la' nodelay' era impostato. Ho capito male? – oldergod

+0

Non è privo di significato. 'burst' definisce il numero di richieste che un client può eseguire in eccesso rispetto a un determinato' rate'. In termini di algoritmo leaky bucket è la capacità del bucket. – VBart

+0

'nodelay' solo definisce queste richieste eccessive ritardate o meno. – VBart

Problemi correlati