简体   繁体   English

Google App Engine:后端与前端实例

[英]Google App Engine: Backend vs Frontend Instances

GAE allows different restrictions depending on whether or not the code is running on a frontend instance or a backend instance. GAE允许不同的限制,具体取决于代码是在前端实例还是后端实例上运行。 For example, it permits you to kick off long-running background threads on a backend, whereas this would timeout and throw a runtime exception if the code was running on a frontend instance. 例如,它允许您在后端启动长时间运行的后台线程,而如果代码在前端实例上运行,则会超时并抛出运行时异常。

I am very confused about how to engineer an app so that you know that only certain code executes on a backend instance (and not a frontend instance). 我对如何设计应用程序非常困惑,以便您知道只有某些代码在后端实例(而不是前端实例)上执行。

My understanding of how GAE works is that you upload your app (a WAR file) and that it scales (creates clustered instances of) that app as needed or until it exceeds a ceiling that you define (for budgeting, etc.). GAE如何工作的理解是你上传你的应用程序(一个WAR文件),并根据需要扩展你的应用程序(或创建集群实例),直到它超出你定义的上限(用于预算等)。

But unless I'm mistaken, it doesn't allow you to upload different modules (multiple WARs) for the same app, and thus have 1 WAR to be ran on frontend instance, and another WAR to be ran on backend instance (to guarantee that you only run background threads on backends!). 但除非我弄错了,否则它不允许你为同一个应用程序上传不同的模块(多个WAR),因此在前端实例上运行1个WAR,在后端实例上运行另一个WAR(以保证你只在后端运行后台线程!)。

So my question is: how do you develop, package and deploy GAE apps so that the right code always executes on the right instance? 所以我的问题是:您如何开发,打包和部署GAE应用程序,以便正确的代码始终在正确的实例上执行? Tangential to this is the question of how to specify different long-running jobs be ran on specific backends. 与此相关的是如何在特定后端上运行指定不同的长时间运行作业的问题。 For instance if you have a background thread that should be cronned to run nightly at midnight, but you have 10 backends, wouldn't this mean you would have the same background thread kicking off on all ten instances every night? 例如,如果你有一个后台线程,应该在午夜每晚运行,但你有10个后端,这是不是意味着你每晚都会在所有10个实例上开启相同的后台线程? Obviously, there are situations where you only want 1 backend to run the job, and other instances when each backend should behave the same. 显然,在某些情况下,您只需要1个后端来运行作业,而其他实例则需要每个后端的行为相同。

Again, it all comes back to: how do you make sure the right code deploys and executes on the correct instance? 同样,这一切都回到了: 如何确保正确的代码在正确的实例上部署和执行? Thanks in advance! 提前致谢!

backends are addressable directly by name although they share the same code and servlets with other regular/frontend instances within your app. 后端可以直接通过名称进行寻址,尽管它们与应用程序中的其他常规/前端实例共享相同的代码和servlet。

ref: https://developers.google.com/appengine/docs/java/backends/overview 参考: https//developers.google.com/appengine/docs/java/backends/overview

You can direct requests that need to run on a backend, to backendname.yourapp.appspot.com/someroute 您可以将需要在后端运行的请求定向到backendname.yourapp.appspot.com/someroute

You can also configure multiple backends in backends.xml (with different names) and using the same logic, send requests meant for specific backends to their corresponding uri. 您还可以在backends.xml中配置多个后端(使用不同的名称)并使用相同的逻辑,将针对特定后端的请求发送到其对应的uri。

Essentially the same code runs on all instances, but you can design you routing to direct specific requests to named backends instances. 基本上相同的代码在所有实例上运行,但您可以设计路由以将特定请求定向到命名后端实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM