Memcache Latency Time Too High?

435 views Asked by At

I have below code working on GAE. When getting the items from memcache I get a latency around 30 ms for 5 to 20 results only. Isn't it too high? Is there anyway I can improve it?

        @SuppressWarnings({ "unchecked"})
        @ApiMethod(name = "queryDesire2")
        public List<String> queryDesire2(
                @Nullable @Named("name2") String name2){
            EntityManager mgr = getEntityManager();
            List<String> list1=new ArrayList<String>();
            Key userKey=null;
            Long x=0L;
            List<Key> keysNew = new ArrayList<Key>();
            MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();

            try {
                    userKey=KeyFactory.createKey(name2,1);
                    if (memcache.get(userKey)==null) {
                        Query query2 = mgr.createQuery("select d.good from Desire d where d.ctgry = :name2");        
                        list1 = query2.setParameter("name2", name2).getResultList();          

                        for (String d : list1){
                        x=x+1L;
                        userKey = KeyFactory.createKey(name2,x);                            
                        memcache.put(userKey, d);
                        memcache.put(name2+"no", x);
                        }
                    } else {
                        Long y=(Long) memcache.get(name2+"no");
                    for (x = 1L; x<=y; x++){
                        userKey=KeyFactory.createKey(name2,x);
                        keysNew.add(userKey);
                    }   
                        Map mMap;
                        mMap = memcache.getAll(keysNew);
                        list1 = new ArrayList<String>(mMap.values());
                    }

             }
            finally {
                mgr.close();
            }
            return list1;


        } 

EDIT:

enter image description here

I captured this snapshot from https://appengine.google.com/... logs. I assumed that 26ms on the top one is the latency. But also I realized there is cpu_usd: 0.000035. What my real concern is to understand how much instance hour will my application use. Is there any formula or way to calculate that?

2

There are 2 answers

2
Andrei Volgin On BEST ANSWER

You can put all objects in a single call. You can also use AsyncMemcacheService - it will work a little faster with put calls.

Just remember:

The "multi" batch operations can have any number of elements. The total size of the call and the total size of the data fetched must not exceed 32 megabytes.

0
Dave W. Smith On

The memcache available through App Engine is either shared or dedicated. With shared, which is what I assume you're using, you're in a pool with other users, and latency is going to depend a lot on what they're up to at the moment.