Mercurial > hg > nginx
comparison src/http/ngx_http_file_cache.c @ 6063:d698c300b9ff
Cache: added support for reading of the header in thread pools.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 01 Apr 2015 03:49:17 +0300 |
parents | 1fdba317ee6d |
children | 4821fc788c12 |
comparison
equal
deleted
inserted
replaced
6062:173561dfd567 | 6063:d698c300b9ff |
---|---|
20 ngx_http_cache_t *c); | 20 ngx_http_cache_t *c); |
21 static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r, | 21 static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r, |
22 ngx_http_cache_t *c); | 22 ngx_http_cache_t *c); |
23 #if (NGX_HAVE_FILE_AIO) | 23 #if (NGX_HAVE_FILE_AIO) |
24 static void ngx_http_cache_aio_event_handler(ngx_event_t *ev); | 24 static void ngx_http_cache_aio_event_handler(ngx_event_t *ev); |
25 #endif | |
26 #if (NGX_THREADS) | |
27 static ngx_int_t ngx_http_cache_thread_handler(ngx_thread_task_t *task, | |
28 ngx_file_t *file); | |
29 static void ngx_http_cache_thread_event_handler(ngx_event_t *ev); | |
25 #endif | 30 #endif |
26 static ngx_int_t ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, | 31 static ngx_int_t ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, |
27 ngx_http_cache_t *c); | 32 ngx_http_cache_t *c); |
28 static ngx_int_t ngx_http_file_cache_name(ngx_http_request_t *r, | 33 static ngx_int_t ngx_http_file_cache_name(ngx_http_request_t *r, |
29 ngx_path_t *path); | 34 ngx_path_t *path); |
634 | 639 |
635 | 640 |
636 static ssize_t | 641 static ssize_t |
637 ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c) | 642 ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c) |
638 { | 643 { |
639 #if (NGX_HAVE_FILE_AIO) | 644 #if (NGX_HAVE_FILE_AIO || NGX_THREADS) |
640 ssize_t n; | 645 ssize_t n; |
641 ngx_http_core_loc_conf_t *clcf; | 646 ngx_http_core_loc_conf_t *clcf; |
642 | 647 |
643 if (!ngx_file_aio) { | |
644 goto noaio; | |
645 } | |
646 | |
647 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 648 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
648 | 649 #endif |
649 if (clcf->aio != NGX_HTTP_AIO_ON) { | 650 |
650 goto noaio; | 651 #if (NGX_HAVE_FILE_AIO) |
651 } | 652 |
652 | 653 if (clcf->aio == NGX_HTTP_AIO_ON && ngx_file_aio) { |
653 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool); | 654 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool); |
654 | 655 |
655 if (n != NGX_AGAIN) { | 656 if (n != NGX_AGAIN) { |
656 c->reading = 0; | 657 c->reading = 0; |
658 return n; | |
659 } | |
660 | |
661 c->reading = 1; | |
662 | |
663 c->file.aio->data = r; | |
664 c->file.aio->handler = ngx_http_cache_aio_event_handler; | |
665 | |
666 r->main->blocked++; | |
667 r->aio = 1; | |
668 | |
669 return NGX_AGAIN; | |
670 } | |
671 | |
672 #endif | |
673 | |
674 #if (NGX_THREADS) | |
675 | |
676 if (clcf->aio == NGX_HTTP_AIO_THREADS) { | |
677 c->file.thread_handler = ngx_http_cache_thread_handler; | |
678 c->file.thread_ctx = r; | |
679 | |
680 n = ngx_thread_read(&c->thread_task, &c->file, c->buf->pos, | |
681 c->body_start, 0, r->pool); | |
682 | |
683 c->reading = (n == NGX_AGAIN); | |
684 | |
657 return n; | 685 return n; |
658 } | 686 } |
659 | |
660 c->reading = 1; | |
661 | |
662 c->file.aio->data = r; | |
663 c->file.aio->handler = ngx_http_cache_aio_event_handler; | |
664 | |
665 r->main->blocked++; | |
666 r->aio = 1; | |
667 | |
668 return NGX_AGAIN; | |
669 | |
670 noaio: | |
671 | 687 |
672 #endif | 688 #endif |
673 | 689 |
674 return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0); | 690 return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0); |
675 } | 691 } |
690 | 706 |
691 ngx_http_set_log_request(c->log, r); | 707 ngx_http_set_log_request(c->log, r); |
692 | 708 |
693 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | 709 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
694 "http file cache aio: \"%V?%V\"", &r->uri, &r->args); | 710 "http file cache aio: \"%V?%V\"", &r->uri, &r->args); |
711 | |
712 r->main->blocked--; | |
713 r->aio = 0; | |
714 | |
715 r->write_event_handler(r); | |
716 | |
717 ngx_http_run_posted_requests(c); | |
718 } | |
719 | |
720 #endif | |
721 | |
722 | |
723 #if (NGX_THREADS) | |
724 | |
725 static ngx_int_t | |
726 ngx_http_cache_thread_handler(ngx_thread_task_t *task, ngx_file_t *file) | |
727 { | |
728 ngx_str_t name; | |
729 ngx_thread_pool_t *tp; | |
730 ngx_http_request_t *r; | |
731 ngx_http_core_loc_conf_t *clcf; | |
732 | |
733 r = file->thread_ctx; | |
734 | |
735 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
736 tp = clcf->thread_pool; | |
737 | |
738 if (tp == NULL) { | |
739 if (ngx_http_complex_value(r, clcf->thread_pool_value, &name) | |
740 != NGX_OK) | |
741 { | |
742 return NGX_ERROR; | |
743 } | |
744 | |
745 tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name); | |
746 | |
747 if (tp == NULL) { | |
748 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
749 "thread pool \"%V\" not found", &name); | |
750 return NGX_ERROR; | |
751 } | |
752 } | |
753 | |
754 task->event.data = r; | |
755 task->event.handler = ngx_http_cache_thread_event_handler; | |
756 | |
757 if (ngx_thread_task_post(tp, task) != NGX_OK) { | |
758 return NGX_ERROR; | |
759 } | |
760 | |
761 r->main->blocked++; | |
762 r->aio = 1; | |
763 | |
764 return NGX_OK; | |
765 } | |
766 | |
767 | |
768 static void | |
769 ngx_http_cache_thread_event_handler(ngx_event_t *ev) | |
770 { | |
771 ngx_connection_t *c; | |
772 ngx_http_request_t *r; | |
773 | |
774 r = ev->data; | |
775 c = r->connection; | |
776 | |
777 ngx_http_set_log_request(c->log, r); | |
778 | |
779 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
780 "http file cache thread: \"%V?%V\"", &r->uri, &r->args); | |
695 | 781 |
696 r->main->blocked--; | 782 r->main->blocked--; |
697 r->aio = 0; | 783 r->aio = 0; |
698 | 784 |
699 r->write_event_handler(r); | 785 r->write_event_handler(r); |