Thanks for sharing your question and situation here.

>From what I understand of your scenario, accessing a large array of 
integers from memcache and occasionally Datastore is not quite as fast as 
is needed for your implementation.

The fastest as you suggested would be to have all constants loaded within 
instance memory.  There would be a few different points to consider if 
using this route that regard performance:

   - Compile time
   - Start-up time
   - Read time
   
Compile time
This cost is only paid once and is not incurred by your end users which I 
believe is your main concern.

Start-up time
This may be longer if hard-coding all your constants into your Java code. 
 This would still only be paid when starting instances and may not be all 
that significant.  I might suggest testing start-up times with some logging 
to really know what the time cost would be.  This time however, will not 
affect too many end-users barring the occasional ones to be waiting for 
instance to be available.

Read time
This should be very fast with an *int* 
<https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html> 
array and still quite fast with a *HashMap* 
<https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html>.  Both 
of these would have a negligible memory footprint if existing once per 
instance (as opposed to once per request).

If you noticed start-up time being a problem, you could instead store the 
constants in a file accessible to your App Engine service using 
*<resource-files>* 
<https://cloud.google.com/appengine/docs/java/config/appref#resource_files> 
or a Cloud Storage bucket 
<https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/read-write-to-cloud-storage#reading_from_cloud_storage>
 
and only load it upon the first request.  For example in pseudo-code:
HashMap constants = null;


private void loadConstants() {
  // retrieve values from constants.json
  // and set to constants HashMap
}


public void doGet(...) {
  if (constants == null) {
    loadConstants();
  }
  // serve response
}

The trade off here is that the time cost of getting the constants into 
instance memory is only paid during the first request.  You should also 
consider deferring it to a warm-up request 
<https://cloud.google.com/appengine/docs/java/warmup-requests/> as they are 
excellent for these sorts of tasks.

Hope this helps!

On Wednesday, June 8, 2016 at 11:20:03 PM UTC-4, YuRen Lin wrote:
>
> Hi, all
>
> I am in the game industry and use Google App Engine as my backend server. 
> My problem is we do the game logic calculation in the server side and use 
> thousands of Constants which read from csv files. Our current solution is 
> to read CSV files and store them into the datastore. Then when a request 
> comes, the servlet checks memcache first, if miss read from datastore. This 
> is done automatically by Objectify. I am wondering if there is other more 
> effective way to do this. 
>
> Other solutions include:
> 1. store all constants in the servlet as int array. But I think the launch 
> overhead may be a lot, since there are thousands more constants.
> 2. read constant from csv files each time the servlet needs it. I don't 
> think this is a good idea.
>
>
> Thanks in advance. First time to post here.
>

-- 
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 google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
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/addc1755-0d84-4018-bec3-faae4f3f18c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to