Fastly delivers more than a million log events per second. Our Real-Time Log Streaming is easy to set up, but there are many features you might not be using to their full extent.
This workshop will cover setting up logging to various endpoints, dealing with structured data, and getting real-time insights into your customers’ behavior.
- - - - - - - - - - -
Live streaming and on-demand video can provide a powerful way to connect with customers, but viewers expect seamless pixel-perfect streams without common video delivery inconveniences, such as downtime or lags. This workshop will demonstrate how anyone can deliver live video at scale. We’ll thoroughly explain key video delivery optimizations and more importantly, demonstrate their efficacy using the data collected from both Fastly Log Streaming/Sumo Logic and the Mux quality of experience service.
9. STEPS
● Clone the service
● Add the Sumo Logic endpoint
● Add the custom VCL
● Upload the custom VCL
● Activate the updated version
Optimizing video delivery
Visibility - Configure log streaming
23. curl to set up
Sumo Logic
logging endpoint
curl -X POST
https://api.fastly.com/service/${SERVICE_ID}/version/2/logging/sumologic
-H "Fastly-Key: ${API_KEY}"
-d@logging-log_format.txt | jq
Talk Title
24. api response
should look
something like this
{
"name": "workshop1-SumoLogic",
"message_type": "blank",
"format": "<redacted>",
"url":
"https://endpoint3.collection.us2.sumologic.com/receiver/v1/http/ZaVnC4dhaV1z1AeZ1
Y1MjfCQd5Ypwxi7jXvw0uY2hR3ycKg_lCVd77rj5lgKm-8krz30nPgv-
dBhWCqIl_et_Yez_BMeVUnv2S4d9iqYD1uWMqOZcgiT-A==",
"service_id": "2KVPqlEPCh6tRCVQBxlUYk",
"version": "1",
"placement": null,
"format_version": "2",
"response_condition": "",
"updated_at": "2018-09-08T09:12:09Z",
"deleted_at": null,
"created_at": "2018-09-08T09:12:09Z"
}
Talk Title
37. curl to activate the
service
curl -X PUT
https://api.fastly.com/service/${SERVICE_ID}/version/2/activate
-H "Fastly-Key: ${API_KEY}" | jq
Talk Title
38. …make a bunch of requests from around
the world using Catchpoint
Optimizing video delivery
Visibility - Configure log streaming
42. • Two main ways of delivering video
• Progressive download
• HTTP Streaming
Optimizing video delivery
Quick video overview
43. • Progressive Download
• Supported natively in all modern
browsers via the HTML5 <video> tag
• Usually for short videos ~30 secs
• VOD only
Optimizing video delivery
Quick video overview
44. • HTTP Streaming
• VOD and Live
• No special server software or license required
• Provides Adaptive Bit Rate (ABR)
• Video is packaged into discrete chunks or
segments
• Generally requires a player
Optimizing video delivery
Quick overview of video delivery via HTTP
45. • HTTP streaming comes in a variety of
flavors
• HLS (Apple)
• DASH (MPEG)
• HDS (Adobe)
• Smooth Streaming (Microsoft)
Optimizing video delivery
Quick overview of video delivery via HTTP
46. • HLS Components
• Manifests (.m3u8)
• Master
• Child or Media Playlist
• Segments
• Transportation Segments (.ts)
• Fragmented MP4 (.fmp4)
Optimizing video delivery
Quick overview of video delivery via HTTP
49. 1. Get familiar with the Fastly API
2. Understand video delivery challenges
3. Test, optimize, and confirm improvements for VOD delivery
Optimizing video delivery
Goals: Optimize VOD Delivery
50. A
CDN's
Role
● CDNs help scale & accelerate content
delivery
● Reduce origin load by serving cached
objects
● Works great for smaller objects
● Larger objects benefit from optimizations
51. Optimizing video delivery
A content delivery workflow
End user CDN Origin
Requests Object Fetches Object
Delivers Object Caches Object
54. Optimizing video delivery
HTTP & TCP Optimizations
Increase Congestion Window
Allows clients to better estimate
network bandwidth and thereby
select the ideal rendition and
bitrate for the best playback
quality.
Configure Streaming Miss
Reduces the time clients (players)
must wait to begin downloading
streams when Fastly's edge
servers must fetch content from
your origin.
55. Optimizing video delivery
Step 1: Testing download
alias curltest="curl -w
'nLookup time:t%{time_namelookup} n
Connect time:t%{time_connect} n
App Con time:t%{time_appconnect} n
PreXfer time:t%{time_pretransfer} n
Redirect time:t%{time_redirect} n
StartXfer time:t%{time_starttransfer} nn
Total time:t%{time_total}n'
-svo /dev/null -H 'Fastly-Debug: 1'"
Test Curl Command
Download Video File
time curltest https://<num>-
videoworkshop.global.ssl.fastly.net/vod/tears_of_steel/720p.mp4
56. Optimizing video delivery
Step 1: Testing download cont….
Lookup time: 0.067303
Connect time: 0.081613
App Con time: 0.145351
PreXfer time: 0.145988
Redirect time: 0.000000
StartXfer time: 2.429937
Total time: 12.066361
real 0m12.087s
user 0m0.563s
sys 0m0.561s
Output
57. Clone service from version 2 to version 3
Optimizing video delivery
Step 2: Cloning new service
curl -sv -H "Fastly-Key: ${API_KEY}" -X PUT
https://api.fastly.com/service/${SERVICE_ID}/version/2/clone
| jq
58. Open main.vcl in your git repo, and add specific configuration optimizations.
In vcl_fetch add contents of vod-vcl_fetch.vcl:
Talk Title
Step 3: Add optimizations
############################################
# VIDEO WORKSHOP: INSERT vcl_fetch CODE HERE
############################################
# Set 1s ttl if origin response HTTP status code is anything other than 200 and 206
if (!http_status_matches(beresp.status, "200,206")) {
set beresp.ttl = 1s;
}
# Enable Streaming Miss only for video or audio objects.
# Below conditions checks for video or audio file extensions commonly used in
# HTTP Streaming formats.
if (req.url.ext ~ "m4s|mp4|ts|aac|fmp4") {
set beresp.do_stream = true;
}
# Configure caching for VOD content
if(req.http.X-Service == "vod") {
/* set stale_if_error and stale_while_revalidate (customize these values) */
set beresp.stale_if_error = 7d;
set beresp.stale_while_revalidate = 60s;
# Cache VOD content for 1 year
set beresp.ttl = 365d;
}
############################################
# END VIDEO WORKSHOP
############################################
59. Add final optimizations in vcl_deliver from the file vod-vcl_deliver.vcl
Talk Title
Step 3: Add optimizations cont...
############################################
# VIDEO WORKSHOP: INSERT vcl_deliver CODE HERE
############################################
# increase init cwnd
if (client.requests == 1) {
set client.socket.cwnd = 45;
}
############################################
# END VIDEO WORKSHOP
############################################
60. Save config, upload using the API, and activate the version in our service (version 3).
In order to upload VCL we must URL encode the file so that we can send it via cURL:
Talk Title
Step 4: Upload & activate version
curl -vs -H "Fastly-Key: ${API_KEY}" -X POST -H
"Content-Type: application/x-www-form-urlencoded"
--data "name=workshop2&main=true"
--data-urlencode "content@workshop2_v3.vcl"
https://api.fastly.com/service/${SERVICE_ID}/version/3/vcl
| jq
61. Response:
Talk Title
Step 4: Upload & activate version
{
"name": "workshop2",
"main": true,
"content": "<lots of VCL>,
"service_id": "1OPpKYvOlWVx37twfGVsq0",
"version": 3,
"deleted_at": null,
"created_at": "2018-06-20T20:23:52+00:00",
"updated_at": "2018-06-20T20:23:52+00:00"
}
62. Now,we can activate the version we just uploaded
Talk Title
Step 4: Upload & activate version
curl -vs -H "Fastly-Key: ${API_KEY}" -X PUT
https://api.fastly.com/service/${SERVICE_ID}/version/3/activate | jq
63. Purge our video content (updating host to your specific service):
Talk Title
Step 5: Purge URL & re-test
curl -X PURGE https://<num>-
videoworkshop.global.ssl.fastly.net/vod/tears_of_steel/720p.mp4
Finally, test our video download again:
time curltest https://<num>-
videoworkshop.global.ssl.fastly.net/vod/tears_of_steel/720p.mp4
64. Talk Title
Step 5: Purge URL & re-test cont...
Lookup time: 0.067303
Connect time: 0.081613
App Con time: 0.145351
PreXfer time: 0.145988
Redirect time: 0.000000
StartXfer time: 0.429937
Total time: 11.066361
real 0m12.087s
user 0m0.563s
sys 0m0.561s
Output
66. 1. Learn the differences between VOD and live video delivery
2. Deploy a new origin to deliver live video
3. Configure live streaming specific optimizations
4. Create a scalable live video configuration
Talk Title
Goals: Optimize Live Delivery
67. Why Live
is
Different
● Content is more dynamic
● Stale content not as important
● Thundering Herd issues
● Protecting origin more critical
68. Talk Title
A live delivery workflow
End user CDN Origin
Requests Object Fetches Object
Delivers Object Caches Object
Client wants fresh content
CDN doesn't need to
cache as long
70. Talk Title
Optimizations for Live
Keeping Manifests "Dynamic"
Reduces time in cache to allow for
frequent updates of video
segments.
"Right-sizing" TTLs for segments
Old segments have no need to be
cached, reducing storage
requirements and increasing CHR
for other content.
71. Talk Title
Step 1: Add New Origin Server
● Clone the active service to a new development version (this time cloning
version 3 to version 4):
curl -sv -H "Fastly-Key: ${API_KEY}" -X PUT
https://api.fastly.com/service/${SERVICE_ID}/version/3/clone | jq
{
"testing": false,
"locked": false,
"number": 4,
....
}
● JSON response:
72. Talk Title
Step 1: Add New Origin Server Cont..
Now, lets add a new backend, our "live" service.
curl -sv -H "Fastly-Key: ${API_KEY}" -X POST -H
"Content-Type: application/x-www-form-urlencoded" --data
"ipv4=35.230.111.226&name=live"
https://api.fastly.com/service/${SERVICE_ID}/version/4/backend
73. Talk Title
Step 2: Add live optimizations
● In your repo you will find a file live-vcl_recv.vcl.
● This contains VCL to send any requests on the live route (in this case /live) to the new created created origin
● Add this to workshop2.vcl in the workshop section. It should look something more like this, ready to upload:
###########################################
# VIDEO WORKSHOP - DO STUFF HERE
###########################################
if(req.url.path ~ "^/live") {
set req.backend = F_live;
set req.url = regsub(req.url, "/live", "/hls");
set req.http.X-Service = "live";
}
######## vcl_recv ###########
# Record number of retrans on the connection
set req.http.total_retrans = client.socket.tcpi_total_retrans;
###############################
74. Talk Title
Step 2: Add live optimizations cont..
● In your repo you will find a file live-vcl_fetch.vcl.
● This contains VCL to set specific caching behavior for manifests and segments
if(req.http.X-service == "live") {
# Set 1s ttls for video manifest and 3600s ttls for segments of HTTP Streaming formats.
# Microsoft Smooth Streaming format manifest and segments do not have file extensions.
# Look for the keywords "Manifest" and "QualityLevel" to identify manifest and segment requests.
if (req.url.ext ~ "m3u8|mpd" || req.url.path ~ "Manifest") {
set beresp.ttl = 1s;
} else {
if (req.url.ext ~ "m4s|mp4|ts|aac" || req.url.path ~ "QualityLevel") {
set beresp.ttl = 3600s;
}
}
}
75. Talk Title
Step 3: Upload and activate
Upload our new configuration:
curl -vs -H "Fastly-Key: ${API_KEY}" -X POST -H
"Content-Type: application/x-www-form-urlencoded"
--data "name=workshop3&main=true" --data-urlencode "content@workshop3_v4.vcl"
https://api.fastly.com/service/${SERVICE_ID}/version/4/vcl | jq
Activate the draft version:
curl -vs -H "Fastly-Key: ${API_KEY}" -X PUT
https://api.fastly.com/service/${SERVICE_ID}/version/4/activate | jq
76. Talk Title
Step 4: Play our live stream
● Open a media player (or Safari)
● https://<num>-
videoworkshop.global.ssl.fastly.net/live/stream.
m3u8
● Let the good times roll!
● We're not done just yet
78. ● Many services / POPs connecting to origin
● Higher egress
● Higher infrastructure costs (CPU, etc)
Talk Title
What's the Thundering Herd?
79. ● Designating a PoP as your "shield" reduces requests to
origin
● Delivers content to edge PoPs requesting content
● Collapses multiple requests to 1 for new content
Talk Title
Origin Shielding
80. ● Enabling shielding in Fastly helps mitigate this issue
● What about my other CDNs?
Talk Title
Shielding all the Things
81. Talk Title
Fastly Media Shield - A CDN for your CDNs
Misses from edge sent to Media Shield
Significant reduction in origin load
Request collapsing consolidates
multiple requests for same content
down to one request to origin
OriginMedia Shield
End User Edge POP