I have a web app that I would like to have the following functionality:
- user gives a url
- webapp gets json data from that url and others from same website (this can take anywhere from 1-10 seconds)
- webapp uses data to generate page for user
With this approach, I believe that if the server is in the process of getting the data for one user, then the other user won’t be able to load the page (server busy). I would like to avoid this if possible.
It seems like the Google Tasks API would be useful for this, but I don’t see how I can run the task, and then use the output of the task to generate the page (how would the main app know when the task was finished?)
What is the best way to resolve this?
Thanks in advance
Some ideas:
1) App engine can serve more than one request at a time. Try it out – app engine will probably spin up more than one instance of your app => multiple requests can be done at once. With request times so long though, I wouldn’t expect it to scale much though (they recommend request/response time in under 1 second – see this link).
2) If you wanted to return quickly to the user, you could enqueue to the task queue as you suggested. Then have the user’s webpage (via meta tag http-equiv or JavaScript perhaps) poll the server every couple seconds to see if the page is ready.
3) If the generated page may be needed again, you should consider memcaching it to try to save the effort of generating it again. With load times of 10 seconds, you might even consider storing them in the datastore for a little while (if caching is appropriate for your app).
Here’s a very basic example of how you might do this: