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

Alessandro Ghedini alessandro at cloudflare.com
Fri Nov 20 15:35:36 UTC 2015


On Fri, Nov 20, 2015 at 05:46:12PM +0300, Maxim Dounin wrote:
> Hello!

Hi,

> 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.

Well, I guess not. But processing at the connection level could still be
useful for request processing as well.

> 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.
> 
> [...]

My intention is to expose this functionality to the lua-nginx module to do
my application-specific processing in Lua, and leave the nginx changes as
general-purpose as possible.

AFAICT none of the methods above allows me to do that, not if I want to do the
processing only once at connection creation or closing, and I really can't
think of any alternative. I'm very much open to suggestions though.

Cheers



More information about the nginx-devel mailing list