压测数据参考

文章通过对比8U16G配置下,一个带有100ms延迟的SpringBoot应用(IO型)与一个执行计算密集型任务的应用(计算型)的性能。使用wrk工具进行负载测试,展示了不同并发设置下的响应时间和吞吐量。预热和调整计算任务大小对性能有显著影响。

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

IO型

 8U 16G 100ms  springboot

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoWebApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoWebApplication.class, args);
        System.out.println("----- http://localhost:8880/demo/ -----");
    }

    @GetMapping(value = "/hello", name = "返回Hello World")
    public String hello(@RequestParam(value = "name", required = false) String name) throws InterruptedException {
        Thread.sleep(100);
        return String.format("Hello %s! ", name == null ? "World" : name);
    }

}

wrk -t16 -c500 -d30s --latency http://localhost:8080/hello

Running 30s test @ http://localhost:8080/hello
  16 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   255.52ms  128.35ms   1.31s    75.70%
    Req/Sec   125.18     36.90   313.00     78.01%
  Latency Distribution
     50%  271.27ms
     75%  287.39ms
     90%  302.03ms
     99%  784.10ms
  59274 requests in 30.10s, 7.19MB read
Requests/sec:   1969.39
Transfer/sec:    244.56KB

计算型:

 8U 16G 50ms  springboot

public class DemoWebApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoWebApplication.class, args);
        System.out.println("----- http://localhost:8880/demo/ -----");
    }

    @GetMapping(value = "/hello", name = "返回Hello World")
    public String hello(@RequestParam(value = "name", required = false) String name) throws InterruptedException {
//        Thread.sleep(100);
        long t1 = System.currentTimeMillis();
        pertest();
        long t2 = System.currentTimeMillis();
        return "Hello World" + (t2 - t1);
    }

    public void pertest() {
//        int size = 100000000;
        int size = 12000000; //50ms
        //记录多线程的总执行次数,保证高并发下的原子性
        AtomicInteger atomicInteger = new AtomicInteger(0);
        int count = 0;
        while (count < size) {
            count++;
            atomicInteger.getAndIncrement();
        }
    }


}

wrk -t8 -c400 -d30s http://localhost:8080/hello
Running 30s test @ http://localhost:8080/hello
  8 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.32s   268.15ms   2.00s    80.14%
    Req/Sec    24.25     19.09   151.00     73.98%
  4408 requests in 30.05s, 554.88KB read
  Socket errors: connect 0, read 0, write 0, timeout 92
Requests/sec:    146.71

未预热,无错误

wrk -t4 -c10 -d30s http://localhost:8080/hello
Running 30s test @ http://localhost:8080/hello
  4 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    53.39ms   10.44ms 365.47ms   98.32%
    Req/Sec    37.66      4.84    40.00     79.33%
  4519 requests in 30.02s, 561.22KB read
Requests/sec:    150.54
Transfer/sec:     18.70KB

预热后

wrk -t4 -c10 -d30s http://localhost:8080/hello
Running 30s test @ http://localhost:8080/hello
  4 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    28.32ms    1.48ms  49.39ms   78.40%
    Req/Sec    70.62      7.59    80.00     42.33%
  8475 requests in 30.02s, 1.03MB read
Requests/sec:    282.29
Transfer/sec:     35.06KB

 

public void pertest() {
//        int size = 100000000;
//        int size = 12000000;//50ms
        int size = 2000000;//10ms
        //记录多线程的总执行次数,保证高并发下的原子性
        AtomicInteger atomicInteger = new AtomicInteger(0);
        int count = 0;
        while (count < size) {
            count++;
            atomicInteger.getAndIncrement();

            ///////////////
            //在此写入需要测试性能的代码块
            ///////////////
        }
    }

wrk -t8 -c400 -d30s http://localhost:8080/hello
Running 30s test @ http://localhost:8080/hello
  8 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   299.91ms  322.39ms   2.00s    89.76%
    Req/Sec   110.90     47.01   300.00     67.26%
  26346 requests in 30.08s, 3.21MB read
  Socket errors: connect 0, read 0, write 0, timeout 1243

Requests/sec:    875.86
Transfer/sec:    109.12KB

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值