【问题标题】:Concurrency in Spring BootSpring Boot 中的并发
【发布时间】:2019-03-12 13:45:36
【问题描述】:

我有带有嵌入式码头的 Spring Boot 应用程序,它的配置是: jetty's minThread: 50 jetty's maxThread: 500 jetty's maxQueueSize: 25000(我将默认队列更改为LinkedBlockingQueue) 我没有更改acceptorsselectors(因为我不相信硬编码值)

通过以上配置,我得到以下 jmeter 测试结果:

  1. 并发用户数:60

摘要 = 00:01:54 中的 183571 = 1611.9/s 平均:36 分钟:3 最大: 1062 错误:0 (0.00%)

  1. 并发用户数:75

摘要 = 00:05:00 中的 496619 = 1654.6/s 平均:45 分钟:3 最大: 1169 错误:0 (0.00%)

如果我增加并发用户,我看不到任何改进。我想增加并发性。如何做到这一点?


================================================ ============================== 2019 年 3 月 29 日更新

我在改进业务逻辑上投入了更多精力。还是没有太大起色。然后我决定开发一个 hello world spring-boot 项目。 即,

弹簧启动 (1.5.9)

码头 9.4.15

具有获取端点的休息控制器

代码如下:

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

然后我尝试使用 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

从上面的测试运行中,我自己在 75 个用户的情况下达到了每秒约 27K,但它看起来增加了用户也增加了延迟。此外,我们可以清楚地注意到连接时间正在增加。

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

请帮帮我

【问题讨论】:

  • “增加并发”是什么意思?为什么您期望使用更多并发用户获得更好的应用程序性能?由于您有 500 个接受线程,当并发用户少于 500 个时,您可能不会看到任何与码头相关的性能变化,
  • 最少 200 个并发用户可以访问我们的应用程序并并行使用 Web 服务,预期响应时间应小于 200 毫秒。无论在 jmeter 中设置多少并发用户,我都可以看到一次只有大约 80 到 100 个线程正在处理。
  • 也许这和你的 jmeter 设置有关?
  • 我使用 apachebench 进行了测试。并添加了清晰的注释。请查看并帮助

标签: java spring-boot concurrency jetty apachebench


【解决方案1】:

您可以尝试增加或减少 Jetty 线程的数量,但应用程序性能将取决于应用程序逻辑。如果您当前的瓶颈是数据库查询,则通过调整 HTTP 层几乎看不到任何改进,尤其是在通过本地网络进行测试时。

找到您的应用程序中的瓶颈,尝试改进它,然后再次测量以确认它更好。重复这三个步骤,直到达到所需的性能。不要盲目地调整性能,这是浪费时间。

【讨论】:

  • 是的,现在我们所有的请求都指向数据库。但我觉得 db 已经在它的局限性上表现良好。我的意思是,我们的应用程序每秒能够执行 6000 db 操作。因此,我们希望扩展我们的应用程序以每秒处理至少 3000 个请求。但不知道如何找到正确的路径。我是这个性能调整的新手。
  • 先看this video,性能不好衡量。
  • 能否请您看看更新的信息和帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
  • 1970-01-01
  • 1970-01-01
  • 2016-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多