1

I have a problem with performance, and i don't know where it comes from.

The gap between createLogoutURL and the first datastore query is huge... its between the following code passage:

loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));
...
ch.zhaw.ams.server.auth.user.User userAms = DatabaseHelper.findByParama(user.getEmail(), "emailAddress",
                    "String", ch.zhaw.ams.server.auth.user.User.class);

enter image description here

@Override
public GoogleLoginInfo login(String requestUri) {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    GoogleLoginInfo loginInfo = new GoogleLoginInfo();

    if (user != null) {
        loginInfo.setLoggedIn(true);
        loginInfo.setEmailAddress(user.getEmail());
        loginInfo.setNickname(user.getNickname());
        loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));
        loginInfo.setIsGoogleLogin(true);

        ch.zhaw.ams.server.auth.user.User userAms = DatabaseHelper.findByParama(user.getEmail(), "emailAddress",
                "String", ch.zhaw.ams.server.auth.user.User.class);
        if (userAms != null) {
            loginInfo.setFirstname(userAms.getFirstName());
            loginInfo.setLastname(userAms.getLastName());
        }

        // Set Memcache
        try {
            SessionCache.setupCache(user.getEmail());
            loginInfo.setIsCached(true);
        } catch (CacheException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            loginInfo.setIsCached(false);
        }

    } else {
        loginInfo.setLoggedIn(false);
        loginInfo.setLoginUrl(userService.createLoginURL(requestUri));
    }
    return loginInfo;
}

Does anybody has an idea why its so slow?

Ingo
  • 1,552
  • 10
  • 31
Sam
  • 2,707
  • 1
  • 23
  • 32
  • Does google app engine still start a new JVM per request (and stop it when finished) or is that just a rumour? – Peter Lawrey Sep 13 '13 at 09:10
  • If it does, it means you are paying the cost of start up, the cost of warming up the code on every request. There should be a law again such inefficiencies IMHO. Perhaps you should consider an alternative app server, anything else would be much faster. As much 100x faster. – Peter Lawrey Sep 13 '13 at 10:06
  • 2
    It only starts a new one if no instances are currently running. If you have billing enabled you can set a minimum number of instances to keep running. You can also enable warmup requests, that will start an instance and requests won't sent to the instance until it has started up. Make sure the request you are profiling isn't starting a new one instance . – Tim Hoffman Sep 13 '13 at 11:50
  • Normally it will stay up for a minute or so. Try making the call again directly after this and see if you get similar timings. If you do it's spin up time and you'll want to have some idle instances. GAE kills unused instances to keep billing down. If it's infrequently used you'll be paying to keep a server up and running for no reason so they default to the more conservative model so you aren't over billed. – Jason Tholstrup Sep 14 '13 at 04:22
  • Thanks, It's not because of the startup - this is on my local development machine... (Online its the same, it doesn't depend if its running or not.) I have billing enabled. – Sam Sep 15 '13 at 12:53

1 Answers1

0

On the plus side, appstats has narrowed it down to three lines for you:

loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));

loginInfo.setIsGoogleLogin(true);

ch.zhaw.ams.server.auth.user.User userAms = DatabaseHelper.findByParama(user.getEmail(), "emailAddress",
            "String", ch.zhaw.ams.server.auth.user.User.class)

You can probably fiddle around and try to figure out which line causes the delay. My best guess is that this is the first time you're loading the class ch.zhaw.ams.server.auth.user.User.class. This class might be causing other classes to load. The long delay you see might just be the class loading time.

You might be able to add a startup handler to load some of these classes, so it hopefully only appears rarely, but you'll see a lot of complaints about Java class loading time on GAE. It's not a problem that can be completely solved on GAE.

dragonx
  • 14,963
  • 27
  • 44