2

In my GAE server the Datastore Read Operation is reaching to 100% after 12 hrs and I have about 20 users.

Along with other operations in my app I built a chat in which users that is connected to my app is pooling the server every 1 sec. Therefore I have a lot of request to /message but I'm not accessing the datastore.

Is there a correlation between the number of requests to /message (about 42K) with the maximum Datstore Read Operation (50k) ?

enter image description here

Edited:

code of /message:

ArrayListMultimap<String, ChatMessage> messages;
ServletContext application = null;

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{

    if (application == null)
    {
        application = getServletContext();
        messages = ArrayListMultimap.create();          
    }       

    out = response.getOutputStream();
    oos = new ObjectOutputStream(out);  
    Object o = ServerUtils.readObject(request);

    if(o instanceof ChatMessage)
    {
        ChatMessage message = (ChatMessage) o; 
        messages.put(message.getReciverId(), message);          
        List<ChatMessage> list = (List<ChatMessage>) messages.get(message.getReciverId());              
    }

    else if(o instanceof String)
    {           
        String sender = (String) o;
        List<ChatMessage> list = (List<ChatMessage>) messages.removeAll(sender);
        ArrayList<ChatMessage> newList = new ArrayList<ChatMessage>(list);
        reponseToClient(newList);
    }


}
Rami
  • 2,098
  • 5
  • 25
  • 37

2 Answers2

2

A good place to start is to setup Appstats. This will show you were the datastore reads are occurring and which reads are taking a long time. https://developers.google.com/appengine/docs/java/tools/appstats

Also, instead of polling, consider using using channelApi or xmpp for messages. https://developers.google.com/appengine/docs/java/xmpp/overview https://developers.google.com/appengine/docs/java/channel/

Rob Curtis
  • 2,245
  • 24
  • 33
0

Is your app session-enabled? Sessions work by storing its data in the datastore for persistence, and this could be what being read every time a request coming in to the /message handler.

Ibrahim Arief
  • 8,742
  • 6
  • 34
  • 54
  • Sessions also use memcache, so if memcache is available, he should not see 1:1 between requests and reads. – Peter Knego Aug 17 '12 at 09:39
  • @PeterKnego yes, but we don't know what is the hit/miss rate of the memcache for the OP's session. Requests hitting the app every one second per user is not particularly memcache-friendly. I'm not suggesting all read ops came from the session reads, but a significant portion of it might be. – Ibrahim Arief Aug 17 '12 at 10:58
  • Yes I'm using sessions in /sign – Rami Aug 17 '12 at 11:05
  • @Rami CMIIW, but I think enabling sessions in GAE is an [application-wide configuration](https://developers.google.com/appengine/docs/java/config/appconfig#Enabling_Sessions), and not something you could enable in a per-handler basis. So I suspect even if your /message handler is not using sessions, the persisted session is still preloaded from the datastore by the GAE servlet. [This SO answer](http://stackoverflow.com/a/1135158/752918) appears to point to the same direction. – Ibrahim Arief Aug 17 '12 at 11:35
  • I built now new test server with session enabling that not using datastore and the Datastore Read Operation didn't change. So I'm guessing that although /message has 42K the problem white depleting the quota is with /sign requests. – Rami Aug 17 '12 at 12:23
  • @Rami Could you clarify a bit? So when you disable sessions, the datastore read ops counter in the dashboard stays the same? – Ibrahim Arief Aug 20 '12 at 10:46
  • No I didn't disabled sessions and the the datastore read ops counter stayed the same. Meaning I can have has many request to /message handler and the counter w'll stay the same. – Rami Aug 20 '12 at 11:26