Welcome! Log In Create A New Profile

Advanced

Nginx architecture & implementation

Posted by naquad 
Nginx architecture & implementation
February 09, 2011 06:58PM
Hi.

Are there any materials explaining how Nginx is implemented, why such solutions were applied?
I'm reading sources atm, but I'm new to C and server programming and I can't see the whole picture how it works.

As I understand Nginx work flow is something like following: create listening socket, set its flags (non-blocking, accept defer
socket option, etc...), create multiple threads (workers), each of them can call accept() on main server socket when thats needed and if main sockets mutex is unlocked.
Each thread has its own epoll/kqueue/<whatever multiplexing mechanism is used> loop.

But what I don't understand is following: which data structures are used for storing client related data?
I've found following in ngx_cycle_s structure (ngx_cycle.h at line 43):

[code]
ngx_connection_t **files;
[/code]


its a simple array of pointers to ngx_connection_t (which is actually a typedef to structure ngx_connection_s) and in
poll module (ngx_poll_module.c) its used like this:

[code]
c = ngx_cycle->files[event_list\[i].fd];
[/code]


Thats confusing for me: fd may be anything starting from 0 to <system limit> and creating such array will take
sizeof(void*) (because we have pointer, on my box its 8 byte long) * 1024 (again, limit from my box) = 8192.
Thats pretty much if we have at least 3-4 threads, or am I wrong?

Also, is there some good reading on creating high load applications in C?

Thank you.



Edited 1 time(s). Last edit at 02/09/2011 07:02PM by naquad.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 160
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