Multiple Server Instances - How do they work?

34 views
Skip to first unread message

Randy Walsh

unread,
Nov 28, 2011, 3:25:12 PM11/28/11
to google-a...@googlegroups.com
Multiple Server Instances - How do they work?
 

I’m new to Google AppEngine and am trying to understand more about how applications run distributed across multiple servers.

 

What I’m wondering is this.  If I create a GO application, with a global variable, such “Counter” in the code below.  Each time a user hit’s the page, the counter is shown and incremented.  In all cases that I’ve tried, this works fine, even with multiple users.  Each user getting the next counter. However, what if the google infrastructure starts spreading my application to other servers.  What happens then?

 

#1) Does each new server instance get a copy of the active memory space (starting off from the last known Counter)? do they start at zero again?

#2) If multiple server instances are created, are they ever consolidated again (who wins in a consolidated memory roundup?) 

#3) When a user connects during a session (eh, whatever that is), is he guaranteed to get the same server again? The same memory space again (if moved to another server)?

 

Is this stuff documented somewhere? 

 

 

Thanks in advance,

 

Randy

 

package main

 

import (

    "http"

    "fmt"

)

 

var Counter int

 

func init() {

       http.HandleFunc("/", httpRootHandler)

}

 

func httpRootHandler(response http.ResponseWriter, request *http.Request) {

    response.Header().Set("Content-Type", "text/plain; charset=utf-8")

 

       fmt.Fprint(response, "Current counter is ", Counter)

       Counter++

}

 

 

 

Brandon Wirtz

unread,
Nov 28, 2011, 11:11:56 PM11/28/11
to google-a...@googlegroups.com

Memcache and DataStore as shared, Variables are not.  If you built a hit counter you would need to increment the datastore with every hit.

 

Data store only allows you to change a value once a second, so you’d have to create new values.

 

Likely you would be doing something like

 

Hit!

Add IP to Datastore as new entity (  <increment> , IP, Time)

Display the <increment> Value as Hit counter

 

You can also do things like

Add IP to Memache array,

Echo Memcache array,

 

Which would return IP’s from all visitors on all instances, until the memcache flush occurred.

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/JxW2kx72hfUJ.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Reply all
Reply to author
Forward
0 new messages