为什么在twirl中使用@ routes.Assets.versioned时,播放框架2.4如此缓慢? [英] Why play framework 2.4 is so slow when using @routes.Assets.versioned in twirl?

查看:98
本文介绍了为什么在twirl中使用@ routes.Assets.versioned时,播放框架2.4如此缓慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我渲染一个旋转模板并在我的操作中将其返回时,我有一个控制器.播放性能下降了大约5倍(在Apache基准测试中为每秒15000个请求).但是当我在此操作中返回json时,播放性能提高了约5倍(apache基准测试中每秒79000个请求).我有一个非常简单的旋转模板:

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

}

更新:我发现当我使用@ routes.Assets.versioned而不是@ routes.Assets.at解决资产时,会发生此问题.

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>

推荐答案

返回原始数据的操作与需要解析和呈现某些Twirl视图视图的操作之间总是存在差异,另外,versioned资产检查每个文件,因此为整个过程添加了其他作业.

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.

比较两个Twirl视图的性能,一个使用versioned方法,另一个用于手动添加字符串,然后考虑如何优化视图.

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.

这篇关于为什么在twirl中使用@ routes.Assets.versioned时,播放框架2.4如此缓慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