作为proxy具备的功能
downstream连接管理
upstream hosts管理
load balance
转发
熔断限流
过载保护
plugin式的动态加载机制,在envoy中为filter
hot reload
downstream连接管理
在server InstaceImpl构建函数中initialize时,创建listener_manager_,由listener_manager_负责addOrUpdateListener
。
ListenerImpl创建时会进行相关filter的构造,如果worker已经started会调用onListenerWarmed将自己添加到woker中。
worker 持有的ConnectionHandlerImpl addListener
--> ActiveListener::onAccept
--> ActiveListener::newConnection
--> createNetworkFilterChain
进行相应协议filter的处理过程
// Network::ConnectionCallbacks in ActiveConnection
void onEvent(Network::ConnectionEvent event) override {
// Any event leads to destruction of the connection.
if (event == Network::ConnectionEvent::LocalClose ||
event == Network::ConnectionEvent::RemoteClose) {
listener_.removeConnection(*this);
}
}
upstream hosts管理
cluster manager负责管理upstream hosts及相关策略。
load顺序static non-EDS
--> ADS
--> static EDS
--> ThreadLocalClusterManagerImpl
--> CDS
worker真正使用的是cluster manager的thread local的版本,cluster manager通过在TLS上注册的thread dispatcher list使用dispatcher的post方法进行更新。
load balance
enum class LoadBalancerType { RoundRobin, LeastRequest, Random, RingHash, OriginalDst, Maglev };
熔断限流
实现在source/common/upstream/outlier_detection_impl.*
中。
plugin式的动态加载机制,在envoy中为filter
使用静态变量注册Factory,根据配置动态加载
hot reload
使用shared memory保持统计信息和进程间共享的锁,用unix domain socket传递fd。
SCM_RIGHTS - Send or receive a set of
open file descriptors from another
process. The data portion contains an
integer array of the file descriptors.
The passed file descriptors behave as
though they have been created with
dup(2).
SCM_RIGHTS使用参考 know-your-scm_rights