Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is get_result() a required call for put_async() in Google App Engine

With the new release of GAE 1.5.0, we now have an easy way to do async datastore calls. Are we required to call get_result() after calling 'put_async'?

For example, if I have an model called MyLogData, can I just call:

put_async(MyLogData(text="My Text"))

right before my handler returns without calling the matching get_result()? Does GAE automatically block on any pending calls before sending the result to the client?

Note that I don't really care to handle error conditions. i.e. I don't mind if some of these puts fail.

like image 437
Amir Avatar asked May 19 '11 16:05

Amir


1 Answers

I don't think there is any sure way to know if get_result() is required unless someone on the GAE team verifies this, but I think it's not needed. Here is how I tested it.

I wrote a simple handler:

class DB_TempTestModel(db.Model):
    data = db.BlobProperty()

class MyHandler(webapp.RequestHandler):
    def get(self):
        starttime = datetime.datetime.now()
        lots_of_data = ' '*500000
        if self.request.get('a') == '1':
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
        if self.request.get('a') == '2':
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
        self.response.out.write(str(datetime.datetime.now()-starttime))

I ran it a bunch of times on a High Replication Application.

The data was always there, making me believe that unless there is a failure in the datastore side of things (unlikely), it's gonna be written.

Here's the interesting part. When the data is written with put_async() (?a=2), the amount of time (to process the request) was on average about 2 to 3 times as fast as put()(?a=1) (not a very scientific test - just eyeballing it).

But the cpu_ms and api_cpu_ms were the same for both ?a=1 and ?a=2.

From the logs:

ms=440 cpu_ms=627 api_cpu_ms=580 cpm_usd=0.036244

vs

ms=149 cpu_ms=627 api_cpu_ms=580 cpm_usd=0.036244

On the client side, looking at the network latency of the requests, it showed the same results, i.e. `?a=2' requests were at least 2 times faster. Definitely a win on the client side... but it seems to not have any gain on the server side.

Anyone on the GAE team care to comment?

like image 58
Amir Avatar answered Oct 26 '22 17:10

Amir