Learning center

FAQ

All commonly asked questions are posted here. Questions are classified by gategories to help you quickly access answers - click on a category below. Feel free to contact us if you are not able to find the answer here.

How do I use parameterized data?

Data stores are used to parameterize data in load scripts. You create a data store from a CSV file containing the data you want to use in your load scripts. The CSV file should contain rows with one or more column fields in each row. The column fields should be separated by some separator character or string. You upload your CSV file in the user scenario configuration interface, associating the data store with that user scenario. In this process you also give the data store a name.

Inside your load script you will then be able to use the datastore module functionality to initialize a datastore object by using the datastore.open() and referring to the name of your data store. The datastore object, once initialized, can be used to extract data from your data store.

Data stores are a very convenient way to deal with large amounts of data you might need to access from your load script. One of the most common use cases is that you might have a list with 10,000 usernames and passwords that you want the simulated clients in a load test to use to access restricted content on your site. Entering all these usernames and passwords by hand into your load script would be a time-consuming task, but you might be able to export them to a file in CSV format, allowing you to upload them and create a data store from them.

Example:

Let’s say you have a CSV file called “user_credentials.csv” that looks like this:

 username,password
 john,topsecret
 sally,verysecret
 anne,alsosecret

It contains the usernames and passwords of three users, and you want to use these in your load test. You would then open the user scenario configuration interface, and click on the “+” icon next to the text that says “Selected data store: None”. Here is a screenshot of the relevant part of the screen:

After clicking the “+” icon, the load script code section at the bottom will be hidden and you will instead be shown the data store configuration section that looks like this:

Here you would usually get a list of data stores to choose from, but in this case we have no existing data stores, so the only thing we can do is create a new one by clicking the “New data store” button. That will take you to the data store upload interface that looks like this:

Now you can click on the “Choose file” button. This will let you choose a file on your local computer that you want to upload. This file should, as described a bit earlier here, be a text file in the CSV format. It can be up to a maximum of 50 MB in size. In our example we select our small “user_credentials.csv” file that contains only four rows. Next, we will see this:

Note that the file has not been uploaded yet, but parsed on the client side, via Javascript. The Javascript has found out that the file is 62 bytes in size, and it gives you a preview of the first few lines of data from the file. In our case, the file is so small that the preview shows all of it, but most of the time your CSV files are probably going to be quite large. The preview shows you what data your file contains, and also how it is going to be parsed when it is uploaded. On the screenshot above you can see that we will get four rows, with two columns in each row. However, we are not so interested in including the first row from the file – the one that says “username” and “password”. Those are just the column names, not actual login credentials that we can use. So we want to get rid of them, and we can do that by clicking the “+” icon next to the text “File parsing options”. This is what we get then:

Note that with these extra options you can change the field seperator character to be something other than the comma character, for example it is quite common that CSV files have semicolon as field separator. You can also specify what character is used to quote string values inside the CSV file (“Text delimiter”). Finally, you also have an option to start parsing the CSV file at some specific row (“Use data from line”). This setting defaults to line 1 – i.e. start using data from the first line of the CSV file. In our case we want to start using data from line #2 of the CSV file, and in the screenshot above we have just changed this parameter to “2”, which is why the preview now only shows the last three lines from the file.

When we are done setting file parsing options we click the “Upload” button, which starts the upload of the CSV file. If the file is large, the upload may take a little while. When the upload is done, the system will start converting the data into an internal format so it can be used in load tests. This can also take a little while (up to several minutes) if the file is large. When everything is done you will see a new data store object available to your user scenario:

Now, you just have to click the “Select” button to associate your data store with the current user scenario, then you can close the data store selection interface by clicking the “-” icon next to the “Selected data store” text. That will return you to the standard user scenario configuration interface, allowing you to start writing load script code to use data from your data store.

In your load script, you could then use the following code:

 -- Initialize data store
 local ds = datastore.open("My Data Store")
 -- Get a random row from data store
 local row = ds:get_random()
 -- The row is a table (array). Extract username field from it
 local username = row[1]
 -- ...and password field
 local password = row[2]
 -- Issue a HTTP POST request to login this user on our site
 http.post("http://my.dom.ain/login.aspx", nil, nil, 
               "username=" .. username .. "&password=" .. password)

See also: - The Load Impact load script tutorial
 - The Load Impact load script API – data store module


Permalink