How does memory/state work in google app engine? Server instances
I have a GWT/GAE project that has an arraylist of Strings on the server side. I originally assumed that every client that accesses the app gets its own instance of the server. but today while testing some Strings from someone elses run of the app popped up while I was executing it. I am not using any datastore, just memory. What is the proper way to handle this in GAE? Create a separate class to store the strings and associate an object of that with the client somehow (perhaps by s开发者_如何学运维ending a parameter with a users name with each call to the server?
App Engine spins up as many instances of your app as are necessary to serve the amount of traffic you're getting. Multiple users will be served by one server, and one user may be served by multiple servers. You shouldn't store any per-user state in memory - it's shared, and it's unreliable, as an instance may be shut down at any time.
Indeed, it wouldn't be practical to spin up a new instance of your app for every user: HTTP is stateless, so has no concept of users in the first place, and it would use far too much in the way of resources besides.
You should store per-user state in the Datastore and/or Memcache.
精彩评论