繁体   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