自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Spring Boot中Tomcat、Jetty、Undertow哪個(gè)嵌入式服務(wù)器最好?

開(kāi)發(fā) 前端
Greetings API 是一個(gè)簡(jiǎn)單的應(yīng)用程序,它公開(kāi)了一個(gè)端點(diǎn) /greetings?name=?,該端點(diǎn)返回一個(gè)問(wèn)候語(yǔ)。如果沒(méi)有提供name,它將返回“[greeting-word] World!”。否則,它將返回“[greeting-word] [name]!”。

當(dāng)我們使用  Spring Boot 創(chuàng)建一個(gè) Web 應(yīng)用程序時(shí),Apache Tomcat 是默認(rèn)的嵌入式 Web 服務(wù)器。然而,我們也可以選擇其他選項(xiàng),如 Jetty 和 Undertow。但哪一個(gè)才是最佳選擇呢?一起來(lái)探討一下!

為此,我們將構(gòu)建一個(gè)名為 Greetings API 的簡(jiǎn)單 Spring Boot 應(yīng)用程序。我們將在應(yīng)用程序的 pom.xml 中添加 Maven 配置文件,以便通過(guò)選擇適當(dāng)?shù)呐渲梦募诓煌那度胧?Web 服務(wù)器之間切換。Tomcat 將是默認(rèn)選項(xiàng),但我們還將為 Jetty 和 Undertow 設(shè)置配置文件。

設(shè)置好配置文件后,我們將為每個(gè) Web 服務(wù)器創(chuàng)建 Docker 鏡像,并在單獨(dú)的容器中運(yùn)行它們。然后,我們將根據(jù)啟動(dòng)時(shí)間、CPU 和內(nèi)存使用情況以及請(qǐng)求處理性能對(duì)它們進(jìn)行比較。


測(cè)試應(yīng)用

Greetings API 是一個(gè)簡(jiǎn)單的應(yīng)用程序,它公開(kāi)了一個(gè)端點(diǎn) /greetings?name=?,該端點(diǎn)返回一個(gè)問(wèn)候語(yǔ)。如果沒(méi)有提供name,它將返回“[greeting-word] World!”。否則,它將返回“[greeting-word] [name]!”。

它的實(shí)現(xiàn)如下:

