Welcome! Log In Create A New Profile

Advanced

Adding tests for handlers and filters

Marcus Clyne
August 13, 2009 06:05PM
Hi,

Would it not be a good idea to add tests at conf-read time to see if
headers/filters need to be added into the source code to avoid the
unnecessary overhead of checking whether they need to be used or not at
runtime?

For example, the SSI module. The filter is automatically added to the
list in:

static ngx_int_t
ngx_http_ssi_filter_init(ngx_conf_t *cf)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_ssi_header_filter;

ngx_http_next_body_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_ssi_body_filter;

return NGX_OK;
}

I believe a better implementation would include a variable (it might as
well be global) to test whether the filter needs to be installed, e.g.

ngx_int_t http_ssi_filter_use = 0;
...
[NEW FUNCTION - replacing the use of ngx_conf_set_flag_slot for
directive 'ssi']
static char*
ngx_http_ssi (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
// test for on/off (like ngx_conf_set_flag_slot)
http_ssi_filter_use = 1;
return NGX_CONF_OK;
}

static ngx_int_t
ngx_http_ssi_filter_init (ngx_conf_t *cf)
{
if (http_ssi_filter_use) {
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_ssi_header_filter;

ngx_http_next_body_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_ssi_body_filter;
}

return NGX_OK;
}


Doing this for all the modules, including headers and footers (if it's
not already done) I think would make a difference in speed. Some
modules wouldn't need creating a new function, just adding the
http_[module]_use = 1 to an existing conf function, and the tests for
adding handlers / filters.

Most configurations probably do not use that many handlers / filters,
and by eliminating all the additional function pointer calls, checks and
returns could add a little performance increase to the server as a
whole, and would not affect the functionality of the server in any way.

Cheers,

Marcus.
Subject Author Posted

index or try_files in reverse proxy

meto August 12, 2009 03:27PM

Re: index or try_files in reverse proxy

meto August 12, 2009 07:47PM

Re: index or try_files in reverse proxy

edogawaconan August 13, 2009 12:40AM

Re: index or try_files in reverse proxy

Igor Sysoev August 13, 2009 03:22AM

Re: index or try_files in reverse proxy

meto August 13, 2009 06:15AM

Re: index or try_files in reverse proxy

Igor Sysoev August 13, 2009 06:24AM

Re: index or try_files in reverse proxy

meto August 13, 2009 10:13AM

Re: index or try_files in reverse proxy

Igor Sysoev August 13, 2009 02:13PM

Adding tests for handlers and filters

Marcus Clyne August 13, 2009 06:05PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 306
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready