I have a jmx script which makes jsch connection and upload files in parallel using ultimate thread group with one user with below configuration and provide output as well
Start Thread count - 5 Start up delay - 600 secs Hold load for - 1800 secs
import com.jcraft.jsch.*;
import java.io.*;
class Monitor implements SftpProgressMonitor{
//Progress monitoring code
}
def jsch = new Jsch()
def session = jsch.getSession("xyz", "xyz", "xyz")
session.setPassword("abc")
def sftpSession = session.connect()
def channel = session.openChannel("sftp")
channel.connect();
def channelSftp = (ChannelSftp)channel;
channelSftp.cd("xyz");
def f1 = new File("Test.txt");
channelSftp.put(new java.io.FileInputStream(f1), f1.getName()+Math.random(), new Monitor(SampleResult));
session.disconnect();
Now is there any way to do the same thing with multiple different users taking some thread out of ultimate start thread count instead for only 1 user taking all threads like running 5 different users concurrently taking 2 threads out of 10 start threads?
Normally people use CSV Data Set Config for parameterization, if you create a CSV file named users.csv
looking like:
username
xyz
xyz1
xyz2
etc.
and add it to your JSR223 Sampler like this:
once you change this line:
def session = jsch.getSession("xyz", "xyz", "xyz")
to this one:
def session = jsch.getSession(vars.get("username"), "xyz", "xyz")
each JMeter thread (virtual user) on each iteration will take the next line from the CSV file and send the new username.
In the above example vars
stands for JMeterVariables class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy for more information on this and other JMeter API shorthands available for the JSR223 Test Elements.
Also there is jmeter-ssh-sampler plugin which adds SSH and SFTP protocols support to JMeter so you won't have to write the code and will be able to use GUI