Randomize MIME-Type in Avalanche (or How To Use Cursors)

Recently, a Proxy equipment vendor was asking me how to randomize the MIME-Type of the files retrieved over HTTP using their Avalanche. They do different things to different file types – don’t cache JavaScript, but cache images, for instance.

It’s easy to specify a static percentage of MIME Type you’re going to get in your test. If you create an Action List, make 10 GET to a MP3, 10 GET to a MPEG and 80 to HTML transactions, and you’ll get 10% MP3, 10% MPEG and 80% HTML. But in the case of today’s post, we want a 10% chance of getting MP3, not exactly 10% MP3 on the wire. See the difference?

Fortunately, Avalanche can do that thanks to a feature that not a lot of people know about: cursors. They allow to move through a Forms Database randomly (or not). We will use this, following this scenario:

  • Files must be real (for the magic bytes signing)
  • We will use 10 files of different type
  • We will upload these files to the Avalanche HTTP Server
  • We will put these file names into a file (FormDB)
  • We will randomly access lines in the FormDB, get a file name, and GET it from the Avalanche Server.

I’ve decided to use the values below for the probability to hit a file with a specific type:

  • AUDIO MP3: 10%
  • CSS: 5%
  • DOCX: 5%
  • PDF: 5%
  • HTTP-TEXT: 30%
  • IMAGE (LARGE): 5%
  • IMAGE (SMALL) : 10%
  • AUDIO WAV: 5%
  • VIDEO MPG: 20%

I’ve bundled together one file of each type, and uploaded them on the Avalanche HTTP Server (Server>Transaction>Body Content Type: Files from Directory). See first screenshot below. We can see that all the files were uploaded on the second screen.

Now the idea is to put all these files names in a FormDB. I will use 100 lines in the form. Five lines will be “audio.mp3” (since we want a probability of 5%), 30 lines will be “http-text.htm” (30%), etc…

But we don’t have the randomness yet. This is the next step. Going to the Action List, I’m going to use this:

CREATE <global.myRandomFile files random_uniform_autoinc>

This will create a global cursor (shared by all the SimUsers) named “myRandomFile“, browsing through the “files” FormDB in a random fashion, and automatically moving to a next (random) row thanks to the “autoinc” option. Bear in mind this only moves the cursor through the FormDB, we now need to put into a variable the value of the current cursor location. For this, we use an ASSIGN statement as usual:

ASSIGN VARIABLE <myFileName global.myRandomFile 1>

This will create a variables named “myFileName“, using the current position of the global.myRandomFile cursor, and using the column 1 (we have only one column in the form DB but we still need to specify it). Then we just need to add that file name to a HTTP GET. Note I’m wrapping this in a loop (named myLoop) that will do 10 iterations of this for each SimUser. The final action list looks like this:

# Create a global cursor (random uniform, autoinc between each assign)
CREATE <global.myRandomFile files random_uniform_autoinc>

# Get a file name from the cursor, first column of the formDB
# Loop 10 times
ASSIGN VARIABLE <myFileName global.myRandomFile 1>
1 get<APPLY myFileName>

In the end, we get a more “spiky” traffic pattern since the file sizes are different and we randomly access them. Here on a 1Gb link:


About acastaner

I'm the EMEA Technical Lead for Application & Security at Spirent. I specialize in layer 4-7 technologies, Cloud, Programming and CyberSecurity.
This entry was posted in Tutorial and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s