我有一个上传1.5 Gb文件的场景,我使用分布式jmeter测试。I.e请求数据对我的测试没有意义,所以我不希望将post数据从slave(代理(jmeter传输到master(服务器(。然而,在beanshell后处理器中,我还没有找到任何API来从http采样器中删除原始post数据。
https://jmeter.apache.org/api/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.html#setPostBodyRaw-boolean-似乎不是这样。那么,如何从Jmeter中的采样器中去除大量的后置数据,以使分布式测试工作更加稳健呢?
- 默认情况下,JMeter不应将POST数据从从属服务器传输到主服务器。如果它确实仔细检查了您的结果文件配置,并确保
jmeter.save.saveservice.output_format
设置为csv
,并且您只存储那些绝对需要的度量
仅供参考:您看到的函数错误,如果您想以编程方式从"文件上传"部分删除文件,则需要执行类似sampler.setHTTPFiles(new HTTPFileArg[0]);
的操作
请注意,此更改后,您的文件上载将停止工作。
- 从JMeter 3.1开始,建议使用JSR223测试元素和Groovy语言进行脚本编写,主要是因为Groovy的性能比其他脚本语言好得多,所以今后一定要使用Groovy
SO,我不知道如何从jmeter从机到主通信中排除post数据;我必须编写自己的JSR-223 Sampler,它使用HttpConnection类来执行名为form Java代码的http请求,然后操纵Java代码中的示例数据。Http采样器对我不起作用。
这种采样器很好,因为它还允许使用Input/OutputStreams和缓冲区读取文件并将其发送到http post-body,因此我们不再需要HttpSampler用来分配的整个上传文件的内存。
示例采样器代码为:
import java.net.HttpURLConnection;
HttpURLConnection httpConn = null;
String line = null;
try {
URL url = new URL("http://${url}/api/v2.0/datasets");
URLConnection urlConn = url.openConnection();
if (!(urlConn instanceof HttpURLConnection)) {
throw new IOException ("URL is not an Https URL");
}
httpConn = (HttpURLConnection)urlConn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Connection", "keep-alive");
httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=boundary");
httpConn.setRequestProperty("User-Agent", "Apache-HttpClient/4.5.5 (Java/1.8.0_161)");
httpConn.setReadTimeout(500 * 1000);
httpConn.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(
httpConn.getOutputStream());
out.write("--boundaryrn");
out.write("Content-Disposition: form-data; name="name"rn");
out.write("Content-Type: text/plain; charset=US-ASCIIrn");
out.write("Content-Transfer-Encoding: 8bitrn");
out.write("rn");
out.write("dataset${__time}rn");
out.write("--boundaryrn");
out.write("Content-Disposition: form-data; name="token"rn");
out.write("Content-Type: text/plain; charset=US-ASCIIrn");
out.write("Content-Transfer-Encoding: 8bitrn");
out.write("rn");
out.write("${user_token}rn");
out.write("--boundaryrn");
out.write("Content-Disposition: form-data; name="sep"rn");
out.write("Content-Type: text/plain; charset=US-ASCIIrn");
out.write("Content-Transfer-Encoding: 8bitrn");
out.write("rn");
out.write("${separator}rn");
out.write("--boundaryrn");
out.write("Content-Disposition: form-data; name="csv_file"; filename="filename.csv"rn");
out.write("Content-Type: text/plainrn");
out.write("Content-Transfer-Encoding: binaryrn");
out.write("rn");
out.write("rn");
String filepath="files//${datasetFileName}";
File file = new File(filepath);
FileInputStream fileInputStream = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fileInputStream);
BufferedReader fin =
new BufferedReader(isr);
String bufString;
while ((bufString = fin.readLine()) != null) {
out.write(bufString+"rn");
}
out.write("--boundary--");
out.flush();
out.close();
InputStream _is;
log.info(""+httpConn.getResponseCode());
SampleResult.setResponseCode(httpConn.getResponseCode()+"");
if (httpConn.getResponseCode() >= 400) {
_is = httpConn.getErrorStream();
SampleResult.setSuccessful(false);
} else {
/* error from server */
_is = httpConn.getInputStream();
}
if (_is!=null)
{
BufferedReader in =
new BufferedReader(
new InputStreamReader(_is)
);
String decodedString;
String accumulate="";
while ((decodedString = in.readLine()) != null) {
accumulate=accumulate+"n"+decodedString;
log.info(decodedString);
}
SampleResult.setResponseData(accumulate);
}
else
{
SampleResult.setResponseData("No data from server");
}
}
catch (MalformedURLException e) {
e.printStackTrace();
log.info(e.getMessage());
} catch( SocketTimeoutException e){
e.printStackTrace();
log.info(e.getMessage());
}
finally {//httpConn.disconnect();
}