jmeter除了可以做http测试,还支持tcp长连接

图中的Ramp-Up Period需要注意,它表示启动所有线程花费的时间,如图所示,设置为40秒,jmeter会自动计算每秒应该启动多少个线程。

设置thinktime,即每个客户端两次请求之间的时间间隔

发送tcp请求,注意End of line,如果不设置,jmeter会一直读取流,最后认为请求失败,response code 500,所有的结果都会被标记为错误。10是byte值,代表换行,即 \n

自定义响应是否正确,比较字节数会高效一些

显示每个断言的结果,如果断言为false,会显示错误原因,一般用于debug

显示所有请求记录,可以查看响应,便于排查错误

最后是测试报告

/*

* Licensed to the Apache Software Foundation (ASF) under one or more

* contributor license agreements. See the NOTICE file distributed with

* this work for additional information regarding copyright ownership.

* The ASF licenses this file to You under the Apache License, Version 2.0

* (the "License"); you may not use this file except in compliance with

* the License. You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*

*/

/*

* TCP Sampler Client implementation which reads and writes binary data.

*

* Input/Output strings are passed as hex-encoded binary strings.

*

*/

package org.apache.jmeter.protocol.tcp.sampler;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.InterruptedIOException;

import java.io.OutputStream;

import java.net.SocketTimeoutException;

import org.apache.commons.io.IOUtils;

import org.apache.jmeter.util.JMeterUtils;

import org.apache.jorphan.logging.LoggingManager;

import org.apache.jorphan.util.JOrphanUtils;

import org.apache.log.Logger;

/**

* TCPClient implementation.

* Reads data until the defined EOM byte is reached.

* If there is no EOM byte defined, then reads until

* the end of the stream is reached.

* The EOM byte is defined by the property "tcp.BinaryTCPClient.eomByte".

*

* Input data is assumed to be in hex, and is converted to binary

*/

public class BinaryTCPClientImpl extends AbstractTCPClient {

private static final Logger log = LoggingManager.getLoggerForClass();

private static final int eomInt = JMeterUtils.getPropDefault("tcp.BinaryTCPClient.eomByte", 1000); // $NON_NLS-1$

public BinaryTCPClientImpl() {

super();

setEolByte(eomInt);

if (useEolByte) {

log.info("Using eomByte=" + eolByte);

}

}

/**

* Convert hex string to binary byte array.

*

* @param hexEncodedBinary - hex-encoded binary string

* @return Byte array containing binary representation of input hex-encoded string

* @throws IllegalArgumentException if string is not an even number of hex digits

*/

public static final byte[] hexStringToByteArray(String hexEncodedBinary) {

if (hexEncodedBinary.length() % 2 == 0) {

char[] sc = hexEncodedBinary.toCharArray();

byte[] ba = new byte[sc.length / 2];

for (int i = 0; i < ba.length; i++) {

int nibble0 = Character.digit(sc[i * 2], 16);

int nibble1 = Character.digit(sc[i * 2 + 1], 16);

if (nibble0 == -1 || nibble1 == -1){

throw new IllegalArgumentException(

"Hex-encoded binary string contains an invalid hex digit in '"+sc[i * 2]+sc[i * 2 + 1]+"'");

}

ba[i] = (byte) ((nibble0 << 4) | (nibble1));

}

return ba;

} else {

throw new IllegalArgumentException(

"Hex-encoded binary string contains an uneven no. of digits");

}

}

/**

* Input (hex) string is converted to binary and written to the output stream.

* @param os output stream

* @param hexEncodedBinary hex-encoded binary

*/

public void write(OutputStream os, String hexEncodedBinary) {

try {

os.write(hexStringToByteArray(hexEncodedBinary));

os.flush();

} catch (IOException e) {

log.warn("Write error", e);

}

log.debug("Wrote: " + hexEncodedBinary);

return;

}

/**

* {@inheritDoc}

*/

public void write(OutputStream os, InputStream is) {

throw new UnsupportedOperationException(

"Method not supported for Length-Prefixed data.");

}

/**

* Reads data until the defined EOM byte is reached.

* If there is no EOM byte defined, then reads until

* the end of the stream is reached.

* Response data is converted to hex-encoded binary

* @return hex-encoded binary string

*/

public String read(InputStream is) {

byte[] buffer = new byte[4096];

ByteArrayOutputStream w = new ByteArrayOutputStream();

int x = 0;

try {

while ((x = is.read(buffer)) > -1) {

w.write(buffer, 0, x);

if (useEolByte && (buffer[x - 1] == eolByte)) {

break;

}

}

} catch (SocketTimeoutException e) {

// drop out to handle buffer

} catch (InterruptedIOException e) {

// drop out to handle buffer

} catch (IOException e) {

log.warn("Read error:" + e);

return "";

}

IOUtils.closeQuietly(w); // For completeness

final String hexString = JOrphanUtils.baToHexString(w.toByteArray());

log.debug("Read: " + w.size() + "\n" + hexString);

return hexString;

}

}

