使用 jMeter 对 SFTP 服务器进行性能测试
Performance Testing of SFTP server using jMeter
我需要在 SFTP 服务器上对 upload/download 的某些场景进行测试。为此,我正在使用 apache JMeter 插件 SSH 协议支持。我能够为单个用户测试单个文件上传。我正在努力执行场景,例如使用此插件为单个用户上传多个文件或为多个用户上传多个文件。
知道是否有任何其他插件可以实现此目的或任何其他方式吗?
自定义采样器代码
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()
在 apache 服务器的 GUI 模式下工作正常,但是当 运行 在 linux 框或无头方式上时,它会出现以下错误。
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
关于如何解决这个问题的任何帮助?
您不能通过单个 SFTP 连接一次传递多个文件,多个文件需要排队。
但是,您可以通过单个用户或不同用户打开多个连接,只需确保正确参数化凭据和文件 names/locations。
例如:
- 凭据可以使用 CSV Data Set Config
参数化
- 可以使用 Directory Listing Config
参数化文件
我需要在 SFTP 服务器上对 upload/download 的某些场景进行测试。为此,我正在使用 apache JMeter 插件 SSH 协议支持。我能够为单个用户测试单个文件上传。我正在努力执行场景,例如使用此插件为单个用户上传多个文件或为多个用户上传多个文件。 知道是否有任何其他插件可以实现此目的或任何其他方式吗?
自定义采样器代码
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()
在 apache 服务器的 GUI 模式下工作正常,但是当 运行 在 linux 框或无头方式上时,它会出现以下错误。
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
关于如何解决这个问题的任何帮助?
您不能通过单个 SFTP 连接一次传递多个文件,多个文件需要排队。
但是,您可以通过单个用户或不同用户打开多个连接,只需确保正确参数化凭据和文件 names/locations。
例如:
- 凭据可以使用 CSV Data Set Config 参数化
- 可以使用 Directory Listing Config 参数化文件