最近,我們將后端 API 從 Grails 3 遷移到 Grails 5.1.1,同時我們還將 Java 版本升級到 11。一切都在 Docker 上運行。否則,其他一切都沒有改變。
遷移后,我們現在面臨性能問題。但這是一個奇怪的。
首先,我們從 NewRelic 得到一些結果:

NewRelic 表明這org.grails.web.mapping.mvc.GrailsControllerUrlMappingInfo是罪魁禍首。它下面沒有其他東西是緩慢的。再深入一點,我們發現一篇
From that little execution time logger I've got 161ms

Given all of that, it looks like NewRelic is kinda right. Something else is wasting cycles. The biggest question is WHAT?
How can I profile that? Maybe someone came across a similar situation. How can I resolve it?
On another note, since we have all the possible monitoring tools in place, I can tell for sure that the servers are not doing much (including the DB). The allocated heap size is up to 3G. Usually, the first request to the same endpoint takes much longer, and the consecutive ones are much better but still slow.
UPDATE
Decided to dig deeper. Hooked up the Async Profiler and I think my original assumptions were proved true.

The class loader seems to be the one causing the performance issues. This also explains the slowness of the first request (of any type), while subsequent ones start working faster. But, if I do the same call in another 4-5 minutes, it loads the classes again and is slow.
So, unless I am mistaken, the issue here is the class loader. I am blaming TomcatEmbeddedWebappClassLoader for this.
現在,最大的問題是如何在 Grails 中解決這個問題?我在 prod 中運行一個戰爭檔案->java -Dgrails.env=prod -Xms1500m -Xmx3000m -jar app.war
我發現這篇文章的方向有些相同,但我不確定如何在 Grails 中將其連接起來。
更新#2
尋找類加載器解決方案讓我想到了這個問題。建議的解決方案適用于 Spring。我想知道為 grails 解決這個問題的方法是什么。
uj5u.com熱心網友回復:
在鏈接https://github.com/spring-projects/spring-boot/issues/16471有以下報告:
“它的優先級很低,因為可以通過使用 .jar 包裝而不是 .war 包裝來避免該問題,或者我相信,通過切換到另一個嵌入式容器。就目前情況而言,我們沒有計劃在 2.x 時間范圍內解決這個問題。”
所以我運行了命令'./gradlew bootJar'。
我用siege做了測驗,第一個請求是從1.62秒到0.47秒
uj5u.com熱心網友回復:
運行 siege 命令以查看多個用戶在同一點發出請求的總時間。
我做了一個存盤庫試圖做你所說的
https://github.com/fernando88to/slowness5
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/426568.html