https://my.oschina.net/enyo/blog/833279

https://blog.csdn.net/ccfeng2008/article/details/50375100

java tcp链接慢_jmeter tcp长连接性能测试相关推荐

  1. tcp、http协议的长连接和短连接

    转载:http://www.cnblogs.com/onlysun/p/4520553.html 当网络通信时采用TCP协议时,在真正的读写操作之前,server与client之间必须建立一个连接,当 ...

  2. java 服务器长链接_Java如何实现长连接

    实现原理: 长连接的维持,是要客户端程序,定时向服务端程序,发送一个维持连接包的. 如果,长时间未发送维持连接包,服务端程序将断开连接. 客户端: Client通过持有Socket的对象,可以随时(使 ...

  3. jmeter tcp长连接性能测试

    jmeter除了可以做http测试,还支持tcp长连接 图中的Ramp-Up Period需要注意,它表示启动所有线程花费的时间,如图所示,设置为40秒,jmeter会自动计算每秒应该启动多少个线程. ...

  4. 游戏消息服务器长链接,游戏服务器匹配 长连接

    游戏服务器匹配 长连接 内容精选 换一换 目录 前言 1.常见游戏模块 2.开发语言与项目构建发布 3.JAVA游戏服务器,需要掌握的技术 4.总结 点赞在看,养成习惯 前言 <摩尔庄园> ...

  5. java comet_用java实现comet,基于 HTTP长连接的实现,用于从服务端实时发送信息到客户端...

    http://homelink.javaeye.com/blog/293328#comments 参考文档 http://www.ibm.com/developerworks/cn/web/wa-lo ...

  6. JAVA网络编程Socket常见问题 【长连接专题】

    一. 网络程序运行过程中的常见异常及处理 第1个异常是 java.net.BindException:Address already in use: JVM_Bind. 该异常发生在服务器端进行new ...

  7. linux拒绝tcp链接,Linux 内核 TCP SACK 拒绝服务问题

    上次更新时间:太平洋夏令时 2019 年 6 月 18 日上午 11:45 CVE 标识符:CVE-2019-11477.CVE-2019-11478.CVE-2019-11479 这是此问题的更新信 ...

  8. java memcachedclient_Java memcached client怎样建立长连接

    摇曳的蔷薇 package com.ghj.packageofclient;import java.util.Date;import junit.framework.TestCase;import c ...

  9. 网络:tcp长连接与短连接

    当网络通信采用tcp协议时,在真正的读写操作之前,sever与client之间必须建立一个连接,当读写操作完成之后,对方不再需要这个连接时他们可以释放这个链接,连接的连接需要三次握手,释放需要四次握手 ...

最新文章

  1. 手把手教你学Kotlin (1): JetBrains的Kotlin Educational Tool下载、安装和 Kotlin Koans的安装和使用
  2. SpringBoot2.0配置redis相关
  3. animated bar chart race下载_下载腾讯会议
  4. 你如果只是一直囤干货,那永远不可能进步
  5. 打印N个数组整体最大的TopK
  6. 【集合之HashMap】HashMap实现原理及非线程安全原因
  7. 通过调试获得SAP Fiori gateway系统的系统ID
  8. 为什么嵌入式工程师会对8位MCU有误解?
  9. argparser_Java命令行界面(第22部分):argparser
  10. java 偏向锁 怎么用_Java锁升级、偏向锁、轻量级锁
  11. JAVA SAX解析XML文档
  12. WebAssembly系列1-从 ASM.JS 到 WebAssembly
  13. 2021-09-09321. 拼接最大数 单调栈
  14. 用C语言来写斐波那契数列
  15. tomcat设置一级域名、二级域名访问指定项目
  16. Android 应用瘦身
  17. c# opengl tao
  18. 英文间隔符占位html,HTML空格占位
  19. CORBA协议相关的概念
  20. 版本管理-SVN分支,合并,切换

热门文章

  1. Linux之HugePages快速配置
  2. Linux IPTables:如何添加防火墙规则
  3. 想做DBA,多租户管理你一定要知道这些
  4. 【华为云技术分享】Linux内核编程环境 (2)
  5. 揪出MySQL磁盘消耗迅猛的真凶
  6. ProjectMan是这样炼成的
  7. 3dmax标注尺寸插件_抖音最火CAD插件教程汇总
  8. etc php5 conf.d,php – nginx:[emerg]“location”指令不允许在/etc/nginx/conf.d/default.conf中使用:...
  9. 基于序贯重要性重采样的粒子滤波and(RBPF)
  10. WORD 表格后面的空白页删不掉?