How to Load Test HTTP Live Media Streaming (HLS) with JMeter
These days, video is probably the most popular type of online content. As such, it’s essential for online magazines and websites to provide high quality video content worldwide and ensure seamless streaming. After all, millions of viewers are watching at any given time! The most common video streaming protocol is RTMP, which is a flash-based protocol (developed by Adobe) - but it’s not supported by HTML or any iOS devices.
Luckily, there is something that you can do. HTTP Live Streaming (HLS) is not only supported by both HTML and iOS devices, it also can be load tested by JMeter. Here’s how:
HTTP-Based Media Streaming
Apple put HTTP Live Streaming (HLS) into effect in a bid to deliver audio and video content without special server software. As an HTTP-based media streaming protocol, HLS uses web servers to send both live and prerecorded content through a variety of streams at different bit rates, adapting to different network bandwidths. It does this by breaking the media stream up into shorter sequential downloadable file components of their overall streams.
What’s more, HLS is able to bypass firewalls or proxy servers that allow standard HTTP traffic
in, which enables content distribution across a multitude of CDNs. Learn more about HLS in the iOS Developer Library.
As HLS is based on HTTP, generated traffic can be easily consumed by JMeter, which means that it’s easy for us to create load tests. As I’ve already mentioned, HLS works by splitting up media sources into small files and distributing them into a playlist format. So, basically, after you get a hold of the playlist, you can loop the content and download all of the files. That’s it!
Let’s Start Scripting!
As I mentioned before, the whole stream is split into small segments. This means that, in order to get a hold of the playlist file (m3u8), you have to first complete the initial HTTP request (a simple HTTP sampler that performs a GET to the resource). Note that each stream can have multiple playlists (i.e. per video resolution).
Since the response from the playlist provides a chunk-list (i.e. smaller playlists), we will use a regex post-processor to collect them all in an array:
It is important to notice the ‘-1’ in the ‘Match No.’ box. This great feature enables JMeter to find all of the strings that match a particular regex, then bunch them together for further review.
Now that we have our ‘chunks’ array, we need to add a foreach-controller:
This controller understands that the variable, ‘chunks’, is a list of strings. So, it will put the current value in the ‘chunk’ variable for each iteration.
The next step involves getting the actual media-parts so that our ‘browser’ will be able to receive the media-content. This requires creating another HTTP sampler:
The response from this request will be the actual media files that our browser will play.
Disclaimer: These files are usually hosted on another service provider (i.e. a CDN provider, such as Akamai or AWS CloudFront). So, generally speaking, there is no need to make the rest of the requests, because the CDN will perform traffic shaping during load testing and may even think the traffic is a DDoS. This means you should contact the CDN before running such a test.
The next step involves grabbing the streams themselves - which requires yet another regex post-processor:
The same JMeter, ‘-1’, trick is used here.
Finally, perform another loop on the ‘streams’ array, as well as inside another HTTP request to grab it.
The JMeter-tree should look like this:
HLS is one of the best ways today to stream videos, being the only one to support iOS. No wonder it’s such a popular video streaming framework!
As it relies on HTTP, it streams videos in much the same way as any other web traffic data stream. It offers great flexibility as it allows us to use “native HTTP” based tools to test, develop and operate online videos. After reading this blog post, hopefully you can now also see how easy it is to load test HLS with JMeter!
If you have any questions or comments, please feel share them below. I’ll do my best to answer as quickly as possible.
Want more information on load testing with JMeter? Sign up for our free JMeter online training course. Try out BlazeMeter by putting your JMX file or URL in the box below and your test will start in minutes.
Click here to subscribe to our newsletter.
Learn more about performance testing HLS from our free "Using JMeter for Performance Testing HLS Video Delivery" webinar.
You might also find these useful:
Interested in writing for our Blog? Send us a pitch!