Erel Segal-Halevi
Erel Segal-Halevi

Reputation: 36813

Preloading content in a GWT+AppEngine application

I have an application built with GWT+AppEngine, for automatic creation of quizzes:

  1. The main web page has a button "Create new quiz".

  2. Clicking the button activates a service in the back-end, that creates the quiz and returns it.

  3. The main page then displays the quiz.

The quiz creation takes a lot of time, so I thought of pre-loading a quiz while the user answers a quiz: after displaying the quiz, I activate another service in the back-end, that creates the next quiz and keeps it in a local variable. When the user clicks "create new quiz" again, the back-end notices that there is a pre-created quiz, and returns it immediately.

This works well in development mode on my computer, but doesn't work when I deploy to AppEngine.

It seems that there are several copies of the back-end with all its local variables, so that the "preload" service runs on one copy, and the "return new quiz" runs on another, and doesn't use the preloaded quiz.

Is this so? How many copies of my back-end exist? If the number is constant, I can just run "preload quiz" several times, one for each copy.

Upvotes: 2

Views: 137

Answers (1)

Riley Lark
Riley Lark

Reputation: 20890

The number is not constant, and you should not assume that your backend servers can work in this way.

You must use the provided services like memcache and the datastore to communicate between requests. You should essentially assume that every request is answered by a completely different, completely new instance of your application. Variables in normal memory just don't work well between requests.

Upvotes: 1

Related Questions