liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new()...
Transcript of liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new()...
![Page 1: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/1.jpg)
Nginx ����
����
![Page 2: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/2.jpg)
/
![Page 3: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/3.jpg)
WEB, EMAIL�
TCP�
!�����"���
�������������
������
������ HTTP��� MAIL���
Access����Error����
FastCGI, uWSGI. SCGI, memcached��
HTTP, Mail �stream(TCP) ��
Nginx����
![Page 4: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/4.jpg)
Nginx����
Master��Worker�� Cache manager
Cache loader
![Page 5: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/5.jpg)
Nginx�������
Master�� Worker�� nginx��
Ø �worker��• CHLD
Ø �worker��Ø ����• TERM, INT• QUIT• HUP• USR1• USR2• WINCH
Ø ����• TERM, INT
• QUIT
• USR1
• WINCH
Ø reload�HUP
Ø reopen�USR1
Ø stop�TERM
Ø quit�QUIT
![Page 6: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/6.jpg)
reload��
�master,&.HUP���reload���
master,&���#$�'
master,&�*worker�,&.QUIT��
master,&�1/)+ ���%
master,&"�/)���#worker�,&
*worker,&�0$�����!���-� (�,&
01
02
03
04
05
06
![Page 7: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/7.jpg)
reload��������
Master Master
W W W W
W W W W
W W
W W
Master.'�%!2)��!&worker.'
#!nginx.conf2) �Master�1SIGHUP ��+�,nginx -s reload
*2)Worker.'������/�"3&0�
������(��-,���$&#��2)
![Page 8: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/8.jpg)
�����
��Nginx�����Nginx��������
master"���pid����� .oldbin
�!master"��#WINCH� �$!worker
�master"��#USR2�
master"���Nginx�����master"�
����!master�#HUP���master�#QUIT
01
02
03
04
05
06
![Page 9: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/9.jpg)
� ����������������
Master�new�
W W
W W
Master�old�
W W
W W
�master����SIGQUIT�����
������
��Nginx��Master����SIGUSR2
��Nginx �������
Master
W W
W W
Master�new�
W W
W W
![Page 10: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/10.jpg)
worker 4 2
01
02
0304
05
worker_shutdown_timeout
3 0
5
1
4
![Page 11: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/11.jpg)
54
2
54
8
1
A B3 3
22
54545454
88 88
5 5 5
54
![Page 12: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/12.jpg)
TCP����
TCP/IP���
DATA
DATA
DATA
DATA�bv. HTTP, SMTP…����
����
�IP����IP��
�MAC����MAC��
�
��
��
���
TCP, UDP
HTTP, SMTP, POP3,IMAP, SSH, DNS
Ethernet, ADSL, Wifi, PPP
IP, ICMP, DHCP, ARP
HEADER(UDP, TCP)
HEADER(IP)
HEADER(Ethernet)
FOOTER(Ethernet)
![Page 13: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/13.jpg)
TCP��������
��
• Accept���
• Read��
���
• Write���
![Page 14: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/14.jpg)
Nginx����
![Page 15: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/15.jpg)
![Page 16: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/16.jpg)
epoll
+
+
+
+
��Ø
��ØØ
��ØØ /ØØ
![Page 17: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/17.jpg)
��
���������
• ����������
• ���������
��������
• ������
• ������������
![Page 18: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/18.jpg)
�� �
�accept��
������
![Page 19: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/19.jpg)
����
������������
'&�accept
'&�accept
�����"
�����"
�accept
�accept
��EAGAIN
�� ��
� ����'&�
� ����'&�
ACCEPT%���
ACCEPT%����
"EAGAIN$�
��� ���ACCEPT%������!�#�
![Page 20: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/20.jpg)
�����������
local client = redis:new()client:set_timeout(30000)local ok,err = client:connect(ip,port)if not ok then
ngx.say("failed: ",err)return
end
Openresty�������
�� ������post_handler�� �
���������
����body���ngx_http_upstream_init �
rc = ngx_http_read_request_body ( r, ngx_http_upstream_init) ;if ( rc�= NGX_HTTP_SPECIAL_RESPONSE) {
return rc ;}
ngx_int_tngx_http_read_client_request_body (ngx_http_request_t * r,
ngx_http_client_body_handler_pt post_handler)
voidngx_http_upstream_init (ngx_http_request_t * r ){
![Page 21: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/21.jpg)
Nginx �
�����ginx
������
�����
�����
![Page 22: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/22.jpg)
Nginx ��7: :
: 3
7:3 : 3 7
7-33
7 77 3 07 37 7-
: 7 7-: 7 3: 7 7
: 3 0 7
773 +3++ 73 7
: 3 7
7 3 +7 3 +
: 3 3 0 7
7 3 +7 3 +
0003
0 33 -3 77
3
: 7 3 0 7
3 + 7 33 7 3 + 7 3
7 3 +7 3 +7 3 +
3 +7 03 3 +
03 3 +
: -77 3 0 7
7:
3 +3 +
: 0 3 + 7: 7
��
Ø
Ø �����
Ø �����• http• event• mail• stream
��
![Page 23: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/23.jpg)
����
coreNGX_CORE_MODULE
event_core
NGX_EVENT_MODULE
epoll
ngx_http_core_module
NGX_HTTP_MODULE
�����
ngx_stream_core_module
NGX_STREAM_MODULE
steam��
upsteam���
������
errlog thread_pool
events http stream
openssl
ngx_conf_moduleNGX_CONF_MODULE
ngx_mail_core_module
NGX_MAIL_MODULE
![Page 24: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/24.jpg)
��
: ( ( ( : ( ( ( : ( ( ( : +( ( ( ( : ( + ( : ( ( ( : ( + ( : ( ( (: : ( ( ( : ( ( : ( ( (: : +( ( ( ( : ( ( ( (
) :
() () (( () (( (( ( ( ( ( : ( (
( :+( :
( ) ( :+ ( ( :
() (
(( ( (
( ( ((
) ) ()) () :
() :) (
+ (
: (
d b (
d b (
d b (
(c a
( ( (( ( (
_b
��
�� �����
�� ����
![Page 25: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/25.jpg)
����struct ngx_event_s {
void *data;
unsigned instance:1;
unsigned timedout:1;
unsigned timer_set:1;
unsigned available:1;
ngx_event_handler_pt handler;
ngx_uint_t index;
ngx_log_t *log;
ngx_rbtree_node_t timer;
ngx_queue_t queue;
… …
};
struct ngx_connection_s {
void *data;
ngx_event_t *read;
ngx_event_t *write; ����
ngx_socket_t fd;
ngx_recv_pt recv;
ngx_send_pt send; � �OS���
off_t sent; <= bytes_sent��ngx_log_t *log;
ngx_pool_t *pool; <= �� connection_pool_size��
int type;
struct sockaddr *sockaddr;
socklen_t socklen;
ngx_str_t addr_text;
ngx_str_t proxy_protocol_addr;
in_port_t proxy_protocol_port;
ngx_buf_t *buffer;
ngx_queue_t queue;
};
����
�����
![Page 26: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/26.jpg)
���
�� ����
������
![Page 27: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/27.jpg)
Nginx ������
�����
������
• �
• ����
• �
• ������ �
![Page 28: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/28.jpg)
������worker������ nginx��������
�������
Ngx_http_lua_api
rbtree
���
Ngx_stream_limit_conn_moduleNgx_http_limit_conn_moduleNgx_stream_limit_req_module
http cache
ssl
Ngx_http_upstream_zone_module
Ngx_stream_upstream_zone_module
Ngx_http_file_cacheNgx_http_proxy_moduleNgx_http_scgi_moduleNgx_http_uwsgi_moduleNgx_http_fastcgi_module
Ngx_http_ssl_modulNgx_mail_ssl_moduleNgx_stream_ssl_module
![Page 29: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/29.jpg)
OpenResty��������
![Page 30: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/30.jpg)
Slab����
object
object
object
ngx_slab_page_t
object
object
object
ngx_slab_page_t
ngx_slab_page_t
objectngx_slab_page_t
ngx_slab_page_t
ngx_slab_page_t
ngx_slab_page_t
ngx_slab_page_t
slot:2�
slot:3�
�$&
#
��&�����&
#
���$&
��#
������&��# ���
���slot�
�!1�" ���1�����&%
ngx_slab_page_t
• �������
Bestfit
• �� ��
• ����
• ������
Bestfit
![Page 31: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/31.jpg)
ngx_slab_stat���Slab����
![Page 32: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/32.jpg)
Nginx ��
�
��
�
���
��
���
![Page 33: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/33.jpg)
Nginx ���
![Page 34: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/34.jpg)
�����
Bucket size����
Max size
![Page 35: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/35.jpg)
���2 7+ 6 + 2 62 7+ 6 + 25 62 7+ 6 + 1 6
3365 26 2 125 6
2 7+ 6 +6
()
8
��
��
��
��
�
�
�
��
��
��
![Page 36: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/36.jpg)
���
������2�log(n)
����O(n)
�� �����O(log(n))�������
![Page 37: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/37.jpg)
��������
���
ngx_conf_modulengx_event_timer_rbtreeNgx_http_file_cacheNgx_http_geo_moduleNgx_http_limit_conn_moduleNgx_http_limit_req_moduleNgx_http_lua_shdict:ngx.shared.DICTresolver Ngx_stream_geo_moduleNgx_stream_limit_conn_module
ngx_resolver_t
LRU����
config_dump_rbtree
![Page 38: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/38.jpg)
���-�����
load_module modules/ngx_http_image_filter_module.so;
Configure�����
���binary
���������
��load_module��
���� ������
���������
![Page 39: liuhonghe.me · 2018. 12. 27. · EAGAIN$ ACCEPT% ! # local client = redis:new() client:set_timeout(30000) local ok,err = client:connect(ip,port) if not ok then ngx.say("failed: ",err)](https://reader033.fdocuments.in/reader033/viewer/2022060921/60acb61127a52f605a54147d/html5/thumbnails/39.jpg)
/