Measuring Performance with Server Timing

A presentation at BristolJS in November 2018 in Bristol, UK by Drew McLellan

Slide 1

Slide 1

BRISTOL JS MEASURING PERFORMANCE WITH SERVER TIMING @drewm

Slide 2

Slide 2

LET’S TALK PERFORMANCE.

Slide 3

Slide 3

Slide 4

Slide 4

Slide 5

Slide 5

TTFB: WAITING FOR YOUR SERVER

Slide 6

Slide 6

MEASURING PERFORMANCE WITH SERVER TIMING WHAT CREATES THE DELAY? ▸ Database calls / slow queries ▸ Templating ▸ Synchronous API interactions ▸ Cold cache hits ▸ Bottlenecked operations of any kind ▸ Stupid stuff like sending emails, resizing images, rainbow painting

Slide 7

Slide 7

WE NEED TO DISCOVER WHAT’S CAUSING THE DELAY.

Slide 8

Slide 8

SERVER MONITORING TOOLS

Slide 9

Slide 9

WOULDN’T IT BE GREAT IF WE COULD PUT THAT INFO HERE

Slide 10

Slide 10

GOOD NEWS MY FRIENDS.

Slide 11

Slide 11

SERVER TIMING https://www.w3.org/TR/server-timing/

Slide 12

Slide 12

MEASURING PERFORMANCE WITH SERVER TIMING WHAT IS SERVER TIMING? ▸ W3C Specification ▸ HTTP response header ▸ Sends basic timing information from server to client ▸ That’s it.

Slide 13

Slide 13

A thing called db had a duration of 123 milliseconds. Server-Timing: db;dur=123, tmpl;dur=56 A thing called tmpl had a duration of 56 milliseconds.

Slide 14

Slide 14

💯

Slide 15

Slide 15

1 2 3 Server-Timing: metric, metric, metric

Slide 16

Slide 16

MEASURING PERFORMANCE WITH SERVER TIMING EACH METRIC HAS THREE POSSIBLE PROPERTIES 1. A short name for the metric (such as db in our example) 2. A duration in milliseconds (expressed as dur=123) 3. A description (expressed as desc=“My Description”) Each property is separated with a semicolon as the delimiter.

Slide 17

Slide 17

Description Name db;dur=123;desc=“Database” Duration

Slide 18

Slide 18

tmpl;dur=56;desc=“Template processing”

Slide 19

Slide 19

Server-Timing: db;dur=123;desc="Database", tmpl;dur=56;desc="Template processing"

Slide 20

Slide 20

Slide 21

Slide 21

Server-Timing: datacenter;desc="East coast data center"

Slide 22

Slide 22

Slide 23

Slide 23

IMPLEMENTATION EXAMPLE

Slide 24

Slide 24

SERVER-TIMING https://www.npmjs.com/package/server-timing

Slide 25

Slide 25

Slide 26

Slide 26

Slide 27

Slide 27

Slide 28

Slide 28

Slide 29

Slide 29

Slide 30

Slide 30

Server-Timing: paint; dur=123; desc="Rainbow painting", bjork; dur=333; desc="Emailing Bjork", total; dur=457.90863199999995; desc="Total Response Time"

Slide 31

Slide 31

Slide 32

Slide 32

CONSIDERATIONS

Slide 33

Slide 33

MEASURING PERFORMANCE WITH SERVER TIMING CONSIDERATIONS ▸ Keep names and descriptions short-ish ▸ Don’t expose anything secret or sensitive ▸ Have some way to enable / disable timing code in your app

Slide 34

Slide 34

IT’S GOOD. Search developer.mozilla.org for “server timing”

Slide 35

Slide 35

THANKS @drewm noti.st/drewm