Slide 1

Slide 1 text

Lynn Root | SRE | @roguelynn Tracing: Fast & Slow Digging into and improving your web service’s performance

Slide 2

Slide 2 text

$ whoami

Slide 3

Slide 3 text

Slide 4

Slide 4 text

agenda —

Slide 5

Slide 5 text

agenda • Overview and problem space —

Slide 6

Slide 6 text

agenda • Overview and problem space • Approaches to tracing —

Slide 7

Slide 7 text

agenda • Overview and problem space • Approaches to tracing • Tracing at scale —

Slide 8

Slide 8 text

agenda • Overview and problem space • Approaches to tracing • Tracing at scale • Diagnosing performance issues —

Slide 9

Slide 9 text

agenda • Overview and problem space • Approaches to tracing • Tracing at scale • Diagnosing performance issues • Tracing services & systems —

Slide 10

Slide 10 text

Tracing Overview —

Slide 11

Slide 11 text

machine-centric • Focus on a single machine —

Slide 12

Slide 12 text

machine-centric • Focus on a single machine • No view into a service’s dependencies —

Slide 13

Slide 13 text

workflow-centric • Understand causal relationships —

Slide 14

Slide 14 text

workflow-centric • Understand causal relationships • End-to-end tracing —

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

why trace? —

Slide 17

Slide 17 text

why trace? • Performance analysis —

Slide 18

Slide 18 text

why trace? • Performance analysis • Anomaly detection —

Slide 19

Slide 19 text

why trace? • Performance analysis • Anomaly detection • Profiling —

Slide 20

Slide 20 text

why trace? • Performance analysis • Anomaly detection • Profiling • Resource attribution —

Slide 21

Slide 21 text

why trace? • Performance analysis • Anomaly detection • Profiling • Resource attribution • Workload modeling —

Slide 22

Slide 22 text

Tracing Approaches —

Slide 23

Slide 23 text

manual

Slide 24

Slide 24 text

def request_id(f): @wraps(f) def decorated(*args, **kwargs): req_id = request.headers.get( "X-Request-Id", uuid.uuid4()) return f(req_id, *args, **kwargs) return decorated @app.route("/") @request_id def list_services(req_id): # log w/ ID for wherever you want to trace # app logic

Slide 25

Slide 25 text

