[PATCH] HTTP: implement 'connect' and 'close' phases

Maxim Dounin mdounin at mdounin.ru
Fri Nov 20 14:46:12 UTC 2015


Hello!

On Fri, Nov 20, 2015 at 09:45:53AM +0000, Alessandro Ghedini wrote:

> # HG changeset patch
> # User Alessandro Ghedini <alessandro at cloudflare.com>
> # Date 1447956026 0
> #      Thu Nov 19 18:00:26 2015 +0000
> # Node ID 9d265c320050a00ff24fa8d84371701e46147e8a
> # Parent  bec5b3093337708cbdb59f9fc253f8e1cd6d7848
> HTTP: implement 'connect' and 'close' phases
> 
> This patch adds the NGX_HTTP_CONNECT_PHASE and NGX_HTTP_CLOSE_PHASE
> phases.
> 
> Handlers for these phases are called when a connection is estabilished
> and when it is closed, and they take a ngx_connection_t as argument
> instead of ngx_http_request_t like the other phase handlers.
> 
> These can be useful for keeping track of TCP connections for debugging,
> monitoring and logging purposes, and can also be used to apply custom
> configurations (e.g. socket options).
> 
> This patch also adds a "ctx" field to ngx_connection_t, to be used by
> modules to store their own context structures (just like the ctx field
> in ngx_http_request_t).

Phases are request processing phases, and what you are trying to 
do doesn't looks like request processing.  Additionally, ctx in 
ngx_connection_t implies noticeable memory overhead for keepalive 
connections.

Instead, consider:

- starting your processing at any request processing stage as 
  needed;

- using a connection pool cleanup handler if you want to track 
  connection termination;

- searching though connection pool cleanups if you want to 
  preserve some connection-specific data.

[...]

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list