簡體   English   中英

使用DI時,播放2.4在第一次請求時花費更多時間

[英]Play 2.4 taking much more time on first request while using DI

我正在使用Play 2.4與依賴注入和注入路由生成器。 但是在第一次請求時,它需要1200毫秒,之后,對同一路由的請求需要20毫秒。 在我調試它之后,我發現在第一次請求時,它使用java.lang.classLoader.loadClass(String)方法加載了大約1000個類。

[Loaded org.jboss.netty.handler.codec.frame.FrameDecoder from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.replay.ReplayingDecoder from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpMessageDecoder from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpRequestDecoder from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.replay.ReplayError from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.frame.TooLongFrameException from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpChunk from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpChunkTrailer from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpMessageDecoder$State from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpMessage from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.replay.ReplayingDecoderBuffer from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.replay.UnreplayableOperationException from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.oneone.OneToOneEncoder from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpMessageEncoder from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.handler.codec.http.HttpResponseEncoder from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.util.CharsetUtil from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.util.CharsetUtil$1 from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.util.CharsetUtil$2 from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]
[Loaded org.jboss.netty.buffer.ChannelBuffers from file:/Users/tushar7795/Reach/reach-api/reach-api-1.0.0/lib/io.netty.netty-3.10.5.Final.jar]

這些是在第一次請求時加載的一些類。 如何在應用程序啟動時加載這些類?

如果由於JVM的延遲加載行為而不希望您對應用程序的初始請求花費更多時間,則一種解決方案是創建外部腳本,該腳本將對應用程序進行預熱,並且在完成預熱之前不會返回200進行運行狀況檢查。 另一種方法是創建一個熱身你的應用程序的akka​​ actor。 您可以在應用啟動后使用fire-forget方法(tell)初始化此actor,並且與上面相同,在完成預熱之前無法進行運行狀況檢查,以便ELB不會開始將請求重定向到此實例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM