P2P Optimization
# Introduction
The configuration of m3u8 and hls.js(mpd and dash.js) will have a great impact on the P2P streaming. The proper configuration can significantly increase the P2P ratio. It is not recommended to use multi-bitrate m3u8/mpd.
# Recommended m3u8 Config for live
- segment duration: <= 4 seconds
- number of segment in playlist: >= 10
Example for NGINX:
rtmp {
server {
...
application show {
...
hls_fragment 4; # 4 seconds fragments
hls_playlist_length 60; # 60 seconds playlist
}
}
}
# Allow Http Range Request
Range requests are used to get only a part of a file from the server (for instance, if part of the segment has been downloaded from peer, we retrieve the other part from the CDN). By using range requests you maximize the potential of our P2P technology. Without range requests, it is not possible to take advantage of chunks of media coming from P2P and if the segment is not downloaded as a whole, this data would be considered useless. If range request is activated, we are able to get chunks of data from peer and then complete the segments by getting other chunks from the CDN, thus, reducing your CDN bandwidth. Below is an example that shows how much CDN bandwidth is saved when range requests were activated:
To activate range requests, you should enable OPTIONS requests, and range requests on both origin of your stream and CDN:
# OPTIONS REQUESTS
OPTIONS requests are mandatory to be able to perform RANGE requests in a cross-domain environment.
Your server/CDN must be able to handle OPTIONS requests. Most web-servers handle it natively.
The general idea is to add the following header to the HTTP response:
Access-Control-Allow-Methods: GET, OPTIONS
# RANGE REQUESTS
The general idea is to add the following header to the HTTP response:
Access-Control-Allow-Headers: Range