· ☕ 4 分钟
https://tenzir.com/blog/production-debugging-bpftrace-uprobes/
https://shaharmike.com/cpp/vtable-part1/
|
|
$ # compile our code with debug symbols and start debugging using gdb
$ clang++ -std=c++14 -stdlib=libc++ -g main.cpp && gdb ./a.out
...
(gdb) # ask gdb to automatically demangle C++ symbols
(gdb) set print asm-demangle on
(gdb) set print demangle on
(gdb) # set breakpoint at main
(gdb) b main
Breakpoint 1 at 0x4009ac: file main.cpp, line 15.
(gdb) run
Starting program: /home/shmike/cpp/a.out
Breakpoint 1, main () at main.cpp:15
15 Parent p1, p2;
(gdb) # skip to next line
(gdb) n
16 Derived d1, d2;
(gdb) # skip to next line
(gdb) n
18 std::cout << "done" << std::endl;
(gdb) # print p1, p2, d1, d2 - we'll talk about what the output means soon
(gdb) p p1
$1 = {_vptr$Parent = 0x400bb8 <vtable for Parent+16>}
(gdb) p p2
$2 = {_vptr$Parent = 0x400bb8 <vtable for Parent+16>}
(gdb) p d1
$3 = {<Parent> = {_vptr$Parent = 0x400b50 <vtable for Derived+16>}, <No data fields>}
(gdb) p d2
$4 = {<Parent> = {_vptr$Parent = 0x400b50 <vtable for Derived+16>}, <No data fields>}
Here’s what we learned from the above:
· ☕ 3 分钟
Terminology
-
Cluster: a logical service with a set of endpoints that Envoy forwards requests to.
-
Downstream: an entity connecting to Envoy. This may be a local application (in a sidecar model) or a network node. In non-sidecar models, this is a remote client.
-
Endpoints: network nodes that implement a logical service. They are grouped into clusters. Endpoints in a cluster are
upstream
of an Envoy proxy. -
Filter: a module in the connection or request processing pipeline providing some aspect of request handling. An analogy from Unix is the composition of small utilities (filters) with Unix pipes (filter chains).
· ☕ 1 分钟
Envoy源码分析之Dispatcher:https://developer.aliyun.com/article/659277
线程相关 Misc:
- Envoy进程由一个Main Thread和多个Worker Thread 组成
- 每个Main和Worker包含一个eventloop,所有的处理都是由eventloop触发开始
- Main负责xDS等功能,Worker负责处理连接和请求
- 当一个client向Envoy建立连接的时候,因为所有Worker的EventLoop都注册了listening fd(启用SO_PORTREUSE除外),会由内核决定分配给哪个Worker
- 当一个下游client连接到了Envoy,在保持连接不断的情况下,会和同一个Worker进行通讯
· ☕ 2 分钟
HTTP/1.1 Header Casing
When handling HTTP/1.1, Envoy will normalize the header keys to be all lowercase. While this is compliant with the HTTP/1.1 spec, in practice this can result in issues when migrating existing systems that might rely on specific header casing.
To support these use cases, Envoy allows configuring a formatting scheme for the headers, which will have Envoy transform the header keys during serialization.
- To configure this formatting on response headers, specify the format in the
http_protocol_options
. - To configure this for upstream request headers, specify the formatting in
http_protocol_options
in the cluster’sextension_protocol_options
.
Currently Envoy supports two mutually exclusive types of header key formatters:
· ☕ 2 分钟
config.core.v3.Http1ProtocolOptions
[config.core.v3.Http1ProtocolOptions proto]
|
|
-
allow_absolute_url
(BoolValue) Handle HTTP requests with absolute URLs in the requests. These requests are generally sent by clients to forward/explicit proxies. This allows clients to configure envoy as their HTTP proxy. In Unix, for example, this is typically done by setting the http_proxy environment variable.
· ☕ 1 分钟
Enable debug log by command line
https://projectcontour.io/docs/v1.10.0/troubleshooting/envoy-debug-log/
The envoy
command has a --log-level
flag that can be useful for debugging. By default, it’s set to info
. To change it to debug
, edit the envoy
DaemonSet in the projectcontour
namespace and replace the --log-level info
flag with --log-level debug
. Setting the Envoy log level to debug
can be particilarly useful for debugging TLS connection failures.
Enable debug log by API
列出 logger 名字:
· ☕ 2 分钟
https://www.envoyproxy.io/docs/envoy/latest/operations/performance
Performance¶
Envoy is architected to optimize scalability and resource utilization by running an event loop on a small number of threads. The “main” thread is responsible for control plane processing, and each “worker” thread handles a portion of the data plane processing. Envoy exposes two statistics to monitor performance of the event loops on all these threads.
-
Loop duration: Some amount of processing is done on each iteration of the event loop. This amount will naturally vary with changes in load. However, if one or more threads have an unusually long-tailed loop duration, it may indicate a performance issue. For example, work might not be distributed fairly across the worker threads, or there may be a long blocking operation in an extension that’s impeding progress.