我有下面的JSR223采样器,它读取图像,稍微修改它,并发送一个POST multipart/form-data请求。与HTTP采样器相比,我发现它广泛使用了CPU,但我不能使用HTTP采样器,因为它不支持在不保存到文件系统的情况下更改映像。
如果任何人有任何输入来优化JSR223采样器中的脚本,这样它就不会占用大量的CPU,我将很感激。
import org.apache.http.HttpHeaders
import org.apache.http.client.config.RequestConfig
import org.apache.http.client.methods.HttpUriRequest
import org.apache.http.client.methods.RequestBuilder
import org.apache.http.conn.ssl.NoopHostnameVerifier
import org.apache.http.conn.ssl.SSLConnectionSocketFactory
import org.apache.http.conn.ssl.TrustStrategy
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.HttpClients
import org.apache.http.ssl.SSLContextBuilder
import org.apache.http.util.EntityUtils
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.HttpMultipartMode;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.io.ByteArrayOutputStream;
import org.apache.http.entity.ContentType;
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
List<String> sendRequest(String url, String method, String body) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(40000)
.setSocketTimeout(50000)
.build();
BufferedImage image = ImageIO.read(new File("/home/4567/loadtest/Bank.JPG"));
Graphics graphics = image.getGraphics();
graphics.setFont(graphics.getFont().deriveFont(16f));
graphics.drawString("User " + ctx.getThreadNum() + '-' + Math.random() +"; iteration: " + ctx.getVariables().getIteration(), 50, 50);
graphics.dispose();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", bytes);
final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.STRICT);
multipartEntity.addBinaryBody("File", bytes.toByteArray(),ContentType.IMAGE_JPEG, "Bank.JPG");
HttpUriRequest request = RequestBuilder.create(method)
.setConfig(requestConfig)
.setUri(url)
.setHeader("x-ibm-client-id","248a20f3-c39b-45d0-b26a-9019c26e9be8")
.setHeader("X-Client-Id","2861D410-773B-4DD9-AE74-882116B08856")
.setHeader("ResponseMinLatencyMs","45")
.setHeader("ResponseMaxLatencyMs","55")
.setEntity(multipartEntity.build())
.build();
// String req = "REQUEST:" + "User " + ctx.getThreadNum() + "; iteration: " + ctx.getVariables().getIteration() + " " + request.getRequestLine() + "\n";
def builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
});
def trustAllFactory = new SSLConnectionSocketFactory(builder.build(), new NoopHostnameVerifier());
HttpClients.custom().setSSLSocketFactory(trustAllFactory).build().withCloseable { httpClient ->
httpClient.execute(request).withCloseable { response ->
// String res = "RESPONSE:" + "User " + ctx.getThreadNum() + "; iteration: " + ctx.getVariables().getIteration() + " " + response.getStatusLine() + (response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "") + "\n";
// log.info(req + "\n" + res);
// return Arrays.asList(req, res);
response.close()
}
httpClient.close()
}
image.flush()
bytes.flush()
bytes.close()
}
sendRequest("https://test-server.com/upload", "POST", "");
我是Jmeter的新手,正在积极学习。 我想知道JSR223采样器和JSR223预处理器有什么不同,采样器可以和预处理器一样使用吗?
我已经在中获得了记录数,我只需要知道如何才能获得的数据 提前感谢!
我在JSR223采样器中有以下代码,我得到SSL证书错误。有什么办法可以做到禁用吗? JSR223脚本中的问题JSR223采样器,消息:javax.script.scriptException:javax.net.ssl.sslhandShakeException:sun.security.validator.validatoreXception:PKIX路径构建失败
我试图使用JSR223采样器模拟并行ajax请求,如这里提到的https://www.blazemeter.com/blog/how-load-test-ajaxxhr-enabled-sites-jmeter ,我在测试计划中启用了cookie管理器。 任何关于我做错什么的帮助都是很好的。
根据答案,应该将velocity添加到JMeter类路径中,以便发现可用的脚本引擎。 如何在JMeter中添加velocity作为脚本引擎?