并发模拟的四种方式

Postman:Http请求模拟工具

在这里插入图片描述
在这里插入图片描述

Apache Bench(AB):Apache附带的工具,测试网站性能

如输入命令:ab -n 1000 -c 50 http://localhost:8081/test
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

JMeter:Apache组织开发的压力测试工具

安装方法看下文【参考】部分

  • 创建线程组:
    在这里插入图片描述
    在这里插入图片描述
  • 添加Http测试
    在这里插入图片描述
    在这里插入图片描述
  • 添加测试结果查看监视器
    在这里插入图片描述
    在这里插入图片描述

代码:Semaphore、CountDownLatch等

package com.dai.concurrency;

import com.dai.concurrency.annoations.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * author daioo
 * create 2019-04-13 21:26
 */

@Slf4j
public class ConcurrencyTest {

    public static int clientTotal = 5000;

    public static int threadTotal = 50;

    public static int count = 0;

    public static void main(String[] args) throws Exception{
        ExecutorService executorService = Executors.newCachedThreadPool();
        final Semaphore semaphore = new Semaphore(threadTotal);
        final CountDownLatch countDownLatch = new CountDownLatch(clientTotal);
        for (int i = 0; i < clientTotal; i++) {
            executorService.execute(() -> {
                try {
                    semaphore.acquire();
                    add();
                    semaphore.release();
                } catch (Exception e) {
                    log.error("exception", e);
                }
                countDownLatch.countDown();
            });
        }
        countDownLatch.await();
        executorService.shutdown();
        System.out.println(count);
    }

    private static void add() {
        count++;
    }
}

在这里插入图片描述
输出结果是4989,不是5000,是线程不安全的

参考

JMeter在Mac下的安装

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值