envoy源码分析(十)--事件机制专项分析

 

简述

envoy 是异步事件驱动的。使用了libevent库来实现。

libevent开启了多线程支持,evthread_use_pthreads(),这个API会打开线程锁。允许跨线程的事件操作。

envoy 有一个master线程,多个worker线程。每个线程有自己的event_fd。

在各线程,event_fd,由 dispatcher 封装。  master 和  worker 之间会相互调用对方的 dispatcher, 所以,libevent需要线程锁。

 

envoy代码实现在目录: envoy/source/common/event/

libevent代码实现在:https://github.com/libevent/libevent/blob/release-2.1.12-stable/event.c#L1923 

 

 

类图

image

 

简要流程图

image

 

更多

envoy 1.34 之后就支持了 io_uring, 可以将主要网络IO模型中的 libevent去掉,也就同时去掉了锁。

不过现在还在迭代中,不是个稳定功能

https://www.envoyproxy.io/docs/envoy/latest/configuration/other_features/io_uring.html

https://arthurchiao.art/blog/intro-to-io-uring-zh/

 

内核需要5.11版本。

 

posted on 2025-12-26 18:33  toong  阅读(2)  评论(0)    收藏  举报