Skip to content

Commit 8fedee5

Browse files
author
YunaiV
committed
构建 spring cloud gateway && zuul 容器测试示例
1 parent 5a1bfc6 commit 8fedee5

File tree

19 files changed

+512
-0
lines changed

19 files changed

+512
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,18 @@
1111

1212
# lab-05
1313

14+
测试 Tomcat、Jetty、Undertow 的基准性能
1415

16+
文章见:[《性能测试 —— Tomcat、Jetty、Undertow 基准测试》](http://www.iocoder.cn/Performance-Testing/Tomcat-Jetty-Undertow-benchmark/)
17+
18+
# lab-06
19+
20+
测试 SpringMVC、Webflux 的基准性能
21+
22+
文章见:[《性能测试 —— SpringMVC、Webflux 基准测试》](http://www.iocoder.cn/Performance-Testing/SpringMVC-Webflux-benchmark/)
23+
24+
# lab-07
25+
26+
测试 Spring Cloud Gateway、Zuul 的基准性能
27+
28+
文章见:[《》]()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>lab-06</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-06-springmvc-tomcat</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-web</artifactId>
18+
</dependency>
19+
</dependencies>
20+
21+
<build>
22+
<plugins>
23+
<!-- 提供给 mapstruct 使用 -->
24+
<plugin>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-maven-plugin</artifactId>
27+
<configuration>
28+
<fork>true</fork>
29+
</configuration>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
34+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.iocoder.springboot.labs.lab06.springmvc;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class Controller {
8+
9+
@GetMapping("/hello")
10+
public String hello() {
11+
// System.out.println(Thread.currentThread().getName());
12+
return "world";
13+
}
14+
15+
@GetMapping("/sleep")
16+
public String sleep() throws InterruptedException {
17+
Thread.sleep(100L);
18+
// System.out.println(Thread.currentThread().getName());
19+
return "world";
20+
}
21+
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.iocoder.springboot.labs.lab06.springmvc;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringMVCApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringMVCApplication.class);
11+
}
12+
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>lab-06</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-06-webflux-netty</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-webflux</artifactId>
18+
</dependency>
19+
</dependencies>
20+
21+
<build>
22+
<plugins>
23+
<!-- 提供给 mapstruct 使用 -->
24+
<plugin>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-maven-plugin</artifactId>
27+
<configuration>
28+
<fork>true</fork>
29+
<mainClass>cn.iocoder.springboot.labs.lab06.webflux.WebfluxNettyApplication</mainClass>
30+
</configuration>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
35+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cn.iocoder.springboot.labs.lab06.webflux;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
import reactor.core.publisher.Mono;
6+
import reactor.core.scheduler.Schedulers;
7+
8+
@RestController
9+
public class Controller {
10+
11+
@GetMapping("/hello")
12+
public Mono<String> hello() {
13+
return Mono.just("world");
14+
}
15+
16+
@GetMapping("/sleep_direct")
17+
public Mono<String> sleepDirect() throws InterruptedException {
18+
Thread.sleep(100L);
19+
return Mono.just("world");
20+
}
21+
22+
@GetMapping("/sleep")
23+
public Mono<String> sleep() {
24+
// System.out.println(Thread.currentThread().getName());
25+
// return Mono.just("world").delayElement(Duration.ofMillis(100));
26+
return Mono.defer(() -> {
27+
// System.out.println(Thread.currentThread().getName());
28+
try {
29+
Thread.sleep(100L);
30+
} catch (InterruptedException ignored) {
31+
}
32+
return Mono.just("world");
33+
}).subscribeOn(Schedulers.parallel());
34+
}
35+
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.iocoder.springboot.labs.lab06.webflux;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class WebfluxNettyApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(WebfluxNettyApplication.class);
11+
}
12+
13+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>lab-06</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-06-webflux-tomcat</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-webflux</artifactId>
18+
<exclusions>
19+
<exclusion>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-netty</artifactId>
22+
</exclusion>
23+
</exclusions>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-tomcat</artifactId>
29+
</dependency>
30+
31+
</dependencies>
32+
33+
<build>
34+
<plugins>
35+
<!-- 提供给 mapstruct 使用 -->
36+
<plugin>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-maven-plugin</artifactId>
39+
<configuration>
40+
<fork>true</fork>
41+
<mainClass>cn.iocoder.springboot.labs.lab06.webflux.WebfluxTomcatApplication</mainClass>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
</project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cn.iocoder.springboot.labs.lab06.webflux;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
import reactor.core.publisher.Mono;
6+
import reactor.core.scheduler.Schedulers;
7+
8+
import java.util.Map;
9+
import java.util.concurrent.ConcurrentHashMap;
10+
11+
@RestController
12+
public class Controller {
13+
14+
@GetMapping("/hello")
15+
public Mono<String> hello() {
16+
return Mono.just("world");
17+
}
18+
19+
@GetMapping("/sleep_direct")
20+
public Mono<String> sleepDirect() throws InterruptedException {
21+
Thread.sleep(100L);
22+
return Mono.just("world");
23+
}
24+
25+
@GetMapping("/sleep")
26+
public Mono<String> sleep() {
27+
// System.out.println(Thread.currentThread().getName());
28+
// return Mono.just("world").delayElement(Duration.ofMillis(100));
29+
return Mono.defer(() -> {
30+
// System.out.println(Thread.currentThread().getName());
31+
try {
32+
Thread.sleep(100L);
33+
} catch (InterruptedException ignored) {
34+
}
35+
return Mono.just("world");
36+
}).subscribeOn(Schedulers.parallel());
37+
}
38+
39+
private Map<String, Boolean> MAP = new ConcurrentHashMap<>();
40+
41+
@GetMapping("/sleep2")
42+
public Mono<String> sleep2() {
43+
return Mono.defer(() -> {
44+
try {
45+
// System.out.println(Thread.currentThread().getName());
46+
if (!MAP.containsKey(Thread.currentThread().getName())) {
47+
System.out.println(Thread.currentThread().getName());
48+
MAP.put(Thread.currentThread().getName(), true);
49+
}
50+
Thread.sleep(100L);
51+
} catch (InterruptedException ignored) {
52+
}
53+
return Mono.just("world");
54+
}).subscribeOn(Schedulers.elastic());
55+
}
56+
57+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.iocoder.springboot.labs.lab06.webflux;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class WebfluxTomcatApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(WebfluxTomcatApplication.class);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)