cdn

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cdn [2020/02/04 00:25] – CDN-Bild ischluffcdn [2025/11/03 12:23] (current) ischluff
Line 1: Line 1:
 = CDN = CDN
-Diese Doku beschreibt unser Live-Streaming CDN, wie es seit dem 34C3 gilt. 
  
-== Architektur +<bootnote> 
-Die CDN-Kaskade hat 5 Stufen: Master-Encoder, Transcoder, Fanout, Transport-/Master-Nodes und schließlich Edge-Nodes.+This documentation describes our Livestreaming CDN as of 2025.
  
-{{:cdn_overview.png?1200|}}+The File-CDN for media.ccc.de is described on [[software:voctoweb]]. 
 +</bootnote>
  
-=== 1. Master-Encoder +==== Repo Links 
-Das Master-Encoding entsteht auf dem encoder-cube im Saal aus dem Ausgabesignal des Voctomix. Das Master-Encoding enthält den Mix als 1080p25 in h264 sowie die Slides als 1080p5 in h264 sowie aac von bis zu drei Audiospuren (NativeTranslated, Translated-2)Wahlweise können die Übersetzerspuren sowie die Slide-Spur weggelassen werdenAlle Spuren werden in einem Matroska-Container verpackt.+  * Stream-api, Upload-ProxyUpload-Server: https://github.com/voc/stream-api 
 +  * rtmp-auth daemon: https://github.com/voc/rtmp-auth 
 +  * Transcoding-Script: https://github.com/voc/transcoding
  
-Das Master-Encoding wird von einem Script erzeugt, welches vom ansible aus folgendem Template erzeugt wirdhttps://github.com/voc/cm/blob/master/ansible/roles/encoder/templates/voctomix-scripts/streaming-sink-mkvonly.sh.j2+== Architecture 
 +The CDN-Cascade has 6 stagesEncoder, Ingest, Transcoder, Origin-Relays, Edge-Relays and finally Load-balancers. 
 +{{:cdn_overview.drawio.png|}}
  
