Why play framework 2.4 is so slow when using @routes.Assets.versioned in twirl?

别等时光非礼了梦想. 提交于 2019-12-08 07:56:49

问题


I have a controller, when i render a twirl template and return it in my action. the play performance decrease about 5 time (15000 Requests per second in apache benchmark). but when i return json in this action play performance increase about 5 time (79000 Requests per second in apache benchmark). I have a very simple twirl template:

@(message: String)

@main("Welcome to Play") {

    @message

}

Update: I find that when i use @routes.Assets.versioned instead of @routes.Assets.at to address assets this problem occurs.

    <link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
    <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
    <script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>

回答1:


There will be always difference between action returning raw data, and actions that need to parse and render some Twirl views view(s), additionally versioned asset checks the each file, so it adds additional jobs for whole process.

Compare performance of two Twirl views, one with versioned method used other with manual adding the string, and consider how you can optimize your views.

Also consider caching the Results where possible, it will for sure speed up the things.



来源:https://stackoverflow.com/questions/35254620/why-play-framework-2-4-is-so-slow-when-using-routes-assets-versioned-in-twirl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!