DeadlineExceededException - how to avoid?

瀏覽次數:1,721 次
跳到第一則未讀訊息

J Keller

未讀,
2009年6月2日 下午3:25:322009/6/2
收件者:Google App Engine
I'm getting this exception. My service is trying to read some data
from another web site, which can take longer than 30 seconds. Is
there anyway I can avoid or handle this?

com.google.apphosting.api.DeadlineExceededException: This request
(81a5d375fd2b99be) started at 2009/05/28 14:22:03.542 UTC and was
still executing at 2009/05/28 14:22:32.008 UTC.
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos
(Unknown Source)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos
(Unknown Source)
at java.util.concurrent.CountDownLatch.await(Unknown Source)
at com.google.net.rpc.util.RpcWaiter.waitForRpcsToFinish
(RpcWaiter.java:96)
at com.google.apphosting.runtime.ApiProxyImpl.doSyncCall
(ApiProxyImpl.java:81)
at com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall
(ApiProxyImpl.java:54)
at com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall
(ApiProxyImpl.java:32)
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:72)
at com.google.appengine.api.datastore.DatastoreApiHelper.makeSyncCall
(DatastoreApiHelper.java:47)
at com.google.appengine.api.datastore.DatastoreServiceImpl$2.run
(DatastoreServiceImpl.java:169)
at
com.google.appengine.api.datastore.TransactionRunner.runInTransaction
(TransactionRunner.java:29)
at com.google.appengine.api.datastore.DatastoreServiceImpl.put
(DatastoreServiceImpl.java:157)
at com.google.appengine.api.datastore.DatastoreServiceImpl.put
(DatastoreServiceImpl.java:137)
at com.google.appengine.api.datastore.DatastoreServiceImpl.put
(DatastoreServiceImpl.java:129)

Nick Johnson (Google)

未讀,
2009年6月2日 下午4:09:272009/6/2
收件者:google-a...@googlegroups.com
Hi,

You can catch the first DeadlineExceededException, after which you have a short time (less than a second) to wrap up your request and return a response to the user. If you fail to do so, a second, uncatchable exception is thrown to terminate your script.

-Nick Johnson

J Keller

未讀,
2009年6月2日 下午5:20:302009/6/2
收件者:Google App Engine
Okay, thank you Nick.

Is there any way I can somehow continue processing, after returning a
response to the user?

If not, I suppose I could spin off multiple threads on the server
side, and hope they all finish in time.

Thanks again.

-J

Wooble

未讀,
2009年6月3日 上午9:13:472009/6/3
收件者:Google App Engine


On Jun 2, 5:20 pm, J Keller <jpaulkel...@gmail.com> wrote:
> If not, I suppose I could spin off multiple threads on the server
> side, and hope they all finish in time.

No, you can't. It's impossible to create new threads.

J Keller

未讀,
2009年6月3日 上午9:51:352009/6/3
收件者:Google App Engine
Ouch. So does this mean I can't use the GAE to do any operation
that's going to take longer than 30 seconds?

Surely that's not the case - that would change it from being a very
useful tool, to one which is useless (for me, anyway).

I hope I'm missing something...

Wooble

未讀,
2009年6月3日 上午10:09:322009/6/3
收件者:Google App Engine
Long running processes are on the roadmap, but at the moment, GAE is
intended to serve web applications. Most users of web applications
don't want to sit around waiting 30 seconds for their requests to do
anything.

fel

未讀,
2009年6月3日 上午10:46:532009/6/3
收件者:Google App Engine
yeah but what if it is a banking app that needs to do all sorts of
complex transactional processing?

Scott Seely

未讀,
2009年6月3日 上午11:17:592009/6/3
收件者:google-a...@googlegroups.com
You have access to cron jobs which can handle long running work. See
http://code.google.com/appengine/docs/java/config/cron.html for java,
http://code.google.com/appengine/docs/python/config/cron.html for python.