@Service
public class GreetingsService {
    private static final String[] greetingWord = new String[]{"Hello", "Hi", "Olá", "Oi", "Hallo"};
    public String randomGreetings(String name) {
        try {
            String word = greetingWord[ThreadLocalRandom.current().nextInt(greetingWord.length)];
            Thread.sleep(1000);
            return "%s %s!".formatted(word, name);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
@RestController
@RequestMapping("/greetings")
public class GreetingsController {
    private final GreetingsService greetingsService;
    public GreetingsController(GreetingsService greetingsService) {
        this.greetingsService = greetingsService;
    }
    @GetMapping
    public String greeting(@RequestParam(required = false, defaultValue = "World") String name) {
        return greetingsService.randomGreetings(name);
    }
}
@Service
public class GreetingsService {

    private static final String[] greetingWord = new String[]{"Hello", "Hi", "Olá", "Oi", "Hallo"};

    public String randomGreetings(String name) {
        try {
            String word = greetingWord[ThreadLocalRandom.current().nextInt(greetingWord.length)];
            Thread.sleep(1000);
            return "%s %s!".formatted(word, name);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

@RestController
@RequestMapping("/greetings")
public class GreetingsController {

    private final GreetingsService greetingsService;

    public GreetingsController(GreetingsService greetingsService) {
        this.greetingsService = greetingsService;
    }

    @GetMapping
    public String greeting(@RequestParam(required = false, defaultValue = "World") String name) {
        return greetingsService.randomGreetings(name);
    }
}
@Service
public class GreetingsService {

    private static final String[] greetingWord = new String[]{"Hello", "Hi", "Olá", "Oi", "Hallo"};

    public String randomGreetings(String name) {
        try {
            String word = greetingWord[ThreadLocalRandom.current().nextInt(greetingWord.length)];
            Thread.sleep(1000);
            return "%s %s!".formatted(word, name);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

@RestController
@RequestMapping("/greetings")
public class GreetingsController {

    private final GreetingsService greetingsService;

    public GreetingsController(GreetingsService greetingsService) {
        this.greetingsService = greetingsService;
    }

    @GetMapping
    public String greeting(@RequestParam(required = false, defaultValue = "World") String name) {
        return greetingsService.randomGreetings(name);
    }
}

Jetty和Undertow的配置

在pom.xml中增加Jetty和Undertow的配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
    ...
    <dependencies>
        ...
    </dependencies>
    <profiles>
        <!-- Jetty Profile -->
        <profile>
            <id>jetty</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <!-- Exclude the Tomcat dependency -->
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <!-- Use Jetty instead -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jetty</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <!-- Undertow Profile -->
        <profile>
            <id>undertow</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <!-- Exclude the Tomcat dependency -->
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <!-- Use Undertow instead -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-undertow</artifactId>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
    <build>
        ...
    </build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
    ...
    <dependencies>
        ...
    </dependencies>

    <profiles>

        <!-- Jetty Profile -->
        <profile>
            <id>jetty</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <!-- Exclude the Tomcat dependency -->
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <!-- Use Jetty instead -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jetty</artifactId>
                </dependency>
            </dependencies>
        </profile>

        <!-- Undertow Profile -->
        <profile>
            <id>undertow</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <!-- Exclude the Tomcat dependency -->
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <!-- Use Undertow instead -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-undertow</artifactId>
                </dependency>
            </dependencies>
        </profile>

    </profiles>

    <build>
        ...
    </build>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
    ...
    <dependencies>
        ...
    </dependencies>

    <profiles>

        <!-- Jetty Profile -->
        <profile>
            <id>jetty</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <!-- Exclude the Tomcat dependency -->
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <!-- Use Jetty instead -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jetty</artifactId>
                </dependency>
            </dependencies>
        </profile>

        <!-- Undertow Profile -->
        <profile>
            <id>undertow</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <!-- Exclude the Tomcat dependency -->
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <!-- Use Undertow instead -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-undertow</artifactId>
                </dependency>
            </dependencies>
        </profile>

    </profiles>

    <build>
        ...
    </build>

</project>

application.properties 配置

分別配置Tomcat、Jetty和Undertow線程配置,具體如下:

# Maximum amount of worker threads. 200 is the default.
server.tomcat.threads.max=200
# Maximum number of threads. 200 is the default.
server.jetty.threads.max=200
# Number of worker threads. The default is 8 times the number of I/O threads.
# The number of I/O threads is set by the property "server.undertow.threads.io" whose default is derived from the number of available processors.
server.undertow.threads.worker=200
# Maximum amount of worker threads. 200 is the default.
server.tomcat.threads.max=200

# Maximum number of threads. 200 is the default.
server.jetty.threads.max=200

# Number of worker threads. The default is 8 times the number of I/O threads.
# The number of I/O threads is set by the property "server.undertow.threads.io" whose default is derived from the number of available processors.
server.undertow.threads.worker=200
# Maximum amount of worker threads. 200 is the default.
server.tomcat.threads.max=200

# Maximum number of threads. 200 is the default.
server.jetty.threads.max=200

# Number of worker threads. The default is 8 times the number of I/O threads.
# The number of I/O threads is set by the property "server.undertow.threads.io" whose default is derived from the number of available processors.
server.undertow.threads.worker=200

這里我們將所有Web服務(wù)器的最大線程數(shù)設(shè)置為200

我們創(chuàng)建了一個(gè)高質(zhì)量的技術(shù)交流群,與優(yōu)秀的人在一起,自己也會(huì)優(yōu)秀起來(lái),趕緊點(diǎn)擊加群,享受一起成長(zhǎng)的快樂(lè)。

更多關(guān)于Spring的技術(shù)學(xué)習(xí),可關(guān)注 https://spring4all.com,專注討論關(guān)于Spring的一切。

構(gòu)建Docker鏡像

上面我們已經(jīng)為 Jetty 和 Undertow 配置了 Maven 配置文件,所以我們可以為每個(gè)嵌入式 Web 服務(wù)器構(gòu)建 Docker 鏡像。

# 構(gòu)建Tomcat的鏡像
./mvnw clean -DskipTests spring-boot:build-image  \
    -Dspring-boot.build-image.imageName=greetings-api-tomcat:latest
# 構(gòu)建Jetty的鏡像
./mvnw clean -DskipTests spring-boot:build-image -Pjetty \
    -Dspring-boot.build-image.imageName=greetings-api-jetty:latest
# 構(gòu)建Undertow的鏡像
./mvnw clean -DskipTests spring-boot:build-image -Pundertow \
    -Dspring-boot.build-image.imageName=greetings-api-undertow:latest
# 構(gòu)建Tomcat的鏡像
./mvnw clean -DskipTests spring-boot:build-image  \
    -Dspring-boot.build-image.imageName=greetings-api-tomcat:latest


# 構(gòu)建Jetty的鏡像
./mvnw clean -DskipTests spring-boot:build-image -Pjetty \
    -Dspring-boot.build-image.imageName=greetings-api-jetty:latest


# 構(gòu)建Undertow的鏡像
./mvnw clean -DskipTests spring-boot:build-image -Pundertow \
    -Dspring-boot.build-image.imageName=greetings-api-undertow:latest
# 構(gòu)建Tomcat的鏡像
./mvnw clean -DskipTests spring-boot:build-image  \
    -Dspring-boot.build-image.imageName=greetings-api-tomcat:latest


# 構(gòu)建Jetty的鏡像
./mvnw clean -DskipTests spring-boot:build-image -Pjetty \
    -Dspring-boot.build-image.imageName=greetings-api-jetty:latest


# 構(gòu)建Undertow的鏡像
./mvnw clean -DskipTests spring-boot:build-image -Pundertow \
    -Dspring-boot.build-image.imageName=greetings-api-undertow:latest

基準(zhǔn)測(cè)試

為了從我們的 Docker 容器中收集基準(zhǔn)測(cè)試的重要數(shù)據(jù),我們將使用這個(gè)開(kāi)源項(xiàng)目:https://github.com/ivangfr/api-oha-benchmarker ,

基準(zhǔn)測(cè)試將包括對(duì)每個(gè)嵌入式 Web 服務(wù)器的 Docker 容器進(jìn)行負(fù)載測(cè)試。每次迭代,我們將進(jìn)行如下操作:

  1. 啟動(dòng) Docker 容器
  2. 使用 100、300、900 和最終 2700 個(gè)并發(fā)請(qǐng)求進(jìn)行 OHA 測(cè)試
  3. 關(guān)閉 Docker 容器。

下面,我們?cè)谑褂?OHA 對(duì) Docker 容器進(jìn)行 100、300、900 和最終 2700 個(gè)并發(fā)請(qǐng)求的負(fù)載測(cè)試后,獲得的結(jié)果數(shù)據(jù):

Application | numRequests | Concurrency | Success rate(%) | Total(secs) | Slowest(secs) | Fastest(secs) | Average(secs) | Requests/sec |
---------------------- + ----------- + ----------- + --------------- + ----------- + ------------- + ------------- + ------------- + ------------ |
  greetings-api-tomcat |         100 |         100 |          100.00 |      1.2949 |        1.2942 |        1.2701 |        1.2822 |      77.2256 |
  greetings-api-tomcat |         300 |         300 |          100.00 |      2.1069 |        2.0835 |        1.0311 |        1.4158 |     142.3913 |
  greetings-api-tomcat |         900 |         900 |          100.00 |      5.1386 |        5.0797 |        1.0283 |        2.8856 |     175.1446 |
  greetings-api-tomcat |        2700 |        2700 |          100.00 |     14.3752 |       14.2423 |        1.0296 |        7.4867 |     187.8241 |
...................... + ........... + ........... + ............... + ........... + ............. + ............. + ............. + ............ |
   greetings-api-jetty |         100 |         100 |          100.00 |      2.0717 |        2.0708 |        1.2639 |        1.5895 |      48.2692 |
   greetings-api-jetty |         300 |         300 |          100.00 |      3.1081 |        3.1056 |        1.0307 |        1.7496 |      96.5223 |
   greetings-api-jetty |         900 |         900 |          100.00 |      5.1943 |        5.1762 |        1.0381 |        3.0216 |     173.2659 |
   greetings-api-jetty |        2700 |        2700 |          100.00 |     15.3022 |       15.2278 |        1.0160 |        7.9127 |     176.4455 |
...................... + ........... + ........... + ............... + ........... + ............. + ............. + ............. + ............ |
greetings-api-undertow |         100 |         100 |          100.00 |      1.3076 |        1.3066 |        1.2665 |        1.2833 |      76.4765 |
greetings-api-undertow |         300 |         300 |          100.00 |      2.0819 |        2.0776 |        1.0413 |        1.4058 |     144.0982 |
greetings-api-undertow |         900 |         900 |          100.00 |      5.1443 |        5.1121 |        1.0780 |        2.8783 |     174.9493 |
greetings-api-undertow |        2700 |        2700 |          100.00 |     14.1748 |       14.0861 |        1.0758 |        7.3721 |     190.4783 |
Application | numRequests | Concurrency | Success rate(%) | Total(secs) | Slowest(secs) | Fastest(secs) | Average(secs) | Requests/sec |
---------------------- + ----------- + ----------- + --------------- + ----------- + ------------- + ------------- + ------------- + ------------ |
  greetings-api-tomcat |         100 |         100 |          100.00 |      1.2949 |        1.2942 |        1.2701 |        1.2822 |      77.2256 |
  greetings-api-tomcat |         300 |         300 |          100.00 |      2.1069 |        2.0835 |        1.0311 |        1.4158 |     142.3913 |
  greetings-api-tomcat |         900 |         900 |          100.00 |      5.1386 |        5.0797 |        1.0283 |        2.8856 |     175.1446 |
  greetings-api-tomcat |        2700 |        2700 |          100.00 |     14.3752 |       14.2423 |        1.0296 |        7.4867 |     187.8241 |
...................... + ........... + ........... + ............... + ........... + ............. + ............. + ............. + ............ |
   greetings-api-jetty |         100 |         100 |          100.00 |      2.0717 |        2.0708 |        1.2639 |        1.5895 |      48.2692 |
   greetings-api-jetty |         300 |         300 |          100.00 |      3.1081 |        3.1056 |        1.0307 |        1.7496 |      96.5223 |
   greetings-api-jetty |         900 |         900 |          100.00 |      5.1943 |        5.1762 |        1.0381 |        3.0216 |     173.2659 |
   greetings-api-jetty |        2700 |        2700 |          100.00 |     15.3022 |       15.2278 |        1.0160 |        7.9127 |     176.4455 |
...................... + ........... + ........... + ............... + ........... + ............. + ............. + ............. + ............ |
greetings-api-undertow |         100 |         100 |          100.00 |      1.3076 |        1.3066 |        1.2665 |        1.2833 |      76.4765 |
greetings-api-undertow |         300 |         300 |          100.00 |      2.0819 |        2.0776 |        1.0413 |        1.4058 |     144.0982 |
greetings-api-undertow |         900 |         900 |          100.00 |      5.1443 |        5.1121 |        1.0780 |        2.8783 |     174.9493 |
greetings-api-undertow |        2700 |        2700 |          100.00 |     14.1748 |       14.0861 |        1.0758 |        7.3721 |     190.4783 |
Application | numRequests | Concurrency | Success rate(%) | Total(secs) | Slowest(secs) | Fastest(secs) | Average(secs) | Requests/sec |
---------------------- + ----------- + ----------- + --------------- + ----------- + ------------- + ------------- + ------------- + ------------ |
  greetings-api-tomcat |         100 |         100 |          100.00 |      1.2949 |        1.2942 |        1.2701 |        1.2822 |      77.2256 |
  greetings-api-tomcat |         300 |         300 |          100.00 |      2.1069 |        2.0835 |        1.0311 |        1.4158 |     142.3913 |
  greetings-api-tomcat |         900 |         900 |          100.00 |      5.1386 |        5.0797 |        1.0283 |        2.8856 |     175.1446 |
  greetings-api-tomcat |        2700 |        2700 |          100.00 |     14.3752 |       14.2423 |        1.0296 |        7.4867 |     187.8241 |
...................... + ........... + ........... + ............... + ........... + ............. + ............. + ............. + ............ |
   greetings-api-jetty |         100 |         100 |          100.00 |      2.0717 |        2.0708 |        1.2639 |        1.5895 |      48.2692 |
   greetings-api-jetty |         300 |         300 |          100.00 |      3.1081 |        3.1056 |        1.0307 |        1.7496 |      96.5223 |
   greetings-api-jetty |         900 |         900 |          100.00 |      5.1943 |        5.1762 |        1.0381 |        3.0216 |     173.2659 |
   greetings-api-jetty |        2700 |        2700 |          100.00 |     15.3022 |       15.2278 |        1.0160 |        7.9127 |     176.4455 |
...................... + ........... + ........... + ............... + ........... + ............. + ............. + ............. + ............ |
greetings-api-undertow |         100 |         100 |          100.00 |      1.3076 |        1.3066 |        1.2665 |        1.2833 |      76.4765 |
greetings-api-undertow |         300 |         300 |          100.00 |      2.0819 |        2.0776 |        1.0413 |        1.4058 |     144.0982 |
greetings-api-undertow |         900 |         900 |          100.00 |      5.1443 |        5.1121 |        1.0780 |        2.8783 |     174.9493 |
greetings-api-undertow |        2700 |        2700 |          100.00 |     14.1748 |       14.0861 |        1.0758 |        7.3721 |     190.4783 |

下圖顯示了啟動(dòng)時(shí)間以及最大 CPU 和內(nèi)存消耗:

Application | StartUpTime(sec) | Max CPU(%) | Max Memory(MB) |
---------------------- + ---------------- + ---------- + -------------- |
  greetings-api-tomcat |           1.8920 |     101.26 |         269.10 |
   greetings-api-jetty |           1.9790 |     100.40 |         217.70 |
greetings-api-undertow |           2.0450 |     124.15 |         237.50 |
Application | StartUpTime(sec) | Max CPU(%) | Max Memory(MB) |
---------------------- + ---------------- + ---------- + -------------- |
  greetings-api-tomcat |           1.8920 |     101.26 |         269.10 |
   greetings-api-jetty |           1.9790 |     100.40 |         217.70 |
greetings-api-undertow |           2.0450 |     124.15 |         237.50 |
Application | StartUpTime(sec) | Max CPU(%) | Max Memory(MB) |
---------------------- + ---------------- + ---------- + -------------- |
  greetings-api-tomcat |           1.8920 |     101.26 |         269.10 |
   greetings-api-jetty |           1.9790 |     100.40 |         217.70 |
greetings-api-undertow |           2.0450 |     124.15 |         237.50 |

響應(yīng)時(shí)間

圖片

我們可以看到,在處理 100 個(gè)并發(fā)請(qǐng)求時(shí),使用 Tomcat 的應(yīng)用程序最快,時(shí)間為 1.2949 秒,緊隨其后的是使用 Undertow 的應(yīng)用程序,時(shí)間為 1.3076 秒。使用 Jetty 的應(yīng)用程序最慢,時(shí)間為 2.0717 秒。

在處理 300 個(gè)并發(fā)請(qǐng)求時(shí),使用 Undertow 的應(yīng)用程序略快,時(shí)間為 2.0819 秒,緊隨其后的是使用 Tomcat 的應(yīng)用程序,時(shí)間為 2.1069 秒。使用 Jetty 的應(yīng)用程序最慢,時(shí)間為 3.1081 秒。

對(duì)于 900 個(gè)并發(fā)請(qǐng)求,使用 Tomcat 的應(yīng)用程序略快,時(shí)間為 5.1386 秒,緊隨其后的是使用 Undertow 的應(yīng)用程序,時(shí)間為 5.1443 秒,以及使用 Jetty 的應(yīng)用程序,時(shí)間為 5.1943 秒。

最后,在處理 2700 個(gè)并發(fā)請(qǐng)求時(shí),使用 Undertow 的應(yīng)用程序最快,時(shí)間為 14.1748 秒,緊隨其后的是使用 Tomcat 的應(yīng)用程序,時(shí)間為 14.3752 秒。使用 Jetty 的應(yīng)用程序最慢,時(shí)間為 15.3022 秒。

啟動(dòng)時(shí)間

圖片

可以看到,使用 Tomcat 的應(yīng)用程序啟動(dòng)時(shí)間最快,為 1.8920 秒,緊隨其后的是使用 Jetty 的應(yīng)用程序,時(shí)間為 1.9790 秒。啟動(dòng)最慢的是使用 Undertow 的應(yīng)用程序,耗時(shí) 2.0450 秒。

內(nèi)存占用

圖片

可以看到,使用 Jetty 的應(yīng)用程序最大內(nèi)存消耗最低,為 217.70 MB,緊隨其后的是使用 Undertow 的應(yīng)用程序,為 237.50 MB。最大內(nèi)存消耗最高的是使用 Tomcat 的應(yīng)用程序,為 269.10 MB。

CPU占用

圖片

以看到,使用 Jetty 的應(yīng)用程序最大 CPU 使用率最低,為 100.40%,緊隨其后的是使用 Tomcat 的應(yīng)用程序,為 101.26%。最高 CPU 使用率的是使用 Undertow 的應(yīng)用程序,為 124.15%。

結(jié)論

根據(jù)上面的測(cè)試,可以看到Tomcat、Jetty 和 Undertow 各有優(yōu)勢(shì)。使用 Tomcat 的應(yīng)用程序啟動(dòng)速度最快,并且能夠很好地處理不同級(jí)別的流量,盡管它使用更多的內(nèi)存。使用 Undertow 的應(yīng)用程序在處理大量流量時(shí)表現(xiàn)最佳,但它的 CPU 使用率更高,啟動(dòng)時(shí)間稍長(zhǎng)。使用 Jetty 的應(yīng)用程序在響應(yīng)流量方面較慢,但它使用的內(nèi)存和 CPU 更少,如果你希望節(jié)省資源,這是一個(gè)不錯(cuò)的選擇。

選擇最佳的 Web 服務(wù)器取決于你的需求。如果你的應(yīng)用程序?qū)⑻幚泶罅苛髁?,Undertow 可能是最佳選擇。如果你想要一個(gè)全能的選擇,Tomcat 是一個(gè)可靠的選擇。而如果節(jié)省內(nèi)存和 CPU 是最重要的,Jetty 是一個(gè)不錯(cuò)的選擇。

來(lái)源:https://spring4all.com/forum-post/7674.html

責(zé)任編輯:武曉燕 來(lái)源: 程序猿DD
相關(guān)推薦

2025-04-02 09:31:33

2019-02-14 14:33:22

Spring BootTomcat開(kāi)發(fā)

2011-07-27 14:14:13

2023-11-01 08:01:04

SpringWeb容器

2018-12-18 10:07:41

Spring Boot服務(wù)器HTTP2

2022-02-22 11:57:32

BOAWeb服務(wù)器

2019-10-23 10:14:24

TomcatJettyGlassFish

2010-09-25 15:05:49

LINUXJVM

2010-03-11 09:10:10

2021-07-29 23:29:55

web服務(wù)器開(kāi)發(fā)

2015-02-03 03:00:51

CentOSJetty

2009-06-11 13:16:00

netbeansTomcat服務(wù)器配置

2011-01-14 13:13:23

嵌入式Linux開(kāi)發(fā)

2018-11-28 15:39:21

人工神經(jīng)嵌入式SDK

2009-07-17 16:06:59

ARM嵌入式開(kāi)發(fā)

2009-12-09 10:12:28

嵌入式Linux

2011-04-18 11:34:34

嵌入式軟件測(cè)試

2009-12-17 10:33:05

嵌入式Linux

2009-12-16 15:41:40

嵌入式Linux入門

2011-06-29 18:17:20

Konqueror Embedded 瀏覽器
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)