Jmeter 5.6.3 自定义GRPC 压测插件,配置,使用,

前言

jmeter 版本 apache-jmeter-5.6.3

说明

jmeter 自定义grpc 压测扩展实现源码,适用对grpc双向通信进行压力测试,其他grpc模式实现都非常一致。调整下代码即可实现。

使用方法:编译工程打包成jar文件,然后放到jmeter的jar目录下,以我本地为例: D:\soft\apache-jmeter-5.6.3\lib\ext

启动jmeter 进行测试

三、配置与使用
1)添加线程组:右键单击测试计划 → 添加 → 线程(用户) → 线程组

在这里插入图片描述

2) 添加GRPC Request:右键单击新建的线程组 → 添加 → 取样器 → GRPC Request

在这里插入图片描述

3)填写请求信息:主机、端口、proto文件夹、rpc方法、请求数据

在这里插入图片描述

必填项:
在这里插入图片描述

java插件核心代码

package org.apache.nifi.processors.grpc;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.grpc.CompressorRegistry;
import io.grpc.DecompressorRegistry;
import io.grpc.ManagedChannel;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.stub.StreamObserver;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;

import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

/**
 * Created by zyq on 2020/3/4.
 */
public class GrpcJmeter implements JavaSamplerClient {
   
    private String userAccount;
    private String password;
    private String address;
    private Integer port;

    private String routingKey;
    private String routingSecret;

    private SampleResult results;

    private StreamObserver<org.apache.nifi.processors.grpc.gen.edge.v1.RequestMsg> inputStream;

    private ManagedChannel channel;

    private CountDownLatch countDownLatch;


    private static final String USER_AGENT_PREFIX = "NiFi_invokeGRPC";



    @Override
    public void setupTest(JavaSamplerContext javaSamplerContext) {
   

        countDownLatch = new CountDownLatch(1);
        results = new SampleResult();

        userAccount = javaSamplerContext.getParameter("userAccount"); // 获取在JMeter中设置的参数值
        password = javaSamplerContext.getParameter("password"); // 获取在JMeter中设置的参数值
        address = javaSamplerContext.getParameter("address"); // 获取在JMeter中设置的参数值
        port =Integer.valueOf(javaSamplerContext.getParameter(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gzcsschen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值