using ebpf for linux performance analyses

50
© 2019 Percona. 1 Peter Zaitsev, CEO Percona Using eBPF for Linux Performance Analyses In 25 Minutes… February 3rd, 2019 FOSDEM, Monitoring and Observability Brussels, Belgium

Upload: others

Post on 10-Dec-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using eBPF for Linux Performance Analyses

© 2019 Percona. 1

Peter Zaitsev, CEO Percona

Using eBPF for Linux Performance AnalysesIn 25 Minutes…

February 3rd, 2019

FOSDEM, Monitoring and ObservabilityBrussels, Belgium

Page 2: Using eBPF for Linux Performance Analyses

© 2019 Percona. 2

Question

Who is familiar with eBPF ?

Page 3: Using eBPF for Linux Performance Analyses

© 2019 Percona. 3

About Myself

Performance Geek turned CEO, who kept

his passion

Page 4: Using eBPF for Linux Performance Analyses

© 2019 Percona. 4

About the Presentation

eBPF Overview

Practical examples of eBPF based tools

Page 5: Using eBPF for Linux Performance Analyses

© 2019 Percona. 5

eBPF History and Linux Support

Page 6: Using eBPF for Linux Performance Analyses

© 2019 Percona. 6

eBPF - Extended Berkeley Packet Filter

Berkeley Packet Filter - Originated in 1992 as efficient virtual machine for Packet Filtering

Extended Berkeley Packet Filter – Extended Version found in Linux

General Event Processing Framework

JIT Compiler for high efficiency

Page 7: Using eBPF for Linux Performance Analyses

© 2019 Percona. 7

eBPF in Linux

Has been in Linux Kernel since 2014

Actively being improved

Integrated in “perf” tooling

system

Page 8: Using eBPF for Linux Performance Analyses

© 2019 Percona. 8

Improvements in recent Kernels

Page 9: Using eBPF for Linux Performance Analyses

© 2019 Percona. 9

eBPF Programs

Linux Kernel can load programs in custom byte code

Programs verified before load to prevent misuse

LLVM Clang can compile to eBPF byte code

This compilation is kernel-dependent

Few will need to write eBPF programs Directly

Page 10: Using eBPF for Linux Performance Analyses

© 2019 Percona. 10

eBPF Code Example

Page 11: Using eBPF for Linux Performance Analyses

© 2019 Percona. 11

eBPF User Space vs Kernel

Source: http://www.brendangregg.com/ebpf.html

Page 12: Using eBPF for Linux Performance Analyses

© 2019 Percona. 12

eBPF in Linux Summary

Page 13: Using eBPF for Linux Performance Analyses

© 2019 Percona. 13

eBPF features in different kernel versions

Page 14: Using eBPF for Linux Performance Analyses

© 2019 Percona. 14

Tracing Landscape per Brendan Gregg

Page 15: Using eBPF for Linux Performance Analyses

© 2019 Percona. 15

Things to note

•perf-tools-unstable

•Iovisor/bcc

•Iovisor/ply

•…

Not all the tools

available in the single package

Page 16: Using eBPF for Linux Performance Analyses

© 2019 Percona. 16

Iovisor bcc installation

Detailed Instructions: https://github.com/iovisor/bcc/blob/master/INSTALL.md

Note: Tools installed to /usr/share/bcc/tools not added to PATH automatically

Page 17: Using eBPF for Linux Performance Analyses

© 2019 Percona. 17

Tools in Action

Page 18: Using eBPF for Linux Performance Analyses

© 2019 Percona. 18

Profile: Better “poor man’s profiler”

Page 19: Using eBPF for Linux Performance Analyses

© 2019 Percona. 19

Biolatency: Block Device Latency

Page 20: Using eBPF for Linux Performance Analyses

© 2019 Percona. 20

Biosnoop: Block Device IO Tracing

Page 21: Using eBPF for Linux Performance Analyses

© 2019 Percona. 21

Ext4dist: Filesystem Latency per Operation

Page 22: Using eBPF for Linux Performance Analyses

© 2019 Percona. 22

Ext4slower: Trace Slow (or all) IO

Page 23: Using eBPF for Linux Performance Analyses

© 2019 Percona. 23

Cachestat: File System Cache Performance

Page 24: Using eBPF for Linux Performance Analyses

© 2019 Percona. 24

Runqlat: CPU RunQueue Latency

Page 25: Using eBPF for Linux Performance Analyses

© 2019 Percona. 25

Execsnoop: Trace Program Starts

Page 26: Using eBPF for Linux Performance Analyses

© 2019 Percona. 26

Opensnoop: Trace Opened Files

Page 27: Using eBPF for Linux Performance Analyses

© 2019 Percona. 27

Tcpconnect: Trace TCP Connections

Page 28: Using eBPF for Linux Performance Analyses

