Jmeter压测Netty or TCP 详细步骤

下载软件

https://jmeter.apache.org/download_jmeter.cgi

创建Tcp测试用例

添加Thread group

image.png

添加Tcp请求样本

image.png

设置tcp相关参数

image.png

send java: ${javaNumber} send beanshell: ${RANDOM_STRING} send function ${__Random(1,100000000000, LOTTERY )} ?

Java Netty收到的结果

send java: 9 send beanshell: zltaz05321dmishm9dpiu26lsf0ntl6hhg3o send function 1090222003 ?

发送Byte形式

6801153532343330303031303034303030303801010002000601022690011B4C7D

image.png

设置发送的内容

  • 发送的内容可以参数化。可以使用内置的参数,或者在 BeanShellPreProcessor定义相关参数
  • BeanShell 也可以支持直接引用java代码。下面是两种引用的方式,把java运行的结果放到 发送的文本框即可。

image.png

BeanShell引用java代码方式一

addClassPath("C:\\");

import JmeterTest;

int c = new JmeterTest().testAdd(3,4);

vars.put("javaNumber" , c.toString());

BeanShell引用java代码方式二

source("C:\\JmeterTest.java");

int c = new JmeterTest().testAdd(3,6);

vars.put("javaNumber" , c.toString());

用Beanshell语法

import java.util.Random;

chars = "1234567890abcdefghiklmnopqrstuvwxyz-";
int string_length = 36;
randomstring ="";

for (int i=0; i < string_length; i++) {
  Random randomGenerator = new Random();
  int randomInt = randomGenerator.nextInt(chars.length());
  randomstring += chars.substring(randomInt,randomInt+1);
}
print(randomstring);
vars.put("RANDOM_STRING",randomstring);

TCPclient className说明

The class names, as they are given in the JMeter documentation, are:

  • TCPClientImpl - this is a basic class for implementation of the text messages exchange. Text messages are provided as a constant or variable strings of different charsets in the ‘Text to send’ field of the TCP sampler.
  • BinaryTCPClientImpl - this is a class for the implementation of the exchange of the text messages. Binary messages in the form of the hex encoded constant or variable values are provided in the ‘Text to send’ field of the TCP sampler.
  • LengthPrefixedBinaryTCPClientImpl - this class is similar to the previous one, but byte data to send is prefixed with the binary length byte.

参考文章

https://jmeter.apache.org/usermanual/functions.html

https://www.blazemeter.com/blog/quick-guide-jmeter-preprocessors

https://dzone.com/articles/how-to-load-test-tcp-protocol-services-with-jmeter

https://www.cnblogs.com/puresoul/p/4949889.html

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值