Processing of upstream access in nginx

WBOY
Release: 2016-07-29 09:00:40
Original
1069 people have browsed it

nginx handles upstream access very well. It cannot be said to be strange, but it is at least very different. In the processing process, for each upstream, when it is accessed, a socket is established, and then the address of the upstream is bound, and then the upstream is read, and then closed. This approach is very counterintuitive to development. When building a game server, system resources such as sockets are pre-established when the system starts, and then remain connected throughout the entire server running process. When a single socket is disconnected, Instead of closing the socket, the socket is reassigned to a new connection.

Look at the process below, it will be shocking

(gdb) bt
#0  ngx_event_connect_peer (pc=0x9c1e6d8) at src/event/ngx_event_connect.c:32
#1  0x0808cd9b in ngx_http_upstream_connect (r=0x9c1de38, u=0x9c1e6d0) at src/http/ngx_http_upstream.c:1368
#2  0x0808bd82 in ngx_http_upstream_init_request (r=0x9c1de38) at src/http/ngx_http_upstream.c:772
#3  0x0808b61d in ngx_http_upstream_init (r=0x9c1de38) at src/http/ngx_http_upstream.c:523
#4  0x080bc5d7 in ngx_http_memcached_handler (r=0x9c1de38) at src/http/modules/ngx_http_memcached_module.c:224
#5  0x0807a37b in ngx_http_core_content_phase (r=0x9c1de38, ph=0x9c33db8) at src/http/ngx_http_core_module.c:1363
#6  0x08075828 in ngx_http_core_run_phases (r=0x9c1de38) at src/http/ngx_http_core_module.c:840
#7  0x0807594a in ngx_http_handler (r=<optimized out>) at src/http/ngx_http_core_module.c:823
#8  0x0807d281 in ngx_http_process_request (r=0x9c1de38) at src/http/ngx_http_request.c:1910
#9  0x0807fa89 in ngx_http_process_request_headers (rev=0x78a930c8) at src/http/ngx_http_request.c:1342
#10 0x0807fd3e in ngx_http_process_request_line (rev=0x78a930c8) at src/http/ngx_http_request.c:1022
#11 0x08080691 in ngx_http_wait_request_handler (rev=0x78a930c8) at src/http/ngx_http_request.c:499
#12 0x08072a91 in ngx_epoll_process_events (cycle=0x9c185e8, timer=60000, flags=1) at src/event/modules/ngx_epoll_module.c:822
#13 0x0806abbc in ngx_process_events_and_timers (cycle=0x9c185e8) at src/event/ngx_event.c:242
#14 0x08070ebc in ngx_worker_process_cycle (cycle=0x9c185e8, data=0x0) at src/os/unix/ngx_process_cycle.c:753
#15 0x0806f932 in ngx_spawn_process (cycle=0x9c185e8, proc=0x8070e2a <ngx_worker_process_cycle>, data=0x0, name=0x80d540a "worker process", 
    respawn=-3) at src/os/unix/ngx_process.c:198
#16 0x08070338 in ngx_start_worker_processes (cycle=cycle@entry=0x9c185e8, n=1, type=type@entry=-3) at src/os/unix/ngx_process_cycle.c:358
#17 0x080716a5 in ngx_master_process_cycle (cycle=0x9c185e8) at src/os/unix/ngx_process_cycle.c:130
#18 0x08052669 in main (argc=1, argv=0xbfaeb814) at src/core/nginx.c:367
Copy after login

The above introduces the processing of uptream access in nginx, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template