Heroku,Grails:如果使用多个Web dynos,缺少资源 [英] Heroku, Grails: Missing resources if using multiple web dynos

查看:73
本文介绍了Heroku,Grails:如果使用多个Web dynos,缺少资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了grails应用程序,并将它上传到了heroku中。

如果我使用了'heroku scale web = 1',那么一切看起来都不错。但是如果我运行'heroku scale web = 2',一些静态资源就会消失。

从日志中我可以看出,来自web.2 dyno的所有静态资源都缺失。但是这个dyno是在没有任何错误的情况下启动的。



我该如何解决这个问题?

解决方案

https://github.com/grails-plugins/grails根据资源插件的所有者Marc Palmer的说法,他们忽略了对静态资源的旧引用的检查。因此,如果您没有使用粘性负载平衡(Heroku就是这种情况),那么这将表现为您在任何系统上都会遇到的负载平衡问题。以下是Heroku案例中发生的情况:


  1. 请求进入someapp.com

  2. index.gsp从app server 1,web.1提供。
    index.gsp包含
  3. 资源插件生成从/static/js/resource.js到/ js / resource的映射。 js on web.1

  4. 客户端请求/static/js/resource.js

  5. 请求被路由到不同的应用服务器,web.2

  6. /static/js/resource.js尚未映射到web.2和404s上

从我的研究中,最好的做法是在资源文件中声明您的资源。



请参阅以下内容:

http:// grails -plugins.github.com/grails-resources/guide/3.%20Declaring%20resources.html



这会在启动时告诉应用服务器资源存在前面,avoi例如,正如在我以前的电子邮件中,MyResources.groovy看起来像:

  modules = {
application {
resource url:'js / application.js'
resource url:'js / ui.geo_autocomplete.js '
}
}

所以,你可以使用两种方法 - 显式指定资源,或使用adhoc加载(将以下内容添加到您的Config.groovy中:)

pre $ grails.resources.adhoc .includes = []
grails.resources.adhoc.excludes = [*]

它基本上禁用了特别的资源处理。


I have created grails application and uploaded it in heroku.
If I use 'heroku scale web=1' everything looks OK. But if I run 'heroku scale web=2', some static resources disappear.
From logs I can figure out, that all static resources from web.2 dyno are missing. But this dyno is started without any errors.

How can I resolve this problem?

解决方案

https://github.com/grails-plugins/grails-resources/pull/11

According to the owner of the resources plugin, Marc Palmer, they're ignoring a check for old references to static resources.

So, this manifests itself as a load balancing issue that you would have on any system if you're not using sticky load balancing (which is the case with Heroku). Here's what's happening in the Heroku case:

  1. Request comes into someapp.com
  2. index.gsp is served from app server 1, web.1 index.gsp contains
  3. The resources plugin generates a mapping from /static/js/resource.js to /js/resource.js on web.1
  4. The client makes a request for /static/js/resource.js
  5. The request is routed to a different app server, web.2
  6. /static/js/resource.js has not been mapped on web.2 and 404s

From my research, the best practice is to declare your resources in a resources file.

See the following:

http://grails-plugins.github.com/grails-resources/guide/3.%20Declaring%20resources.html

This will tell the app server at boot time that a resource exists up front, avoiding the adhoc loading process.

For example, as in my previous email, a MyResources.groovy would look like:

modules = { 
  application { 
    resource url:'js/application.js' 
    resource url:'js/ui.geo_autocomplete.js' 
  } 
}

So, you can use either of the two methods -- explicitly specify resources, or use adhoc loading (add the following to your Config.groovy: )

grails.resources.adhoc.includes = [] 
grails.resources.adhoc.excludes = ["*"]

It essentially disables adhoc resource processing.

这篇关于Heroku,Grails:如果使用多个Web dynos,缺少资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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