Course contentsShow
← Linux
Lesson 1705 of 1,81914. Observability and Performance TroubleshootingFree lesson

Tracing Microservice Sidecar Overhead

Measure the latency added by network proxies or sidecars in service mesh architectures.

In this lesson, you will learn how to isolate and quantify the exact latency introduced by service mesh sidecars, such as Envoy, sitting between your microservices.

The Sidecar Latency Tax

In a service mesh architecture, every network packet must traverse the sidecar proxy twice: once when leaving the source container and once when entering the destination. This "double-hop" adds overhead from context switching, kernel-space socket operations, and internal proxy processing logic. Because sidecars live in a separate process (or namespace), standard application-level logging often hides this latency, making it look like your application is slow when the network stack is actually the bottleneck.

Measuring the "Proxy Penalty"

To measure this effectively, we must trace the read/write system calls at the socket level while correlating them with the proxy's internal processing time. If you use eBPF tools like tcptop or bpftrace, you can observe the delta between a packet entering the proxy's socket and exiting it.

Consider this bpftrace logic to capture the duration a packet spends in the sidecar's ingress buffer:

# Tracing latency between ingress and egress socket writes
bpftrace -e '
kprobe:tcp_sendmsg {
    @start[tid] = nsecs;
}
kretprobe:tcp_sendmsg /@start[tid]/ {
    $delta = nsecs - @start[tid];
    if ($delta > 100000) { printf("Proxy overhead: %d ns\n", $delta); }
    delete(@start[tid]);
}'

By filtering for the sidecar process ID (PID), you can isolate the specific time spent in tcp_sendmsg and tcp_recvmsg. If your application-level metrics (Lesson 12) show 10ms of latency, but your eBPF trace shows 3ms spent inside the proxy process, you have successfully isolated the "sidecar tax."

Why This Matters

When debugging, we often mistake proxy overhead for thread pool saturation (Lesson 14). By tracing the syscall boundary of the proxy, you distinguish between the application struggling to process a request and the sidecar struggling to route or encrypt the traffic. Always correlate these measurements with CPU context switch rates; high proxy overhead is frequently a result of the sidecar process being throttled by CGroup CFS quotas rather than actual network congestion.

Key Takeaway: The sidecar proxy is a distinct execution boundary; you must trace its syscall-level socket transitions to differentiate network transit time from actual application processing latency.