简体   繁体   English

Google App Engine Java程序并发

[英]Google App Engine Java Program concurrency

In order to improve the execution speed of a Java program running in Google App Engine, can I create additional Java threads during the runtime to make use of idle machines in the data center? 为了提高在Google App Engine中运行的Java程序的执行速度,是否可以在运行时创建其他Java线程来利用数据中心中的空闲计算机?

I've found conflicting data thus far. 到目前为止,我发现有冲突的数据。

If your primary concern is to improve the execution time, take a look at Memcache and Tasks. 如果您最关心的是缩短执行时间,请查看Memcache和Tasks。 They can be used to reduce or avoid the latency of reading from or writing to the Datastore or other storage options, fetching URLs, sending emails, etc. If you do a lot of difficult computations that can run in parallel, look at MapReduce API. 它们可用于减少或避免读取或写入数据存储区或其他存储选项,获取URL,发送电子邮件等的延迟。如果您进行了许多可以并行运行的困难计算,请查看MapReduce API。

Once you remove all the delays from your program, there will be no reason to use multiple threads within a single request. 一旦从程序中消除了所有延迟,就没有理由在单个请求中使用多个线程。

Note that App Engine instances can use multithreading to execute multiple requests at the same time, so they tend to use allocated resources efficiently. 请注意,App Engine实例可以使用多线程来同时执行多个请求,因此它们倾向于有效地使用分配的资源。 To enable it, see: 要启用它,请参阅:

https://developers.google.com/appengine/docs/java/config/appconfig#Java_appengine_web_xml_Using_concurrent_requests https://developers.google.com/appengine/docs/java/config/appconfig#Java_appengine_web_xml_Using_concurrent_requests

If you have a problem that calls for a multithreaded solution, you can use threads (as described on the link that you included in your question). 如果遇到需要多线程解决方案的问题,则可以使用线程(如问题中包含的链接所述)。

However, based on your reasoning ("to make use of idle machines in the datacenter"), it seems like you're misguided. 但是,根据您的推理(“使用数据中心中的空闲计算机”),似乎您被误导了。 You should not use threads for that reason. 因此,您不应使用线程。 You use the machines hours that you pay for and not more. 您只需要支付机器使用的小时数,而不会花费更多。 The only time you will have an idle machine is if you tell App Engine to keep around an extra idle machine so that it doesn't have to start up an extra machine your app gets a big usage spike. 唯一会拥有一台闲置机器的情况是,如果您告诉App Engine保持一台额外的闲置机器,从而不必启动一台额外的机器,则您的应用程序会出现大量使用高峰。

Most of the time, unless you are truly doing parallel computation, you won't need to use multiple threads in App Engine. 在大多数情况下,除非您真正进行并行计算,否则您无需在App Engine中使用多个线程。 For instance, the datastore has an asynchronous API so that you can do multiple datastore operations in parallel without having to deal with threads yourself. 例如,数据存储区具有异步API,因此您可以并行执行多个数据存储区操作,而不必自己处理线程。

Does that make sense? 那有意义吗?

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

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