Nginx学习笔记3--(极客时间-陶辉)

it2023-10-27  99

目录

nginx模块 内存池 连接池

nginx模块

?nginx源码的/objs/ngx_modules.c中*ngx_modules[]数组代表了编译进nginx的模块。

nginx连接池

?每个worker进程都有一个独立的ngx_cycle_t这样的一个数据结构 ?connections数组:连接池

官方文档Core_functionality的worker_connections Syntax: worker_connections number; Default: worker_connections 512; Context: events

默认512个数组,nginx一般是要处理万,十万,百万级,一般都要修改。 这些连接不止包括客户端的连接,也包括面向服务器的,所以做反向代理的时候等于消耗两个连接。 ? 每个连接默认对应一个读事件一个写事件。每个连接大概占用96+232字节,worker_connections配置的越大,初始化的时候预分配的内存就越大。

ngx_event_handler_pt handler : 这是一个回调方法,很多第三方模块会把它设置为自己的实现ngx_rbtree_node_t timer : 读写事件超时ngx_queue_t queue : 队列bytes_sent --------------------------------以下是nginx.conf-------------------------------- log_format main ‘$remote_addr - r e m o t e u s e r [ remote_user [remoteu​ser[time_local] "KaTeX parse error: Double superscript at position 37: … '̲status [r e q u e s t l e n g t h : request_length:requestl​ength:bytes_sent “KaTeX parse error: Double superscript at position 42: … '̲"http_user_agent” “$http_x_forwarded_for”’; --------------------------------以下是log--------------------------------------- 127.0.0.1 - - [22/Apr/2019:20:35:42 +0800] “GET /index2.html HTTP/1.1” 200 [465:675 “http://localhost:90/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15” "-

内存池

提前分配好一些内存

连接内存池

Syntax: connection_pool_size size; Default: connection_pool_size 256|512; #字节,每个连接预分配内存大小,可以分配更大。 Context: http, server

请求内存池

Syntax: request_pool_size size; Default: request_pool_size 4k; #包括head,url Context: http, server 连接内存池:当运行一个tcp连接的时候上面可能会运行多个HTTP请求(keepalive),连接没有关闭,有些内存为连接分配一次就够,连接不关闭就不需要释放。请求内存池:每个HTTP请求通常会分配4K的内存。 ?减少内存碎片 ?提前预分配了空间,可以减少分配内存的次数。
最新回复(0)