-Das Master-Encoding wird auf den lokalen (auf dem encoder-cube laufenden) Icedist (= Icecast zur internen Distributionauf Port 7999 gepusht (http://encoderX.lan.c3voc.de:7999/sX). Der Icedist auf ''live.ber.c3voc.de'' pullt diesen und bietet ihn seinerseits auf http://live.ber.c3voc.de:7999/sX an.+=== 1. Encoder 
 +The initial stream encoding is created near the stage on the encoder PC running voctomix or any video-encoder for third party streams. 
 +The encoding usually contains a 1080p25 H264 video signal, the slides as 1080p5 and up to 3 tracks of audio encoded in AAC (Native, Translated, Translated-2). 
 +The translated audio tracks and the slide video track are optional.
  
 +The origin encoding is pushed as MPEG-TS via SRT to the ingest stage.
  
-==== Debugging+=== 2. Ingest 
 +The ingest machines run both [[https://github.com/voc/srtrelay|srtrelay]] and nginx-rtmp to receive pushed streams from the encoders. This also serves as the entry point for third party streams.
  
-http://195.54.164.164:7999 (oder http://live.ber.c3voc.de:7999 im Inkognito-Modus damit einen der Browser nicht zu HTTPS zwingen will)+Additionally the ingest machines run a stream-api daemon which scrapes the local stream information from both srtrelay and nginx-rtmp and publishes it to consul KV. 
 +The consul KV path is /stream/<stream slug>
 ``` ```
-voc@live.ber:/etc/icecast2$ systemctl status icedist                                           2019-08-20 21:52:20 +# consul kv get /stream/s96 
-● icedist.service - distribution Icecast +{"format":"mpegts","source":"srt://ingest.c3voc.de:1337?streamid=play/s96","slug":"s96","publishedAt":0}
-   Loadedloaded (/etc/systemd/system/icedist.service; enabled; vendor presetenabled) +
-   Activeactive (running) since Tue 2019-07-30 19:50:07 CEST; 3 weeks days ago +
- Main PID: 794 (icecast2) +
-    Tasks: 25 (limit: 4915) +
-   CGroup: /system.slice/icedist.service +
-           └─794 /usr/bin/icecast2 -c /etc/icecast2/icedist.xml +
- +
-sudo tail -f /var/log/icedist/error.log+
 ``` ```
  
-=== 2. Transcoder +=== 3. Transcoder 
-Das Transcoding läuft auf Speedy & Tweety im RZ "alb". Dabei sind die Räume wie folgt verteilt: +The stream transcoding transforms the mpegts stream into multiple segmented streams (one per qualityvia one big ffmpeg script. Additionally it creates thumbnails and preview images. 
-  * **speedy**: ''s1'', ''s2'', ''s3'', ''q1'' (Freie Push-Quelle), ''sX'' (Teststream+The transcoding script can be found here https://github.com/voc/transcoding.
-  * **tweety**''s4'', ''s5'', ''s6'', ''q2'' (Freie Push-Quelle), ''s23'' (Encoder CCCB), ''s80'' (Encoder MUC)+
  
-<bootnote important>Es ist unwarscheinlich dass speedy & tweety all diese Streams gleichzeitig mit allen Features (HD, SD und Slides) transcoden können.</bootnote>+A python script runs constantly on each transcoder which fetches streams from consul and tries to claim streams which don't have a transcoder assigned yet. 
 +The consul KV path is /stream/<stream slug>/transcoder 
 +``` 
 +# consul kv get /stream/s96/transcoder 
 +myloc-transcoder3
  
-Diese Verteilung wird über Host-Attribute im cm geregelt: https://github.com/voc/cm/blob/master/ansible/event#L48-L49.+# To reallocate a transcoder for a stuck stream 
 +consul kv delete /stream/s96/transcoder 
 +```
  
-Die Transcoding-Scripte holen sich die Master-Streams von http://live.ber.c3voc.de:7999 und erzeugen die fehlenden Formate: vpx-hd/sd/slides, vorbis-audio (für webm), h264-sd sowie mp3/opus-audio.+Every time a transcoder claims a stream it writes an env file and starts a systemd unit to run the transcoding script. 
 +The transcode updates are also published to the #voc-wok IRC.
  
-Die Scripte dazu werden vom ansible aus folgenden Templates erzeugt: https://github.com/voc/cm/tree/master/ansible/roles/transcoder/templates/transcoder+The transcoding outputs are directly pushed with HTTP uploads to the Origin relays. To ensure proper retries the uploads are sent over a local http-proxy (https://github.com/voc/stream-api/tree/master/cmd/upload-proxy).
  
-Die drei Scripte (h264, vpx, audio) erzeugen aus dem Master-Stream drei Format-Streams: (''sX_h264'', ''sX_webm'', ''sX_audio''), welche wieder gegen ''live.ber.c3voc.de:7999'' gepusht werden. Diese Format-Streams sind dann unter folgenden URLs verfügbar:+=== 4. Origin Relays 
 +Origin relays run the upload server (https://github.com/voc/stream-api/tree/master/cmd/upload-serverwhich receives the http uploads and stores the files on local disk. 
 +The upload server has some additional logic to rewrite the HLS playlists on the fly in order to properly handle stream restarts.
  
- * http://live.lan.c3voc.de:7999/sX_h264 +The segmented streams, thumbnails etcare currently served by nginx.
- * http://live.lan.c3voc.de:7999/sX_vpx und +
- * http://live.lan.c3voc.de:7999/sX_audio+
  
-Da jeder Format-Stream aus einem einzelnen ffmpeg-Prozess stammt und in einem Container landet sind die darin enthaltenen Videoströme Zeitsynchron zueinanderDie Trennung nach Formaten soll ermöglichem einzelne Format-Transport-Chains bei Problemen neustarten zu können, ohne die andere zu stören.+=== 5Edge-Relays 
 +The edge relays run nginx with caching proxy config and upstream set to the active origin relay.
  
-Die Pull-Quelle und das Push-Ziel ist über Group-Vars konfigurierbar: https://github.com/voc/cm/blob/master/ansible/group_vars/transcoders+=== 6. Loadbalancer 
 +The end-user facing domains ''streaming.media.ccc.de'' as well as ''cdn.c3voc.de'' are served by the load-balancers using DNS round robin.
  
 +==== streaming.media.ccc.de
 +The load-balancers serve the [[:software:streamingwebsite|Streaming-Webseite]] under this domain. The sites run completely independent and are just kept in sync by the deployment script. With this procedure one or more load-balancers can easily be taken out of the DNS rotation if necessary.
  
-==== Verwaltung +==== cdn.c3voc.de 
-Je nach Event und Situation möchte man ggfdie Verteilugn der Streams zwischen Speedy und Tweety anders einstellenDazu existieren auf beiden Rechnern systemd-Targets für jeden RaumUm einen Überblick über die derzeit aktivierten Transcodings zu erhalten kann folgender Befehl verwendet werden:+Requests to ''cdn.c3voc.de'' are handled by haproxy on the load-balancers with redirects to one of the edge relays. The redirects are performed following a preconfigured weight distribution.
  
-<code> +The relay weight distribution is stored in consul KV and can be tweaked in real timeThe haproxy configs automatically get updated by consul-template after a change.
-voc@tweety.int:~$ systemctl list-units 'trans*'                                                                                                                                                 2018-01-23 0:22:42 +
-UNIT                        LOAD   ACTIVE     SUB          DESCRIPTION                   +
-transcode_s1_audio.service  loaded active     running      Transcoder audio Stream s1    +
-transcode_s1_h264.service   loaded active     running      Transcoder h264 Stream s1     +
-transcode_s1_vpx.service    loaded active     running      Transcoder vpx Stream s1      +
-transcode_s2_audio.service  loaded active     running      Transcoder audio Stream s2    +
-… +
-transcode_s1.target         loaded active     active       All Transcoders of Stream s1  +
-transcode_s2.target         loaded active     active       All Transcoders of Stream s2  +
-… +
-</code>+
  
-Zum auflisten aller verfügbaren Transcoder kann folgender Befehl benutzt werden: +``` 
-<code> +# Get the current weight distribution, if not explicitly set the default is 100 
-voc@tweety.int:~$ systemctl list-unit-files 'trans*'                                                                                                                                            2018-01-23 0:35:36 +consul kv get -recurse /services/haproxy/backends/ 
-UNIT FILE                   STATE    +services/haproxy/backends/live.event.c3voc.de/weight:1 
-transcode_s1_audio.service  enabled  +services/haproxy/backends/relive.c3voc.de/weight:1 
-transcode_s1_h264.service   enabled  +```
-transcode_s1_vpx.service    enabled  +
-transcode_s2_audio.service  enabled  +
-… +
-transcode_s1.target         disabled +
-transcode_s2.target         disabled +
-transcode_s3.target         disabled +
-transcode_s4.target         enabled  +
-transcode_s5.target         enabled  +
-transcode_s6.target         enabled  +
-</code>+
  
-Einzelne Räume können über die Targets aktiviert bzwDeaktiviert werden: +Because of the behavior of HLS/DASH clients if a client fetches a playlist file and gets a redirect, all further requests go to the same originWith this trick the clients stay persistently on one relay until they are redirected.
-<code> +
-sudo systemctl start transcode_s5.target +
-sudo systemctl stop transcode_s1.target +
-</code>+
  
-<bootnote important>Unbedingt darauf achten, dass Streams nicht auf beiden Hosts transcodet werden, da dies zu Stream-Abbrüchen führen kann.</bootnote>+== Stream-URLs
  
-=== 3. Fanout +The resulting stream URLs are as follows (replace @slug with your actual stream slug):
-Diese 3 Format-Streams je Raum werden von der nächsten Stufe auf ''live.ber.c3voc.de'' in die finalen Streams in allen für Endnutzer angebotenen Kombinationen auseinander gemuxt (="fanout").+
  
-Dabei entstehen alle Kombinationen aus ''sX_[hd|sd|slides]_[native|translated|translated-2]'' in webm, hls und dash sowie ''sX_[native|translated|translated-2].[mp3|opus]'' erzeugt. Die WebMund die Audio-Streams werden gegen den Icecast auf http://live.ber.c3voc.de:8000/ gepusht, die HLS- und DASH-Streams werden vom nginx unter http://live.ber.c3voc.de/hls/ bzw. http://live.ber.c3voc.de/dashangeboten.+HLS (H.264 multi-quality + multi-language) 
 +http://cdn.c3voc.de/hls/@slug/native_hd.m3u8
  
-Die Scripte dazu werden vom ansible aus folgenden Templates erzeugt werdenhttps://github.com/voc/cm/tree/master/ansible/roles/relay/files/fanout.+Moar HLS 
 +  * http://cdn.c3voc.de/hls/@slug/translated_hd.m3u8 - also multi-language, just a different default language 
 +  * http://cdn.c3voc.de/hls/@slug/translated-2_hd.m3u8 
 +  * http://cdn.c3voc.de/hls/@slug/native_sd.m3u8 - only SD, but still multi-language 
 +  * http://cdn.c3voc.de/hls/@slug/translated_sd.m3u8 
 +  * http://cdn.c3voc.de/hls/@slug/translated-2_sd.m3u8
  
 +**Currently not active:**
  
-Um einen Überblick über die deployten Fanout Skripte zu erhalten kann folgender Befehl verwendet werden: +MPEG-DASH (VPx multi-quality multi-language) 
- +* http://cdn.c3voc.de/dash/@slug/manifest.mpd
-<code> +
-voc@live.ber:~$ systemctl list-units 'fanout*'   +
- +
-</code> +
- +
-Die Pull-Quelle und das Push-Ziel sowie der Pfad unter dem die HLS/DASH-Schnipsel und Playlisten abgelegt werden ist über Group-Vars konfigurierbar: https://github.com/voc/cm/blob/master/ansible/group_vars/relays#L5 +
- +
-<del>Zu den Aufgaben der fanout-Scripte gehört auch das übermitteln des h264-Videostroms zu Youtube. Die Stream-Keys dazu kommen aus dem KeePass, die Scripte aus dem oben verlinkten Git-Repo.</del>  +
- +
-  * Youtube ist derzeit deaktiviert und wird üblicherweise nur für den Congress aktiviert. +
- +
-Das Transcoding und Fanout reagiert dynamisch auf die Konfiguration des Streams der vom encoder-cube gesendet wird. Fehlt die Slides-Spur oder die Translation-Spuren wird diese nicht in den Master-Playlists und Dash-Manifestd für Adaptives streaming angeboten. Dadurch kann von Event zu Event entschieden werden, ob der Einsatz der Slide-Spur bzw. von Translations sinn ergibt. Siehe dazu [[voctomix:audiomapping|]] zu Details wie Translations de/aktiviert werden können. +
- +
-=== 4. Transport- und Master-Nodes +
-Im Non-Congress Setup ist ''live.ber.c3voc.de'' die einzige (Non-Public) Transport-Node. Die (Public) Edge-Nodes ziehen ihre Daten von dort. +
- +
-=== 5. Edge-Nodes +
-Die ganzjährigen Edge-Nodes lauten: +
-  * ''live.bn.c3voc.de'' +
-  * ''live.alb.c3voc.de'' +
-  * ''live.dus.c3voc.de'' +
-  * ''live.self.c3voc.de'' +
-  * ''live.fem.c3voc.de'' +
- +
-Diese pullen alle Icecast-Streams (Port :8000) – *nicht* die Icedist-Streams – von ''live.ber.c3voc.de''+
-Für die schlussendliche Auslieferung kommt ein nginx zum Einsatz, der abhängig von der URL Daten von einem der unterschiedlichen Backend proxied: +
- * Für Anfragen zu einem WebM, MP3 oder Opus-Stream (z.B: http://live.x.c3voc.de/sX_native_hd.webm) agiert der nginx als Proxy zu seinem eigenen Icecast. Er übernimmt in dieser Rolle das Aggregieren auf die Ports 80/443 sowie das SSL-Handling (für 443). +
- * Für Anfragen nach HLS oder DASH-Schnipseln, -Playlisten und -Manifests (z.B. http://live.x.c3voc.de/hls/sX_native_hd.m3u8) agiert der nginx als Proxy zur Master-Node ''live.ber.c3voc.de'', von welcher er die angefragten Datein abholt und für einen genau festgelegten Zeitraum zwischenspeichert. Dieser Zeitraum muss dabei mit der Segmentlänge der Playlists abgestimmt sein, um eine Fehlerfreie Wiedergabe zu ermöglichen. +
- +
-== Teststream +
-Für den Teststream <del>vor</del>nach dem Congress (Codename ''sX_native_hd'' & co.) wurde **speedy.lan.c3voc.de** als Transcoder für den Stream ''sX'' konfiguriert; **live.ber.c3voc.de** übernimmt das fanout. Der Teststream wird von einem script in einem screen des voc-Benutzers auf **live.ber.c3voc.de** zugeliefert. +
- +
-Alle bereitgestellten Test-URLs lauten +
- +
-VPx-HD: +
-* http://cdn.c3voc.de/sX_native_hd.webm +
-* http://cdn.c3voc.de/sX_translated_hd.webm +
-* http://cdn.c3voc.de/sX_translated-2_hd.webm +
- +
-VPx-SD: +
-* http://cdn.c3voc.de/sX_native_sd.webm +
-* http://cdn.c3voc.de/sX_translated_sd.webm +
-* http://cdn.c3voc.de/sX_translated-2_sd.webm +
- +
-VPx-Slides: +
-* http://cdn.c3voc.de/sX_native_slides.webm +
-* http://cdn.c3voc.de/sX_translated_slides.webm +
-* http://cdn.c3voc.de/sX_translated-2_slides.webm +
- +
-h264-HD: +
-* http://cdn.c3voc.de/hls/sX_native_hd.m3u8 +
-* http://cdn.c3voc.de/hls/sX_translated_hd.m3u8 +
-* http://cdn.c3voc.de/hls/sX_translated-2_hd.m3u8 +
- +
-h264-SD: +
-* http://cdn.c3voc.de/hls/sX_native_sd.m3u8 +
-* http://cdn.c3voc.de/hls/sX_translated_sd.m3u8 +
-* http://cdn.c3voc.de/hls/sX_translated-2_sd.m3u8 +
- +
-h264-Slides: +
-* http://cdn.c3voc.de/hls/sX_native_slides.m3u8 +
-* http://cdn.c3voc.de/hls/sX_translated_slides.m3u8 +
-* http://cdn.c3voc.de/hls/sX_translated-2_slides.m3u8 +
- +
-WebM Multi-Qualität Multi-Lang +
-* http://cdn.c3voc.de/dash/sX/manifest.mpd+
  
 Audio-MP3: Audio-MP3:
-* http://cdn.c3voc.de/sX_native.mp3 +* http://cdn.c3voc.de/@slug_native.mp3 
-* http://cdn.c3voc.de/sX_translated.mp3 +* http://cdn.c3voc.de/@slug_translated.mp3 
-* http://cdn.c3voc.de/sX_translated-2.mp3+* http://cdn.c3voc.de/@slug_translated-2.mp3
  
 Audio-Opus: Audio-Opus:
-* http://cdn.c3voc.de/sX_native.opus +* http://cdn.c3voc.de/@slug_native.opus 
-* http://cdn.c3voc.de/sX_translated.opus +* http://cdn.c3voc.de/@slug_translated.opus 
-* http://cdn.c3voc.de/sX_translated-2.opus +* http://cdn.c3voc.de/@slug_translated-2.opus 
- +== Dynamic SRT/RTMP endpoints with RTMP Auth 
-=== Vollständiges deaktivieren des Teststreams +SRT and RTMP Endpoints can be created under https://ingest.c3voc.de/backend/ (Password in keepass under ansible/stream-api/htpasswd)After creating the endpoint the stream can be pushed to any ingest machine.
-auf ''speedy.lan.c3voc.de'': +
-<code> +
-sudo systemctl stop transcode_sX.target  +
-sudo systemctl disable transcode_sX.target  +
-</code> +
- +
-auf ''live.ber.c3voc.de'': +
-<code> +
-sudo systemctl stop fanout_sX.target +
-sudo systemctl disable fanout_sX.target +
- +
-screen -rd source-for-teststream +
-:quit +
-</code> +
  
-== Loadbalancer +The RTMP-URL for the endpoint ''stream/qtest23'' on ingest1 would be''%%rtmp://ingest.c3voc.de/stream/qtest23?auth=<token>%%''
-Neben den Transportund Edge-Relays gibt es noch zwei Loadbalancer:+
  
-  * ''lb.dus.c3voc.de'' +The SRT-URL would be : ''%%srt://ingest.c3voc.de:1337?streamid=publish/qtest23/<token>%%''
-  * ''lb.alb.c3voc.de''+
  
-Diese sind sowohl für die Domains ''streaming.media.ccc.de'' als auch für ''cdn.c3voc.de'' zuständig. Im DNS sind für beide Domains beide Server angegeben, so dass Clients per statistischem Round-Robin auf einen der beiden Server verteilt werden.+== Future improvements
  
-=== streaming.media.ccc.de +The diagram below shows the envisioned architecture as of 2020In the meantime many of the improvements have been integrated into the CDN
-Unter dieser Domain liefern beide LBs unabhängig von einander die [[:software:streamingwebsite|Streaming-Webseite]] ausDie LBs sind dabei komplett unabhängig voneinander und haben auch je eine eigene KonfigurationEs ist aufgabe des Website-Deployments die Konfiguration synchron zu haltenDurch dieses Setup kann bei Bedarf der jeweilige LB einfach aus der DNS-Rotation herausgenommen werden.+Some more potential improvements are as follows: 
 + * Dynamically adapting the streaming-website to the existence/lack of a stream 
 + * Building a live status dashboard which shows the current stream->ingest->transcoder pipelines 
 + * To gracefully shutdown a relay it could be instructed via consul KV to redirect all clients back to a load balancer while taking it out of the haproxy redirectsThat way all clients would be redistributed to different relays. 
 + * Build origin relay redundancy using dynamic upload client and relay upstream configuration(Relay upstreams need to be sticky, because the HLS playlists generated on the origin relay are not deterministic) 
 + * Use DNS rotation on ingest 
 + * Finalize srtrelay meshing to allow pushed streams to be pulled from any ingest machine.
  
-=== cdn.c3voc.de +{{drawio>diagram1.png}}
-Die Domain ''cdn.c3voc.de'' wird auf beiden LBs von einem HAProxy bedient. Dieser sortiert eventuell zwischen DTAG und Lokalen Klienten und wählt auf dieser Basis einen des obenstehenden Relays aus. Im unterjährigen Betrieb gibt es keine Unterscheidung: Alle Anfragen werden unter den genannten Relays verteilt.+
  
-Der HAProxy verteilt dabei ausschließlich per Redirect, er proxied (entgegen seines Namens) nicht. 
  
-== RTMP Ingest 
-Für Spezialanwendungen (z.B. Cam-Only Streaming im Fritz-Studio) existieren die RTMP-Endpunkte ''q1'' und ''q2'' auf ''live.ber.c3voc.de''. 
-Die Push-Targets lauten ''%%rtmp://live.ber.c3voc.de/stream/q1%%'' bzw. ''q2''. Eine Systemd-Unit setzt diese dann auf Icedist-Ströme gleichen Namens um, von wo Transcoding und Fanout wie oben beschrieben seinen Weg nehmen. 
  
-Achtung: Aufgrund der langen rtmp-Timeouts in ffmpeg kann es bis zu 40 Sekunden dauern, bis die Streams auftauchen und weitere 30 Sekunden, bis alle Formate zur Verfügung stehen. Keine Ungeduld. 
  • cdn.1580772340.txt.gz
  • Last modified: 2020/02/04 00:25
  • by ischluff