You'll have to have something that allows a webrequest to put a workitem
into a queue that is persisted in the datastore. When your cron job wakes
up, it should interrogate the queue and keep going until the queue is empty.

Wooble

未讀,
2009年6月3日 下午1:04:482009/6/3
收件者:Google App Engine


On Jun 3, 10:46 am, fel <felipeval...@gmail.com> wrote:
> yeah but what if it is a banking app that needs to do all sorts of
> complex transactional processing?

Any bank that would trust the Datastore, with its inability to do
transactions across entity groups, to handle its data is probably run
about as well as, well, American banks.

J Keller

未讀,
2009年6月3日 下午5:08:392009/6/3
收件者:Google App Engine
That might help some, but according to the docs:

A cron job will invoke a URL at a given time of day. A URL invoked
by cron is subject to the same limits and quotas as a normal HTTP
request, including the request time limit.

Unfortuantely, I don't think I can reasonably break my task down into
(20 or fewer) small enough pieces to not exceed that time limit.

I'll keep investigating other approaches, thanks Scott.

-J

Wooble

未讀,
2009年6月3日 下午6:57:102009/6/3
收件者:Google App Engine
You may want to look in to the remote API if you want long-running
processes without waiting for them to be added; you'll have to provide
your own hardware and use the bandwidth to send your data back and
forth, but you can do whatever processing you want and you can do it
now.

Scott Seely

未讀,
2009年6月4日 清晨7:57:232009/6/4
收件者:google-a...@googlegroups.com
If this is the issue, you might find that AWS or Azure meets your needs
better. It seems that GAE, as of now, is more tuned for simpler web sites
and not for more complex processing.

I suspect that there might be a workaround where, around the 25 second mark,
reinvoke the URL with some state information to resume the work. Another
alternative is to figure out how to quantize your work, then have a local
server app invoke the right URLs as needed. I know that this is suboptimal,
but if you are committed to using GAE, it might be needed. The local server
can be pretty low end if it is just invoking URLs.

-----Original Message-----
From: google-a...@googlegroups.com
[mailto:google-a...@googlegroups.com] On Behalf Of J Keller
Sent: Wednesday, June 03, 2009 4:09 PM
To: Google App Engine
Subject: [google-appengine] Re: DeadlineExceededException - how to avoid?


J Keller

未讀,
2009年6月16日 下午3:15:042009/6/16
收件者:Google App Engine
Thank you Scott - that redirect trick worked great.

After processing a subset of the data, I simply redirect back to my
service. Each time it caches more of the data, until the job is
complete. Sometimes this can cause the browser to give up and report
an 'infinite redirect loop', but it usually works fine. And even when
the it does give up, if the user tries again it usually finishes the
process fine.

Thanks again!

bd_

未讀,
2009年6月16日 下午3:21:142009/6/16
收件者:Google App Engine
It should be fairly straightforward to handle this polling in
Javascript, eliminating the infinite redirect loop and allowing for
the possibility of giving status readouts for the user :)

J Keller

未讀,
2009年6月17日 下午2:30:422009/6/17
收件者:Google App Engine
> It should be fairly straightforward to handle this polling in
> Javascript, eliminating the infinite redirect loop and allowing for
> the possibility of giving status readouts for the user :)

That sounds promising. I very familiar with Java, but have just
started playing with javascript recently.

So basically you are suggesting that the client-side script would
loop, calling my service that would return with the GAE's 30 second
limit?
And, within that loop I could also update the client's page? That
would be great.

I'll see what I can figure out, thanks!

Francois Masurel

未讀,
2011年5月16日 上午11:34:042011/5/16
收件者:google-a...@googlegroups.com
Does this still work with SDK 1.5.0 ? It doesn't seem to be the case.

And why are instances restarted causing "Server Error" responses after these exceptions ?

Thanx for your help.

Francois
回覆所有人
回覆作者
轉寄
0 則新訊息