Instance hours are determined by how long an App Engine instance is 
running. What the instance does while running only affects instance hours 
if it takes a long time to execute its code, thus extending how long it is 
operational.

Assuming 'request' is the parameter provided to the servlet method of type 
HttpServletRequest 
<http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html>,
 
this data resides in memory while responding to the request and thus does 
not require any additional external resources. The same can be said about 
chatRoomConcurrentMap. Neither of these should affect instance hours.

I must point out that this architecture requires that only a single 
instance be run and that it be running uninterrupted at all times. If 
requests to this application get low enough in frequency and have enough 
time between them, the instance may shut down to save on operation only to 
spin up later. When this occurs, variables instantiated in the first 
instance will be lost and therefore, not reachable by the next instance. In 
addition, if the maximum number of instances is not capped at 1 in your 
appengine-web.xml 
<https://cloud.google.com/appengine/docs/java/config/appconfig#scaling_and_instance_types>,
 
additional instances may spin up with an influx a requests. In these 
situations, the variables from one instance will not be available to other 
instances.

If you need this application to scale with demand, you would need to 
separate your application state (chatroom messages and present users) from 
the request-handling runtime. I would consider using Datastore 
<https://cloud.google.com/appengine/docs/java/gettingstarted/usingdatastore> 
or Cloud SQL <https://cloud.google.com/appengine/docs/java/cloud-sql/> to 
store chat messages and memcache 
<https://cloud.google.com/appengine/docs/java/memcache/> in the middle to 
mostly reduce data retrieval costs. More real-time (low-latency) and 
scalable solutions could employ Managed VMs 
<https://cloud.google.com/appengine/docs/java/managed-vms/>. An example of 
a chat service over websockets can be found at the bottom of the previously 
linked page.

On Tuesday, January 19, 2016 at 9:13:21 PM UTC-5, Hung Ha wrote:
>
> I got an app built on top of App Engine.
>
> We got a User class and many other classes as well. When user loged in.
>
> How Google count the Instance hours when I do the following:
>
> User user=request.getParameter("user");
>
> I also have public static variable to hold chat messages & that could be 
> called every 5 seconds if a user enter chat room (*note:* if many users 
> enter the chat room then that variable could be called many times every 5 
> seconds), as the following:
>
> public static Map<User, ConcurrentHashMap<User, 
> CopyOnWriteArrayList<String>>> chatRoomConcurrentMap=new 
> ConcurrentHashMap<User, ConcurrentHashMap<User, 
> CopyOnWriteArrayList<String>>>();
>
> If that is the case then how Google count the instance hours of that 
> static variable?
>
> SO, *How does Google count instance hour when we instantiate an object 
> and when we call a public variable?*
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/d5f15d18-ee4c-436f-8325-a601e627d2c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to