jmeter tcp sampler 测试网速

1 下载Jmeter

https://mirror-hk.koddos.net/apache//jmeter/

2 开启Jmeter

3 添加线程组

4添加 TCP sampler

5添加View Tree

设置1个线程不断循环 

6设置线程组  

7设置Tcp sampers

 设置eolvalue=9,十进制,当tcp sampler 接收到服务器回复字节9的时候,开启下一次循环。发送21,539 字节。

 8开启测试

点击绿色三角形开始发送,点stop六边型停止

9服务器端java代码入下 

package com.suncreate.testSocket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
import java.util.Arrays;
public class SocketServer {
    public static void main(String[] args) throws Exception {
        // 监听指定的端口
        int port = 55533;
        ServerSocket server = new ServerSocket(port,50, InetAddress.getByAddress(new byte[]{(byte)172,16,37,(byte)162}));
        System.out.println("waiting");
        Socket socket = server.accept();
        // 建立好连接后,从socket中获取输入流,并建立缓冲区进行读取
        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream=socket.getOutputStream();
        byte[] bytes = new byte[1024];
        int len=0,total=0;
        long second=0,start=System.currentTimeMillis();
        while ((len = inputStream.read(bytes)) != -1) {       
            System.out.println(len);
            total+=len;
            second= (System.currentTimeMillis()-start)/1000;
            if(second!=0)
                System.out.println(total/second);       
            System.out.println("----------------------------------------");
            outputStream.write(new byte[]{1,2,3,4,5,6,7,8,0x09});
            outputStream.flush();
        }
        outputStream.close();
        inputStream.close();
        socket.close();
        server.close();
    }
}

10服务器输出如下

1024
24643128
----------------------------------------
1024
24643242
----------------------------------------
1024
24643356
----------------------------------------
1024
24643470
----------------------------------------
1024
24643584
----------------------------------------
1024
24643697
----------------------------------------
1024
24643811
----------------------------------------
1024
24643925
----------------------------------------
1024
24644039
----------------------------------------
1024
24644152
----------------------------------------
1024
24644266
----------------------------------------
1024
24644380
----------------------------------------
1024
24644494
----------------------------------------
1024
24644608
----------------------------------------
1024
24644721
----------------------------------------
1024
24644835
----------------------------------------
1024
24644949
----------------------------------------
1024
24645063
----------------------------------------
1024
24645176
----------------------------------------
1024
24645290
----------------------------------------
1024
24645404
----------------------------------------
1024
24645518
----------------------------------------
1024
24645632
----------------------------------------
1024
24645745
----------------------------------------
1024
24645859
----------------------------------------
1024
24645973
----------------------------------------
1024
24646087
----------------------------------------
1024
24646200
----------------------------------------
1024
24646314
----------------------------------------
1024
24646428
----------------------------------------
1024
24646542
----------------------------------------
1024
24646656
----------------------------------------
1024
24646769
----------------------------------------
1024
24646883
----------------------------------------
1024
24646997
----------------------------------------
1024
24647111
----------------------------------------
1024
24647224
----------------------------------------
1024
24647338
----------------------------------------
1024
24647452
----------------------------------------
1024
24647566
----------------------------------------
1024
24647680
----------------------------------------
1024
24647793
----------------------------------------
1024
24647907
----------------------------------------
1024
24648021
----------------------------------------
1024
24648135
----------------------------------------
1024
24648248
----------------------------------------
1024
24648362
----------------------------------------
1024
24648476
----------------------------------------
1024
24648590
----------------------------------------
1024
24648704
----------------------------------------
1024
24648817
----------------------------------------
1024
24648931
----------------------------------------
1024
24649045
----------------------------------------
1024
24649159
----------------------------------------
1024
24649272
----------------------------------------
1024
24649386
----------------------------------------
1024
24649500

代码修改:

package com.suncreate.testSocket;


import io.netty.util.concurrent.Promise;
import io.netty.util.concurrent.SingleThreadEventExecutor;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
import java.util.Arrays;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadFactory;

public class SocketServer2 {
    public static void main(String[] args) throws Exception {
        // 监听指定的端口
        int port = 55533;
        ServerSocket server = new ServerSocket(port,50, InetAddress.getByAddress(new byte[]{(byte)172,16,37,(byte)162}));
        // SocketAddress socketaddress=new InetSocketAddress("172.16.37.162");
        // server.bind(socketaddress);
        // server将一直等待连接的到来
        System.out.println("server将一直等待连接的到来");
        Socket socket = server.accept();
        // 建立好连接后,从socket中获取输入流,并建立缓冲区进行读取

        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream=socket.getOutputStream();

        // 必须
        byte[] bytes = new byte[1024*10];
        int len=0,total=0;
        long second = 0, start = System.currentTimeMillis();
        while(true)
        {

            while ((len = inputStream.read(bytes)) != -1) {   
                        total += len;
              System.out.println("------------------");
                if(total>14785*3-100)
                    break;
            }
            System.out.println("++++++++++++++++++");
            second = (System.currentTimeMillis() - start) / 1000;
            outputStream.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 0x09});
            outputStream.flush();

            if(second!=0) {
                System.out.println(second);
                System.out.println(total);
                System.out.println(total / second);
            }
        }
    }
}

++++++++++++++++++
19
1641802368
86410650
------------------
++++++++++++++++++
19
1641812608
86411189
------------------
++++++++++++++++++
19
1641822848
86411728
------------------
++++++++++++++++++
19
1641833088
86412267
------------------
++++++++++++++++++
19
1641843328
86412806
------------------
++++++++++++++++++
19
1641853568
86413345
------------------
++++++++++++++++++
19
1641863808
86413884
------------------
++++++++++++++++++
19
1641874048
86414423
------------------
++++++++++++++++++
19
1641884288
86414962
------------------
++++++++++++++++++
19
1641894528
86415501
------------------
++++++++++++++++++
19
1641904768
86416040
------------------
++++++++++++++++++
19
1641915008
86416579
------------------
++++++++++++++++++
19
1641925248
86417118
------------------
++++++++++++++++++
19
1641935488
86417657
------------------
++++++++++++++++++
19
1641945728
86418196
------------------
++++++++++++++++++
19
1641955968
86418735
------------------
++++++++++++++++++
19
1641966208
86419274
------------------
++++++++++++++++++
19
1641976448
86419813
------------------
++++++++++++++++++
19
1641986688
86420352
------------------
++++++++++++++++++
19
1641996928
86420890
------------------
++++++++++++++++++
19
1642007168
86421429
------------------
++++++++++++++++++
19
1642017408
86421968
------------------
++++++++++++++++++
19
1642027648
86422507
------------------
++++++++++++++++++
19
1642037888
86423046
------------------
++++++++++++++++++
19
1642048128
86423585
------------------
++++++++++++++++++
19
1642058368
86424124
------------------
++++++++++++++++++
19
1642068608
86424663
------------------
++++++++++++++++++
19
1642078848
86425202
------------------
++++++++++++++++++
19
1642089088
86425741
------------------
++++++++++++++++++
19
1642099328
86426280
------------------
++++++++++++++++++
19
1642109568
86426819
------------------
++++++++++++++++++
19
1642119808
86427358

https://testerhome.com/topics/2006

https://www.cnblogs.com/bf-blackfish/p/10579867.html

https://www.cnblogs.com/chenyun-/p/11714634.html

https://www.cnblogs.com/bf-blackfish/p/10579867.html

https://www.cnblogs.com/landhu/p/5488807.html

https://www.cnblogs.com/yiwangzhibujian/p/7107785.html

https://www.cnblogs.com/chenyun-/p/11714634.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值