Search code examples
sshpluginsjmetersftpjmx

Performance Testing of SFTP server using jMeter


I need to perform testing of certain scenarios of upload/download on SFTP server. For that i am using apache JMeter plugin SSH protocol support. I am able to test single file upload for a single user. I am struggling to perform scenarios such as Multiple file upload for single user OR Multiple file upload for multiple users using this plugin. Any idea if there is any other plugin in order to achieve this or any alternative way?

Custom sampler code

import com.jcraft.jsch.*;
import java.io.*;

def jsch = new JSch()
def session = jsch.getSession(${__property(loginUserName)}, ${__property(hostURL)}, ${__property(port)}) 
session.setConfig("StrictHostKeyChecking", "no")
session.setPassword(${__property(loginUserPassword)})
def sftpSession = session.connect()
def channel = session.openChannel("sftp")
channel.connect();
def channelSftp = (ChannelSftp)channel;
log.info("SFTP Connection with host is acquired" + channelSftp)
channelSftp.cd(${__property(sftpDestinationFolder)});
for(i = 0; i <100; i++){
    def f1 = new File(${__property(inputFileLocationOfBigFile)});
    channelSftp.put(new java.io.FileInputStream(f1), f1.getName()+i);
}
session.disconnect()

Working fine on GUI mode of apache server but when running on the linux box or headless way it gives the below error.

2020-03-18 03:25:28,918 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 4: unable to resolve class JSch 
 @ line 4, column 12.
   def jsch = new JSch()
              ^

Script1.groovy: 12: unable to resolve class ChannelSftp 
 @ line 12, column 19.
   def channelSftp = (ChannelSftp)channel;
                     ^

2 errors

javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 4: unable to resolve class JSch 
 @ line 4, column 12.
   def jsch = new JSch()
              ^

Script1.groovy: 12: unable to resolve class ChannelSftp 
 @ line 12, column 19.
   def channelSftp = (ChannelSftp)channel;
                     ^

2 errors

    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.compile(GroovyScriptEngineImpl.java:183) ~[groovy-all-2.4.13.jar:2.4.13]
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:215) ~[ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:69) [ApacheJMeter_java.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250) [ApacheJMeter_core.jar:4.0 r1823414]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 4: unable to resolve class JSch 
 @ line 4, column 12.
   def jsch = new JSch()
              ^

Script1.groovy: 12: unable to resolve class ChannelSftp 
 @ line 12, column 19.
   def channelSftp = (ChannelSftp)channel;
                     ^

2 errors

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) ~[groovy-all-2.4.13.jar:2.4.13]
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958) ~[groovy-all-2.4.13.jar:2.4.13]
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605) ~[groovy-all-2.4.13.jar:2.4.13]
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554) ~[groovy-all-2.4.13.jar:2.4.13]
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) ~[groovy-all-2.4.13.jar:2.4.13]
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) ~[groovy-all-2.4.13.jar:2.4.13]
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254) ~[groovy-all-2.4.13.jar:2.4.13]
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:211) ~[groovy-all-2.4.13.jar:2.4.13]
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getScriptClass(GroovyScriptEngineImpl.java:331) ~[groovy-all-2.4.13.jar:2.4.13]
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.compile(GroovyScriptEngineImpl.java:181) ~[groovy-all-2.4.13.jar:2.4.13]
    ... 6 more
2020-03-18 03:25:28,927 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2020-03-18 03:25:28,927 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1

Any help on how to resolve this?


Solution

  • You cannot pass more than one file at a time over single SFTP connection, multiple files need to be queued up.

    You can however open several connections by a single user or with different users, just make sure to properly parameterize the credentials and file names/locations.

    For example: