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

100k’s client connections 100’s access point hosts 1,000’s unique services running on 10k’s hosts

Slide 17

Slide 17 text

why trace? —

Slide 18

Slide 18 text

why trace? • Performance analysis —

Slide 19

Slide 19 text

why trace? • Performance analysis • Anomaly detection —

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Tracing Approaches —

Slide 24

Slide 24 text

manual

Slide 25

Slide 25 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 26

Slide 26 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 27

Slide 27 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 28

Slide 28 text

blackbox

Slide 29

Slide 29 text

metadata propagation

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Tracing at Scale —

Slide 32

Slide 32 text

four things to think about —

Slide 33

Slide 33 text

four things to think about • What relationships to track —

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

what to track

Slide 38

Slide 38 text

Request One Request Two Submitter Flow PoV

Slide 39

Slide 39 text

Request One Request Two Trigger Flow PoV

Slide 40

Slide 40 text

how to track

Slide 41

Slide 41 text

request ID

Slide 42

Slide 42 text

request ID + logical clock

Slide 43

Slide 43 text

request ID + logical clock + previous trace points

Slide 44

Slide 44 text

tradeoffs —

Slide 45

Slide 45 text

tradeoffs • Payload size —

Slide 46

Slide 46 text

tradeoffs • Payload size • Explicit relationships —

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

how to sample

Slide 50

Slide 50 text

sampling approaches • Head-based —

Slide 51

Slide 51 text

sampling approaches • Head-based • Tail-based —

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

what to visualize

Slide 54

Slide 54 text

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

Slide 55

Slide 55 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 56

Slide 56 text

— context calling tree A B C C D E

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

suggested for performance —

Slide 61

Slide 61 text

suggested for performance — • Trigger PoV

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

Diagnosing —

Slide 65

Slide 65 text

questions to ask — • Batch requests?

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

Frameworks, Systems & Services —

Slide 71

Slide 71 text

OpenTracing

Slide 72

Slide 72 text

OpenCensus

Slide 73

Slide 73 text

self-hosted

Slide 74

Slide 74 text

Zipkin (Twitter) —

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 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 79

Slide 79 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 80

Slide 80 text

Jaeger (Uber) —

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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

Slide 85

Slide 85 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 86

Slide 86 text

honorable mentions • AppDash —

Slide 87

Slide 87 text

services

Slide 88

Slide 88 text

Stackdriver Trace (Google) —

Slide 89

Slide 89 text

Stackdriver Trace (Google) • OpenCensus Python library with gRPC support —

Slide 90

Slide 90 text

Stackdriver Trace (Google) • OpenCensus Python library with gRPC support • Forward traces from Zipkin —

Slide 91

Slide 91 text

Stackdriver Trace (Google) • OpenCensus Python library with gRPC support • Forward traces from Zipkin • Storage limitation of 30 days —

Slide 92

Slide 92 text

Stackdriver Trace (Google) • OpenCensus Python library with gRPC support • Forward traces from Zipkin • Storage limitation of 30 days • Recreate graphs per time period —

Slide 93

Slide 93 text

X-Ray (AWS) —

Slide 94

Slide 94 text

X-Ray (AWS) • Supports OpenCensus, not OpenTracing —

Slide 95

Slide 95 text

X-Ray (AWS) • Supports OpenCensus, not OpenTracing • SDK has Python support —

Slide 96

Slide 96 text

X-Ray (AWS) • Supports OpenCensus, not OpenTracing • SDK has Python support • Lots of flexibility with configuring sampling —

Slide 97

Slide 97 text

X-Ray (AWS) • Supports OpenCensus, not OpenTracing • SDK has Python support • Lots of flexibility with configuring sampling • Send metrics from outside AWS environment —

Slide 98

Slide 98 text

X-Ray (AWS) • Supports OpenCensus, not OpenTracing • SDK has Python support • Lots of flexibility with configuring sampling • Send metrics from outside AWS environment • Flow graphs with latency, response %, sample % —

Slide 99

Slide 99 text

honorable mentions • Datadog • New Relic • LightStep • Azure Monitor —

Slide 100

Slide 100 text

TL;DR —

Slide 101

Slide 101 text

tl;dr — • You need this

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

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

Slide 104

Slide 104 text

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

Slide 105

Slide 105 text

tl;dr — • You need this • Docs are lacking • Language support is improving • One size fits all approaches • But there are open specs!

Slide 106

Slide 106 text

Thanks! — Write up: rogue.ly/tracing Lynn Root | SRE | @roguelynn