Google App Engine 超时?

发布于 2024-12-03 01:53:53 字数 1735 浏览 2 评论 0原文

在 Google App Engine 应用程序中,我使用以下行从站点读取页面:

  String Url="http://...",line,Result="";

  URL url=new URL(Url+"?r="+System.currentTimeMillis());
  BufferedReader reader=new BufferedReader(new InputStreamReader(url.openStream()));

  while ((line=reader.readLine())!=null) { Result+=line+"\n"; }
  reader.close();

但我收到以下错误:

Uncaught exception from servlet
com.google.apphosting.api.DeadlineExceededException: This request (f5e2889605d27d42) started at 2011/09/07 03:20:41.458 UTC and was still executing at 2011/09/07 03:21:30.888 UTC.
    at sun.misc.Unsafe.park(Native Method)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1037)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1326)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:276)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:82)
    at com.google.appengine.tools.development.TimedFuture.get(TimedFuture.java:55)
    at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:69)
    at com.google.apphosting.runtime.ApiProxyImpl.doSyncCall(ApiProxyImpl.java:177)
    at com.google.apphosting.runtime.ApiProxyImpl.access$000(ApiProxyImpl.java:56)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:150)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:148)
    at java.security.AccessController.doPrivileged(Native Method)

似乎花费的时间比等待的时间长,如果该站点速度很慢,我该怎么办?

In a Google App Engine app I used the following lines to read a page from a site :

  String Url="http://...",line,Result="";

  URL url=new URL(Url+"?r="+System.currentTimeMillis());
  BufferedReader reader=new BufferedReader(new InputStreamReader(url.openStream()));

  while ((line=reader.readLine())!=null) { Result+=line+"\n"; }
  reader.close();

But I got the following error :

Uncaught exception from servlet
com.google.apphosting.api.DeadlineExceededException: This request (f5e2889605d27d42) started at 2011/09/07 03:20:41.458 UTC and was still executing at 2011/09/07 03:21:30.888 UTC.
    at sun.misc.Unsafe.park(Native Method)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1037)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1326)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:276)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:82)
    at com.google.appengine.tools.development.TimedFuture.get(TimedFuture.java:55)
    at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:69)
    at com.google.apphosting.runtime.ApiProxyImpl.doSyncCall(ApiProxyImpl.java:177)
    at com.google.apphosting.runtime.ApiProxyImpl.access$000(ApiProxyImpl.java:56)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:150)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:148)
    at java.security.AccessController.doPrivileged(Native Method)

Seems it took longer than it would like to wait, what can I do if that site is slow ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对你而言 2024-12-10 01:53:53

在以下情况下会引发 DeadlineExceededException您的代码,处理对 Web 应用程序的请求需要 30 秒以上的时间。大概您的代码需要一段时间来处理,因为它必须等待从其他站点接收数据的时间很长。

您可以在任务队列上创建任务来获取和处理该数据,并更改您的网络请求/响应流以回复您的任务进度。

A DeadlineExceededException is thrown when your code, handling the request to your web application takes over 30 seconds to process. Presumably your code is taking a while to process because of the length of time it had to wait to receive data from some other site.

You can create a task on a task queue to fetch and process that data, and change your web request/response flow to reply with progress on your task.

不乱于心 2024-12-10 01:53:53

如果您的代码在请求处理程序内运行,则默认情况下 App-Engine 强制执行 60 秒的截止时间。你无法改变它。请参阅本页“缩放类型”下图表的“截止日期”行/“自动缩放”列:

https://developers.google.com/appengine/docs/java/modules/

但是,如果您将模块更改为使用“手动缩放”并且“B1”-“B4” 实例。示例:

default/src/main/webapp/WEB-INF/appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>myapp</application>
  <module>default</module>
  <version>1</version>
  <threadsafe>true</threadsafe>

  <instance-class>B1</instance-class>
  <manual-scaling>
    <instances>1</instances>
  </manual-scaling>
</appengine-web-app>

在此类实例上,您的请求通常不会超时数小时。 (该文件声称截止日期是“无限期”。)

If your code is running inside a request handler, then by default there is an App-Engine-enforced 60 second deadline. You can't change it. See the "Deadlines" row / "automatic scaling" column of the chart on this page under "Scaling types":

https://developers.google.com/appengine/docs/java/modules/

However, this code will be able to run for some hours if you change your module to use "manual scaling" and a "B1"-"B4" instance. Example:

default/src/main/webapp/WEB-INF/appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>myapp</application>
  <module>default</module>
  <version>1</version>
  <threadsafe>true</threadsafe>

  <instance-class>B1</instance-class>
  <manual-scaling>
    <instances>1</instances>
  </manual-scaling>
</appengine-web-app>

On this type of instance, your requests will typically not time out for hours. (The documentation claims that the deadline is "indefinite".)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文