Mercurial > hg > nginx
comparison src/http/modules/ngx_http_limit_req_module.c @ 6653:7a6456398fc3
Simplified extraction of current time.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 08 Aug 2016 17:11:29 +0300 |
parents | 3b7a60371a9a |
children | 7fcf209d40c8 |
comparison
equal
deleted
inserted
replaced
6652:1891b2892b68 | 6653:7a6456398fc3 |
---|---|
360 ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash, | 360 ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash, |
361 ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account) | 361 ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account) |
362 { | 362 { |
363 size_t size; | 363 size_t size; |
364 ngx_int_t rc, excess; | 364 ngx_int_t rc, excess; |
365 ngx_time_t *tp; | |
366 ngx_msec_t now; | 365 ngx_msec_t now; |
367 ngx_msec_int_t ms; | 366 ngx_msec_int_t ms; |
368 ngx_rbtree_node_t *node, *sentinel; | 367 ngx_rbtree_node_t *node, *sentinel; |
369 ngx_http_limit_req_ctx_t *ctx; | 368 ngx_http_limit_req_ctx_t *ctx; |
370 ngx_http_limit_req_node_t *lr; | 369 ngx_http_limit_req_node_t *lr; |
371 | 370 |
372 tp = ngx_timeofday(); | 371 now = ngx_current_msec; |
373 now = (ngx_msec_t) (tp->sec * 1000 + tp->msec); | |
374 | 372 |
375 ctx = limit->shm_zone->data; | 373 ctx = limit->shm_zone->data; |
376 | 374 |
377 node = ctx->sh->rbtree.root; | 375 node = ctx->sh->rbtree.root; |
378 sentinel = ctx->sh->rbtree.sentinel; | 376 sentinel = ctx->sh->rbtree.sentinel; |
481 static ngx_msec_t | 479 static ngx_msec_t |
482 ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits, ngx_uint_t n, | 480 ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits, ngx_uint_t n, |
483 ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit) | 481 ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit) |
484 { | 482 { |
485 ngx_int_t excess; | 483 ngx_int_t excess; |
486 ngx_time_t *tp; | |
487 ngx_msec_t now, delay, max_delay; | 484 ngx_msec_t now, delay, max_delay; |
488 ngx_msec_int_t ms; | 485 ngx_msec_int_t ms; |
489 ngx_http_limit_req_ctx_t *ctx; | 486 ngx_http_limit_req_ctx_t *ctx; |
490 ngx_http_limit_req_node_t *lr; | 487 ngx_http_limit_req_node_t *lr; |
491 | 488 |
507 continue; | 504 continue; |
508 } | 505 } |
509 | 506 |
510 ngx_shmtx_lock(&ctx->shpool->mutex); | 507 ngx_shmtx_lock(&ctx->shpool->mutex); |
511 | 508 |
512 tp = ngx_timeofday(); | 509 now = ngx_current_msec; |
513 | |
514 now = (ngx_msec_t) (tp->sec * 1000 + tp->msec); | |
515 ms = (ngx_msec_int_t) (now - lr->last); | 510 ms = (ngx_msec_int_t) (now - lr->last); |
516 | 511 |
517 excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000; | 512 excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000; |
518 | 513 |
519 if (excess < 0) { | 514 if (excess < 0) { |
547 | 542 |
548 static void | 543 static void |
549 ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, ngx_uint_t n) | 544 ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, ngx_uint_t n) |
550 { | 545 { |
551 ngx_int_t excess; | 546 ngx_int_t excess; |
552 ngx_time_t *tp; | |
553 ngx_msec_t now; | 547 ngx_msec_t now; |
554 ngx_queue_t *q; | 548 ngx_queue_t *q; |
555 ngx_msec_int_t ms; | 549 ngx_msec_int_t ms; |
556 ngx_rbtree_node_t *node; | 550 ngx_rbtree_node_t *node; |
557 ngx_http_limit_req_node_t *lr; | 551 ngx_http_limit_req_node_t *lr; |
558 | 552 |
559 tp = ngx_timeofday(); | 553 now = ngx_current_msec; |
560 | |
561 now = (ngx_msec_t) (tp->sec * 1000 + tp->msec); | |
562 | 554 |
563 /* | 555 /* |
564 * n == 1 deletes one or two zero rate entries | 556 * n == 1 deletes one or two zero rate entries |
565 * n == 0 deletes oldest entry by force | 557 * n == 0 deletes oldest entry by force |
566 * and one or two zero rate entries | 558 * and one or two zero rate entries |