[DEV] nginx ngx_hash_t usage, and other questions...

Brice Figureau brice+nginx at daysofwonder.com
Tue Sep 25 12:33:12 MSD 2007

On Mon, 2007-09-24 at 23:07 +0400, Igor Sysoev wrote:
> On Mon, Sep 24, 2007 at 08:14:19PM +0200, Brice Figureau wrote:
> > 2) What is the purpose of the ngx_hash_keys_arrays_t parameter in
> > ngx_hash_add_key ?
> > After initing one, what should I put in there ?
> ngx_hash_t is not dynamic hash. It's special hash that build
> at reconfiguration time from ready data. While hash initalizing nginx
> finds the optimal hash size to fit one or several keys in single bucket.
> The bucket size is one or several CPU cacheline, so this allows to lookup
> in hash with minimum CPU cache misses.

Oh, I see. The prototype looked quite strange for a dynamic data

> For dynamic data I use rbtree.

OK, it seems that what you are doing in the limit zone module is almost
what I planned to do. I think I'll study this code in more details.

You are placing the rbtree in this module in a shm segment. Is it to
share it between the possibly multiple workers ?
I was wondering how I could share my global data structure between the
different workers...

> > I also have a few more general or basic questions:
> > 
> > 1) There are a lot of ngx_str_t used, but all the ngx_string.c functions
> > are using u_char* . Does it mean the strings are always null terminated
> > and the ngx_str_t len parameter is used for something else ?
> > So to use ngx_strcmp with 2 ngx_str_t, I just have to call it with the value?
> No, ngx_str_t may be null terminated (and len does count null in the case),
> but in general it is not null terminated.

OK, so how do compare strings for instance ?
ngx_strcmp is acting on null terminated strings, but since I don't know
beforehand if the string is terminated or not...
Maybe I have to use ngx_memn2cmp ?

> > 2) Can I register an handler or a phase handler that will be triggered at
> > the end of a request (and if yes how) ?
> > This is to do the cleanup in my hash table containing the uploading requests.
> Use ngx_pool_cleanup_add(r->pool, size).

OK, then the handler will be called when the pool is deallocated, is
that right?
And the request pool is deallocated when the request is over.

I don't have to add any memory to the request pool in my case; is it
possible to pass 0 as the size ?

Thanks for your answer,
Brice Figureau <brice+nginx at daysofwonder.com>

More information about the nginx mailing list