© 2019 Percona. 28

Tcpretrans: TCP Retransmits Details

Page 29: Using eBPF for Linux Performance Analyses

© 2019 Percona. 29

Gethostlatency: DNS Lookup Latency

Page 30: Using eBPF for Linux Performance Analyses

© 2019 Percona. 30

All tools available with BCC:

Page 31: Using eBPF for Linux Performance Analyses

© 2019 Percona. 31

Ply: Simple Scripting for eBPF

Is not available as packages yet!

git clone https://github.com/iovisor/plycd ply./autogen.sh./configuremake

More Details: https://wkz.github.io/ply/

Page 32: Using eBPF for Linux Performance Analyses

© 2019 Percona. 32

Ply Example

Page 33: Using eBPF for Linux Performance Analyses

© 2019 Percona. 33

Ply Language#!/usr/bin/env ply

kprobe:SyS_execve {

@exec[tid()] = mem(arg(0), "128s");

i = 0;

unroll(16) {

argi = mem(arg(1) + i * sizeof("p"), "p");

if (!argi)

return;

@argv[tid(), i] = mem(argi, "128s");

i = i + 1;

}

}

Page 34: Using eBPF for Linux Performance Analyses

© 2019 Percona. 34

Lets Get Some History !

Page 35: Using eBPF for Linux Performance Analyses

© 2019 Percona. 35

eBPF and Trending

Command Line Frontends are great for interactive troubleshooting of current problems

Not very helpful if you want to analyze the past

How do we get the data into Monitoring System ?

Page 36: Using eBPF for Linux Performance Analyses

© 2019 Percona. 36

Meet Cloudflare’s eBPF Exporter

Get results of your eBPF Probes to Prometheus

Can plot Prometheus data using Grafana and other Tools

Use for Alerting with Prometheus Alert Manager

More Info: https://blog.cloudflare.com/introducing-ebpf_exporter/

Page 37: Using eBPF for Linux Performance Analyses

© 2019 Percona. 37

In Search of the Response Time Histograms

Autodesk Research: https://www.autodeskresearch.com/publications/samestats

Page 38: Using eBPF for Linux Performance Analyses

© 2019 Percona. 38

eBPF Exporter Architecture

Uses BCC Frontend (Library)

Can be used to take BCC Programs output and expose them in Prometheus Format

Mind Performance Overhead of eBPF Probes

Page 39: Using eBPF for Linux Performance Analyses

© 2019 Percona. 39

eBPF Overhead

eBPF Programs can be run million+ times per second per core

More Details: https://github.com/cloudflare/ebpf_exporter/tree/master/benchmark

Page 40: Using eBPF for Linux Performance Analyses

© 2019 Percona. 40

Installing eBPF Exporter

• Install Exporter (Binaries Available)

• https://github.com/cloudflare/ebpf_exporter/releases

• Provide Instrumentation Configuration

• https://github.com/cloudflare/ebpf_exporter/tree/master/examples

Page 41: Using eBPF for Linux Performance Analyses

© 2019 Percona. 41

Percona Monitoring and Management (PMM)

100% Free and Open Source

Purpose Built for Open Source Databases

Based on Grafana and Prometheus

Easy to Install and Use

Where should we visualize it ?

Page 42: Using eBPF for Linux Performance Analyses

© 2019 Percona. 42

Adding eBPF Exporter to PMM

pmm-admin add external:service ebpf --service-port=9435

Page 43: Using eBPF for Linux Performance Analyses

© 2019 Percona. 43

Device IO Response Histogram

Page 44: Using eBPF for Linux Performance Analyses

© 2019 Percona. 44

PMM System Overview Dashboard

Page 45: Using eBPF for Linux Performance Analyses

© 2019 Percona. 45

Adding Latency Histograms

Page 46: Using eBPF for Linux Performance Analyses

© 2019 Percona. 46

Can see outliers

Page 47: Using eBPF for Linux Performance Analyses

© 2019 Percona. 47

eBPF Future

Page 48: Using eBPF for Linux Performance Analyses

© 2019 Percona. 48

Bpftrace – Dtrace Replacement

See More: http://www.brendangregg.com/blog/2018-10-08/dtrace-for-linux-2018.html

Page 49: Using eBPF for Linux Performance Analyses

© 2019 Percona. 49

Further Reading List

https://github.com/zoidbergwill/awesome-ebpf

https://slideplayer.com/slide/12710510/

http://www.brendangregg.com/ebpf.html

http://vger.kernel.org/netconf2018_files/BrendanGregg_netconf2018.pdf

http://www.brendangregg.com/Slides/Velocity2017_BPF_superpowers.pdf

https://lwn.net/Articles/740157/

Page 50: Using eBPF for Linux Performance Analyses

© 2019 Percona. 50

Thank You!