代码之家  ›  专栏  ›  技术社区  ›  Raashith

如何提高弹簧靴的一致性

  •  0
  • Raashith  · 技术社区  · 6 年前

    我有一个要求,创建一个产品,应支持40并发用户每秒(我是新的并发工作)

    为了实现这一点,我尝试开发了一个helloworld spring boot项目。 即。,

    弹簧防尘套(1.5.9)

    具有get端点的rest控制器

    代码如下:

    @GetMapping
    public String index() {
        return "Greetings from Spring Boot!";
    }
    

    在Gen10 DL360计算机上运行的应用程序

    然后我尝试使用apachebench进行基准测试

    75个并发用户:

    ab -t 120 -n 1000000 -c 75 http://10.93.243.87:9000/home/
    Server Software:
    Server Hostname:        10.93.243.87
    Server Port:            9000
    
    Document Path:          /home/
    Document Length:        27 bytes
    
    Concurrency Level:      75
    Time taken for tests:   37.184 seconds
    Complete requests:      1000000
    Failed requests:        0
    Write errors:           0
    Total transferred:      143000000 bytes
    HTML transferred:       27000000 bytes
    Requests per second:    26893.28 [#/sec] (mean)
    Time per request:       2.789 [ms] (mean)
    Time per request:       0.037 [ms] (mean, across all concurrent requests)
    Transfer rate:          3755.61 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    1  23.5      0    3006
    Processing:     0    2   7.8      1     404
    Waiting:        0    2   7.8      1     404
    Total:          0    3  24.9      2    3007
    

    100个并发用户:

    ab -t 120 -n 1000000 -c 100 http://10.93.243.87:9000/home/
    Server Software:
    Server Hostname:        10.93.243.87
    Server Port:            9000
    
    Document Path:          /home/
    Document Length:        27 bytes
    
    Concurrency Level:      100
    Time taken for tests:   36.708 seconds
    Complete requests:      1000000
    Failed requests:        0
    Write errors:           0
    Total transferred:      143000000 bytes
    HTML transferred:       27000000 bytes
    Requests per second:    27241.77 [#/sec] (mean)
    Time per request:       3.671 [ms] (mean)
    Time per request:       0.037 [ms] (mean, across all concurrent requests)
    Transfer rate:          3804.27 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    2  35.7      1    3007
    Processing:     0    2   9.4      1     405
    Waiting:        0    2   9.4      1     405
    Total:          0    4  37.0      2    3009
    

    500个并发用户:

    ab -t 120 -n 1000000 -c 500 http://10.93.243.87:9000/home/
    Server Software:
    Server Hostname:        10.93.243.87
    Server Port:            9000
    
    Document Path:          /home/
    Document Length:        27 bytes
    
    Concurrency Level:      500
    Time taken for tests:   36.222 seconds
    Complete requests:      1000000
    Failed requests:        0
    Write errors:           0
    Total transferred:      143000000 bytes
    HTML transferred:       27000000 bytes
    Requests per second:    27607.83 [#/sec] (mean)
    Time per request:       18.111 [ms] (mean)
    Time per request:       0.036 [ms] (mean, across all concurrent requests)
    Transfer rate:          3855.39 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0   14 126.2      1    7015
    Processing:     0    4  22.3      1     811
    Waiting:        0    3  22.3      1     810
    Total:          0   18 129.2      2    7018
    

    1000个并发用户:

    ab -t 120 -n 1000000 -c 1000 http://10.93.243.87:9000/home/
    Server Software:
    Server Hostname:        10.93.243.87
    Server Port:            9000
    
    Document Path:          /home/
    Document Length:        27 bytes
    
    Concurrency Level:      1000
    Time taken for tests:   36.534 seconds
    Complete requests:      1000000
    Failed requests:        0
    Write errors:           0
    Total transferred:      143000000 bytes
    HTML transferred:       27000000 bytes
    Requests per second:    27372.09 [#/sec] (mean)
    Time per request:       36.534 [ms] (mean)
    Time per request:       0.037 [ms] (mean, across all concurrent requests)
    Transfer rate:          3822.47 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0   30 190.8      1    7015
    Processing:     0    6  31.4      2    1613
    Waiting:        0    5  31.4      1    1613
    Total:          0   36 195.5      2    7018
    

    从上面的测试运行来看,我达到了每秒约27K的速度,本身就有75个用户,但这看起来增加了用户数,同时也增加了延迟。此外,我们可以清楚地注意到连接时间正在增加。

    我要求我的应用程序支持40k个并发用户(假设所有用户都使用各自的浏览器),请求应该在250毫秒内完成。

    请帮帮我

    0 回复  |  直到 5 年前
        1
  •  0
  •   Rashin    6 年前

    我自己也不是这个话题的大法师,但这里有一些建议:

    • 有一个硬限制,多少请求可以处理一个实例,所以如果你想支持很多用户,你需要更多的实例
    • 如果您使用多个实例,那么您必须以某种方式在实例之间分配请求。一个流行的解决方案是 Netflix Eureka
    • 如果您不想维护额外的资源,并且产品将在云中运行,那么请使用提供的负载平衡服务(例如AWS上的LoadBalancer)
    • 您还可以微调服务器的连接池设置