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