How to Load Test SMB/CIFS with JMeter
In this article, we will discuss two ways to get files via the SMB/CIFS protocol through Apache JMeter™.
What is SMB/CIFS?
SMB (Server Message Block) is a typical client-server protocol that allows a client application to perform operations - like reading, writing and deleting - to a shared resource, by sending requests to the server. CIFS (Common Internet File System) is a protocol based on SMB and we can say that it is one of SMB’s versions. But unlike SMB, the main transport for CIFS is TCP protocol. Without going into the technical details, CIFS supports backward compatibility, i.e. both protocols work fine with each other.
In this blog post we will explain 2 ways of load testing SMB in JMeter:
- JSR223 Sampler + Java library
- OS Sampler + 3rd party apps
We will show how to upload and download to and from the SMB storage.
JSR223 Sampler and 3rd Party Libraries
Let us start with the more complex and more modifiable version of the two - JSR223 Sampler with jcifs lib. JCIFS is an open source client library that implements the CIFS/SMB networking protocol and is the most used java library to work with these protocols.
1. Download the JCIFS library and drop it to the /lib folder.
2. Groovy is the programming language we are going to use, because it showed the best performance results in comparison with other candidates.
Download the groovy library and put it in the same location if JMeter is not using the latest version, and Restart JMeter.
3. Add a Thread Group
4. Add a JSR223 Sampler. Choose Groovy Language and set the Caching checkbox.
Right Click on Thread group -> Sampler -> JSR223 Sampler
Add a code that will download a file from the directory of the SMB storage you are testing.
Let’s analyze this code:
- First we specify the server address and the path to the file, as well as the authorization data.
- After that, we specify the file in which we need to write the downloaded information (if the file is not present, it will be created).
- We open two streams: one for writing and one for reading.
There may be a situation in which we will need to get all the files from a specific folder. To do that, we should get a list of files from the directory and in the loop (that is in the code) perform the action on the necessary files. ‘*’ is wildcard.
You can also save the necessary data to the sampler response tab in JMeter by using SampleResult.setResponseData(VarWithResults). For example, we can calculate the downloading time using one kludge: time of the last modification of the file - time of file creation = time of file download (approximately).
1. If you do not need authorization to access the server, you need to pass ‘null’ as login and password parameters.
2. If everything is loaded too slowly, then you need to change the server's resolving mode to DNS. In the constructor, add the following:
By this, we specify that the server name will be resolved via DNS. Naturally, if you do not have a local DNS server in your network that will resolve the names of local machines, then the mechanism must be changed to another one. The choice of the mechanisms of resolving will be in the order that is specified in the config file.
3. jcifs.smb.client.ssnLimit - this parameter contains the number of sessions that can be opened over the same transport. The default value is 250. But this can affect the throughput of requests. Reduce this number to 30, for instance.
4. To parameterize file paths you can use CSV Data Set Config.
5. Download the file yourself before running your code. If the download time is very different, then you need to change the connection configuration.
OS Process Sampler and 3rd Party Applications
Another way to upload or download files is to use third-party applications. JMeter has an OS Process Sampler that can be used to execute commands on a local machine. For instance, it allows the execution of any command that can be run from the command line.
In Linux, you can use utilities such as smbget and smbclient. Let us consider smbget, which can be used to download files. You can familiarize all the parameters of the tool on the documentation page. We will use the following:
- -a, --guest Connect as a guest. Used when there is no authorization on the server.
- -R, --recursive This means that you need to download files recursively, i.e. all files in subfolders with corresponding structure of these directories.
- -u, --username = STRING Username
- -p, --password = STRING Password
- -w, --workgroup = STRING Workgroup name
- -n, --nonprompt Do not ask anything. Because we cannot answer the request.
Accordingly, the following command logs in to server "192.168.1.1" as Guest, downloads the README.txt file which is located in "Elements" network resource to the current directory (the directory where the command was executed):
The following command can be used to download the entire ‘elements’ catalog as a user with dev:pwd123 credentials. The ‘Elements’ folder will not be created, each file will be downloaded to the current directory:
The OS Process Sampler configuration will look like this:
- In the Command field, you need to specify the name of the tool - smbget in our case.
- The Working directory is the directory where the command will be executed and the place where the file will be saved.
- After that, the entire command is divided into separate command parameters in Command parameters table. The separator for parameters is a space.
- You also need to set Сheck Return Code checkbox with the value 0. If the tool has completed the operation in the console, the sampler execution will be marked as successful, even if specified file was not found in the storage or the file was not written to the disk. In these cases, the return code will be 1, but if everything is downloaded and written, which is what we need, the code will be 0.
As you can see, the file was downloaded and located in the /bin/ folder. In the response tab, you can see the result of the command. If you need something from this tab, you can extract the data or save the response.
You can familiarize yourself with all the parameters of the command on the documentation page.
We are interested in the following parameters:
- [-Path] <String > - The path to the file that you want to download.
- [[-Destination] <String>] - The path to the directory for saving.
- [-Recurse] - Means that you need to download files recursively, i.e. all files in subdirectories with preservation of the structure of these directories.
- [-Credential <PSCredential>] - Credentials for authorization. If they are not provided, the smb client tries to login using the credentials of the active Windows account.
The following command will copy the file or folder Test_CopyItem to \\DC01\C$ directory. If it is a folder, its content will not be copied. The credentials of the Windows user will be used for authorization.
If we use the command below, all the folder content will be copied, because we added -Recurse flag. The user will log in by using the specified credentials, because we added -Credential flag.
The configuration of OS Process Sampler is almost identical to the previous one, but first we need to run PowerShell. This command is also divided into parameters.
In this blog post, we looked at two ways to get files using SMB: JSR223 + third-party libraries and OS Process Sampler + third-party tools. The first method is more modifiable, for example, we can extract data from the file directly in the code, but it requires knowledge of programming and sometimes bizarre decision-making like our download time calculation. The second one is easier and can provide additional information about the download, but it depends on tools that are used. But for example, to read the file, we will have to use more JMeter elements for extracting data.
Learn more advanced JMeter from our free JMeter academy.
Get scalability, advanced reporting, multiple geo-locations and other SaaS advantages by running your JMX script in BlazeMeter. To try us out, request a demo, or put your URL in the box below and your test will start in minutes.