为什么 Google App Engine 只支持单线程执行? [英] Why does Google App Engine support a single thread of execution only?

查看:17
本文介绍了为什么 Google App Engine 只支持单线程执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么 Google App Engine 只允许一个已部署应用程序的执行线程吗?

Does anybody have an idea why Google App Engine permits only a single thread of execution for a deployed application?

我个人认为它与应用程序的可预测性有关,以便 Google 可以更可靠地调整其性能.Google 的网站上似乎没有关于单线程执行的任何理由,因此我提出了问题.

I personally believe that it has something to do with the predictability of an application so that Google can size its performance more reliably. There does not appear to be any rationale posted on Google's site regarding single threaded execution hence my question.

拥有一个已经是多线程且目前部署在 VM 上的应用程序意味着鉴于此限制,我很难迁移到云中.

Having an application that is already multi-threaded and presently deployed on a VM means that it is difficult for me to move to the cloud given this restriction.

编辑:我已经在下面标记了答案,因为由于水平缩放要求而不允许线程听起来很合理.自然地,线程都在同一个进程空间内执行,并且由于 GAE 可以为您的应用程序运行多个进程,因此共享线程将很困难.也就是说,我仍然认为每个进程一个小的线程池会很有用,并且可能有助于将应用程序迁移到云中.我将要求将此作为一项功能.感谢讨论!

EDIT: I've marked the answer below as it sounds quite plausible that threads are not permitted due to horizontal scaling requirements. Naturally threads all execute within the same process space and, as GAE can run many processes for your application, it would be difficult to share threads. That said, I still think that a small thread pool per process would be useful and might help migrate apps to the cloud. I shall request this as a feature. Thanks for the discussion!

推荐答案

在 Google App Engine 中,有一种有限的替代方案可以替代生成线程,称为任务队列:http://code.google.com/appengine/docs/python/taskqueue/

There is a limited alternative to spawning threads in Google App Engine called task queues: http://code.google.com/appengine/docs/python/taskqueue/

编辑

来自 http://code.google.com/appengine/docs/java/runtime.html#The_Sandbox:

允许 App Engine 分发跨应用请求多个网络服务器,并防止一个应用程序从干扰另一个,应用程序运行在受限的沙箱"环境.在在这种环境下,应用程序可以执行代码,存储和查询数据App Engine 数据存储区,使用 App引擎邮件、URL 获取和用户服务,并检查用户的网络请求并准备响应.

To allow App Engine to distribute requests for applications across multiple web servers, and to prevent one application from interfering with another, the application runs in a restricted "sandbox" environment. In this environment, the application can execute code, store and query data in the App Engine datastore, use the App Engine mail, URL fetch and users services, and examine the user's web request and prepare the response.

就像其他人指出的那样,出于安全原因,沙盒应用程序不支持线程.

Like other people have pointed out, threads are not supported for securities reason to sandbox applications.

Google App Engine 中还有许多其他限制迫使开发者创建可扩展的应用.我相信任务队列只是这些限制中的另一个,因为与在处理 HTTP 请求的当前机器上创建线程相反,任务被放入一个队列中,然后可以由其他机器安排和执行.任务队列允许以可扩展的方式在机器之间共享和分配工作.

There are many other restrictions within Google App Engine that forces developers to create scalable apps. I believe task queues are just another one of these restrictions because, as opposed to creating a thread on the current machine handling the HTTP request, a task is put into a queue which can then be schedule on and executed by other machines. Tasks queues allow work to shared and distributed amongst machines in a scalable manner.

这篇关于为什么 Google App Engine 只支持单线程执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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