async io frame

23
异异 io 异异异异异异异 异异异异异 http://xiaorui.cc

Transcript of async io frame

Page 1: async io frame

异步 io 调度框架的实现峰云就她了

http://xiaorui.cc

Page 2: async io frame

网卡收到数据之后包少,硬中断包多,屏蔽硬中断, DMA+ 软中断

Page 3: async io frame

socket 详细流程tcp 三次握手setblocking

backlog 多大合适 ?

syn, accept 队列accept(), Why new socket

协议栈粘包buffer 缓冲区大小

Page 4: async io frame

IO 阻塞的本质读缓冲,写缓冲区send , recv 原理满加锁,空解锁tcp ack 滑动窗口角色那么 8k 的写缓冲区,我有 80k 要写,流程?

Page 5: async io frame

疑问怎么确定 recv 的结构是完整的 ?

短连接协议约定

粘包是个伪命题 !

长连接、短连接的区别socket 维护长短连接的手段

屏蔽 close()

IO 复用模型用 thread 、 process 活跃上下文

keepalive 心跳包谁来维护 ? 自定义意义

Page 6: async io frame

疑问socket so_keepalive 参数的作用

检测对端的存活keepalive_probes

keepalive_time

keepalive_intvl

如果没配置 so_keepalive, client 挂了 , 服务端在 recv 阶段呆很久 ...

如果配置了 so_keepalive, 通过协议栈来探测存活

Page 7: async io frame

高并发模型fork 模型进程池模型 or 线程池模型io 复用模型

Page 8: async io frame

疑问惊群 ?

饥饿 ?

so_reuseaddr

so_reuseport

Page 9: async io frame

上下文什么是上下文什么是上下文切换为什么要上下文切换什么时候会上下文切换

Page 10: async io frame

执行单元进程线程协程堆、栈抢占、协作

Page 11: async io frame

io同步阻塞同步非阻塞异步阻塞异步非阻塞

Page 12: async io frame

fd

一个线程如何多个 fd ?

忙轮询 ? 要不线程池,堵塞等唤醒

Page 13: async io frame

io 多路复用select

poll

epoll

Page 14: async io frame

select

用法 ?

Page 15: async io frame

epollepoll_create

epoll_ctl

epoll_wait

水平触发 vs 边缘触发tornado 、 nginx 的选择

Page 16: async io frame

跨平台libevent

libev

libuv

Page 17: async io frame

非堵塞客户端connect_ex()

sock.setblocking

eagain == EWOULDBLOCK

O_NONBLOCK

eintr

Page 18: async io frame

连接问题协程可以共用一个连接么 ?

连接池 vs call create ?

Page 19: async io frame

调度器组成部分核心 event loop

类生成器map{fd: object}

信号处理IO 状态文件属性变化定时器periodic

timeout

Page 20: async io frame

prefork + epollMaster Worker 工作模型max_requests

add 、 reduce

worker reload

log reload

socketpair

Page 21: async io frame

epoll wait 惊群某个进程 —配置文件启动了 accept_mutex: 是否超负载 开始尝试拿锁,非堵塞 如果拿到 :           flags |= NGX_POST_EVENTS;   优先处理 accept 事件 释放锁 处理正常 socket 事件 没有拿到 : 返回下次的 epoll_wait 的超时时间 , 而且该 tiemout 缩短,意味着加大机会拿到锁

别的进程在某个进程释放 mutex 和 epoll_wait 超时后,就可以有机会拿到锁了。

Page 22: async io frame

疑问 ?

c10k

服务端没有 65535port 限制

Page 23: async io frame

–xiaorui.cc

“END”