upstream appserver { 10.0.0.0:80; } server { listen 80; # Return to client add_header X-Request-ID $request_id; location / { proxy_pass http://appserver; # Pass to app server proxy_set_header X-Request-ID $request_id; } }

Slide 26

Slide 26 text

log_format trace '$remote_addr … $request_id'; server { listen 80; add_header X-Request-ID $request_id; location / { proxy_pass http://app_server; proxy_set_header X-Request-ID $request_id; # Log $request_id access_log /var/log/nginx/access_trace.log trace; } }

Slide 27

Slide 27 text

blackbox

Slide 28

Slide 28 text

metadata propagation

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Tracing at Scale —

Slide 31

Slide 31 text

four things to think about —

Slide 32

Slide 32 text

four things to think about • What relationships to track —

Slide 33

Slide 33 text

four things to think about • What relationships to track • How to track them —

Slide 34

Slide 34 text

four things to think about • What relationships to track • How to track them • Which sampling approach to take —

Slide 35

Slide 35 text

four things to think about • What relationships to track • How to track them • Which sampling approach to take • How to visualize to employ —

Slide 36

Slide 36 text

what to track

Slide 37

Slide 37 text

Request One Request Two Submitter Flow PoV

Slide 38

Slide 38 text

Request One Request Two Trigger Flow PoV

Slide 39

Slide 39 text

how to track

Slide 40

Slide 40 text

request ID

Slide 41

Slide 41 text

request ID + logical clock

Slide 42

Slide 42 text

request ID + logical clock + previous trace points

Slide 43

Slide 43 text

tradeoffs —

Slide 44

Slide 44 text

tradeoffs • Payload size —

Slide 45

Slide 45 text

tradeoffs • Payload size • Explicit relationships —

Slide 46

Slide 46 text

tradeoffs • Payload size • Explicit relationships • Collate despite lost data —

Slide 47

Slide 47 text

tradeoffs • Payload size • Explicit relationships • Collate despite lost data • Immediate availability —

Slide 48

Slide 48 text

how to sample

Slide 49

Slide 49 text

sampling approaches • Head-based —

Slide 50

Slide 50 text

sampling approaches • Head-based • Tail-based —

Slide 51

Slide 51 text

sampling approaches • Head-based • Tail-based • Unitary —

Slide 52

Slide 52 text

what to visualize

Slide 53

Slide 53 text

gantt chart — GET /home GET /feed GET /profile GET /messages GET /friends Trace ID: de4db33f

Slide 54

Slide 54 text

— request flow graph A call B call C call C call D call E call E reply D reply B reply C reply C reply A reply 2200µs 1500µs 500µs 300µs 400µs 600µs 800µs 500µs 500µs 700µs 500µs 400µs 600µs 100µs

Slide 55

Slide 55 text

— context calling tree A B C C D E

Slide 56

Slide 56 text

keep in mind • What do I want to know? —

Slide 57

Slide 57 text

keep in mind • What do I want to know? • How much can I instrument? —

Slide 58

Slide 58 text

keep in mind • What do I want to know? • How much can I instrument? • How much do I want to know? —

Slide 59

Slide 59 text

suggested for performance —

Slide 60

Slide 60 text

suggested for performance — • Trigger PoV

Slide 61

Slide 61 text

suggested for performance — • Trigger PoV • Head-based sampling

Slide 62

Slide 62 text

suggested for performance — • Trigger PoV • Head-based sampling • Flow graphs

Slide 63

Slide 63 text

Diagnosing —

Slide 64

Slide 64 text

questions to ask — • Batch requests?

Slide 65

Slide 65 text

questions to ask • Batch requests? • Any parallelization opportunities? —

Slide 66

Slide 66 text

questions to ask • Batch requests? • Any parallelization opportunities? • Useful to add/fix caching? —

Slide 67

Slide 67 text

questions to ask • Batch requests? • Any parallelization opportunities? • Useful to add/fix caching? • Frontend resource loading? —

Slide 68

Slide 68 text

questions to ask • Batch requests? • Any parallelization opportunities? • Useful to add/fix caching? • Frontend resource loading? • Chunked or JIT responses? —

Slide 69

Slide 69 text

Systems & Services —

Slide 70

Slide 70 text

OpenTracing

Slide 71

Slide 71 text

self-hosted

Slide 72

Slide 72 text

Zipkin (Twitter) —

Slide 73

Slide 73 text

Zipkin (Twitter) • Out-of-band reporting to remote collector —

Slide 74

Slide 74 text

Zipkin (Twitter) • Out-of-band reporting to remote collector • Report via HTTP, Kafka, and Scribe —

Slide 75

Slide 75 text

Zipkin (Twitter) • Out-of-band reporting to remote collector • Report via HTTP, Kafka, and Scribe • Python libs only support propagation via HTTP —

Slide 76

Slide 76 text

Zipkin (Twitter) • Out-of-band reporting to remote collector • Report via HTTP, Kafka, and Scribe • Python libs only support propagation via HTTP • Limited web UI —

Slide 77

Slide 77 text

def http_transport(span_data): requests.post( "http://zipkinserver:9411/api/v1/spans", data=span_data, headers={"Content-type": "application/x-thrift"}) @app.route("/") def index(): with zipkin_span(service_name="myawesomeapp", span_name="index", # need to write own transport func transport_handler=http_transport, port=app_port, # 0-100 percent sample_rate=100): # do something

Slide 78

Slide 78 text

Jaeger (Uber) —

Slide 79

Slide 79 text

Jaeger (Uber) • Local daemon to collect & report —

Slide 80

Slide 80 text

Jaeger (Uber) • Local daemon to collect & report • Storage support for only Cassandra —

Slide 81

Slide 81 text

Jaeger (Uber) • Local daemon to collect & report • Storage support for only Cassandra • Lacking in documentation —

Slide 82

Slide 82 text

Jaeger (Uber) • Local daemon to collect & report • Storage support for only Cassandra • Lacking in documentation • Cringe-worthy client library —

Slide 83

Slide 83 text

import opentracing as ot config = Config(…) tracer = config.initialize_tracer() @app.route("/") def index(): with ot.tracer.start_span("ASpan") as span: span.log_event("test message", payload={"life": 42}) with ot.tracer.start_span("AChildSpan", child_of=span) as cspan: span.log_event("another test message") # wat time.sleep(2) # yield to IOLoop to flush the spans tracer.close() # flush any buffered spans

Slide 84

Slide 84 text

honorable mentions • AppDash • LightStep (private beta) —

Slide 85

Slide 85 text

services

Slide 86

Slide 86 text

Stackdriver Trace (Google) —

Slide 87

Slide 87 text

Stackdriver Trace (Google) • No Python client libraries; no gRPC client support —

Slide 88

Slide 88 text

Stackdriver Trace (Google) • No Python client libraries; no gRPC client support • Forward traces from Zipkin —

Slide 89

Slide 89 text

Stackdriver Trace (Google) • No Python client libraries; no gRPC client support • Forward traces from Zipkin • Storage limitation of 30 days —

Slide 90

Slide 90 text

X-Ray (AWS) —

Slide 91

Slide 91 text

X-Ray (AWS) • No first class Python support; Boto available —

Slide 92

Slide 92 text

X-Ray (AWS) • No first class Python support; Boto available • Configurable sampling, but not for Boto —

Slide 93

Slide 93 text

X-Ray (AWS) • No first class Python support; Boto available • Configurable sampling, but not for Boto • Flow graphs with latency, response %, sample % —

Slide 94

Slide 94 text

honorable mentions • Datadog • New Relic —

Slide 95

Slide 95 text

TL;DR —

Slide 96

Slide 96 text

tl;dr — • You need this

Slide 97

Slide 97 text

tl;dr — • You need this • Docs are lacking

Slide 98

Slide 98 text

tl;dr — • You need this • Docs are lacking • Language support lacking

Slide 99

Slide 99 text

tl;dr — • You need this • Docs are lacking • Language support lacking • One size fits all approaches

Slide 100

Slide 100 text

tl;dr — • You need this • Docs are lacking • Language support lacking • One size fits all approaches • But there’s an open spec!

Slide 101

Slide 101 text

Thanks! — Sources & links: rogue.ly/tracing Lynn Root | SRE | @roguelynn