views:

255

answers:

1

Say my app has a page on which people can add comments. Say after each comment is added a taskqueue worker is added. So if a 100 comments are added a 100 taskqueue insertions are made.

(note: the above is a hypothetical example to illustrate my question)

Say I wanted to ensure that the number of insertions are kept to a minimum (so I don't run into the 10k insertion limit)

Could I do something as follows.

a) As each comment is added call taskqueue.add(name="stickytask", url="/blah") - Since this is a named taskqueue it will not be re-inserted if a taskqueue of the same name exists.

b) The /blah worker url reads the newly added comments, processes the first one and than if more comments exist to be processed returns a status code other than 200 - This will ensure that the task is retried and at next try will process the next comment and so on.

So all 100 comments are processed with 1 or a few taskqueue insertion. (Note: If there is a lull in activity where no new comments are added and all comments are processed than the next added comment will result in a new taskqueue insertion. )

However from the docs (see snippet below) it notes that "the system will back off gradually". Does this mean that on each "non 200" Http status code returned a delay is inserted into the next retry?

From the docs: If the execution of a particular Task fails (by returning any HTTP status code other than 200 OK), App Engine will attempt to retry until it succeeds. The system will back off gradually so as not to flood your application with too many requests, but it will retry failed tasks at least once a day at minimum.

+1  A: 

There's no reason to fake a failure (and incur backoff &c) -- that's a hacky and fragile arrangement. If you fear that simply scheduling a task per new comment might exceed the task queues' currently strict limits, then "batch up" as-yet-unprocessed comments in the store (and possibly also in memcache, I guess, for a potential speedup, but, that's optional) and don't schedule any task at that time.

Rather, keep a cron job executing (say) every minute, which may deal with some comments or schedule an appropriate number of tasks to deal with pending comments -- as you schedule tasks from just one cron job, it's easy to ensure you're never scheduling over 10,000 per day.

Don't let task queues make you forget that cron is also there: a good architecture for "batch-like" processing will generally use both cron jobs and queued tasks to simplify its overall design.

To maximize the amount of useful work accomplished in a single request (from ether a queued task or a cron one), consider an approach based on monitoring your CPU usage -- when CPU is the factor limiting the work you can perform per request, this can help you get as many small schedulable units of work done in a single request as is prudently feasible. I think this approach is more solid than waiting for an OverQuotaError, catching it and rapidly closing up, as that may have other consequences out of your app's control.

Alex Martelli
molicule
but it does get you around the limit/day, which is the whole point, right?
Bartosz Radaczyński
And, since I have misread what the point of the question really was, i will mention it here that Brett was refering to the backup scheme as a "simple exponential scheme" in hiss google io talk.
Bartosz Radaczyński
@Bartosz thanks for the io link (http://code.google.com/events/io/sessions/OfflineProcessingAppEngine.html). At 0:57:10 Brett talks about the exponential backoff scheme starting at 100ms. Also the same talk talks about name tombstoning so the answer to my q is is NO one cannot depend on taskqueue retry on failure both because of exponential retry backoff and name tombstoning. @Bartosz you have deleted your answer. Please reinsert it so I can vote it up as best answer.
molicule
@Bartosz re: but it does get you around the limit/day. YES, you are right and given the tombstoning/exponential backoff issues will be the way to go. However, on the same talk at 0:09:20 there is a bit more on its limitations.
molicule