Jmeter压测Netty or TCP 详细步骤

本文介绍了如何使用JMeter进行TCP协议的性能测试。首先,从官方下载页面获取JMeter,然后创建TCP测试用例,添加线程组和TCP请求样本。接着,详细设置了TCP请求的相关参数,包括发送的内容,如使用内置变量、BeanShell脚本进行参数化。文中还展示了如何通过BeanShell引用Java代码,生成随机字符串,并发送不同格式的数据,如Byte形式。最后,提到了TCPClient的实现类选择,并提供了相关的参考链接以供深入学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载软件

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

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值