【问题标题】:Spring Boot + SSL : Consuming Too much CPUSpring Boot + SSL:消耗过多的 CPU
【发布时间】:2016-09-08 10:43:21
【问题描述】:

我使用 Spring Boot + SSL 等特性测试了 Java Spring 框架的性能,以开发 REST API。

我发现如果我在 Spring 框架中添加 SSL 功能,它会消耗过多的 CPU。但是,我删除了 SSL 功能,这个问题不会发生。

我通过发送当前 20 个 HTTP 请求/秒或 100 个请求/秒来进行压力测试来测试 REST 应用程序,该应用程序总是会消耗近 200% 的 CPU。

我已将应用程序服务从 Spring 更改为 Tomcat。结果是一样的。

Test Environment
 - Sender  : Loading Test Generator Ubuntu, Dual Core, EC2 on AWS.
 - Receiver: Spring-Boot + SSL, Ubuntu, Dual Core, EC2 on AWS.

以下是接收服务器上的测试程序。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 *
 */
@SpringBootApplication
//@EnableAutoConfiguration
public class App 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
}

以下是 siege on sender server 的 Loading Test Generator 命令。

 //Current 1 request 
 siege -b -c6 -t60S https://receiver Server IP:8443/ 

 //Current 100 request 
  siege -b -c100 -t60S https://receiver Server IP:8443/

以下信息是我在接收服务器上的测试结果。

Current Requests/sec     Usage of CPU1  Usage of CPU2    Succ
   1                         40%           40%           100%
   2                         80%           80%           100%
   3                         95%           95%           100%
   6                         100%          100%          100%
  100                        100%          100%          100%
  600                        100%          100%          100%

似乎 Spring 的最大性能是 3 个请求/秒,而 CPU 的使用率低于 100%。 spring 应用虽然可以处理所有请求,但是消耗的 CPU 太多了。

请下载如下非常简单的代码并试一试。 https://github.com/dpomaresp/Spring-boot-with-ssl

你能帮我澄清一下这个问题吗?为什么会出现这个奇怪的问题?这是Spring框架的问题吗?

非常感谢您在这件事上提供的帮助。

埃里克

【问题讨论】:

  • 我还用 Spring-boot 框架 v1.3.0 和 1.4.0 对其进行了测试。结果是一样的。
  • 你不将 ssl 添加到 spring 你将它添加到 tomcat。因此,将其从嵌入式更改为非嵌入式应该不会改变任何事情。当然,它会增加 CPU 负载,因为所有连接都在进行加密和解密。
  • 感谢您的关注。我确实将它添加到Tomcat。但是即使向 REST 应用程序发送少量数据,cpu 负载也增加得太快。
  • 你真的看过我的评论吗?或者你在第一句话之后就停止了? SSL 将增加开销,因为所有内容都需要加密/解密。所以是的,它增加了 CPU 负载。多少取决于您的系统。在本地测试这些东西可能并不代表真正的生产系统。
  • 我做到了。我知道它会因为加密或解密而增加 CPU 的开销。但这是不正常的。如果 REST 应用程序是用 C/C++ 开发的,cpu 可能会逐渐增加。我没有在本地系统上进行测试,而是在不同的服务器上进行测试——使用压力工具的发送方安装在服务器 A 上,而接收方 REST 应用程序安装在服务器 B 上。它应该使用 REST API 模拟真实用户。我想知道为什么会出现这个问题以及如何改进它。

标签: java ssl spring-boot


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-16
    • 2016-07-18
    • 2020-06-04
    • 2019-08-22
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 2018-05-05
    相关资源
    最近更新 更多