1
votes

I have a module that works fine when I push it to app engine. When it works it logs stuff nicely and the logs are accessible in the console logs viewer. But then after a while it just stops working and when I try to access any url give me 500 server errors with no info (it just says waiting 30 seconds might be a good idea). When this happens nothing gets logged for requests.

If I restart the module (by pushing my code to app engine) then it works for a little while again.

The module is running a Pyramid app and the configuration file looks a little something like:

application: my_app
module: my_module
version: dev
runtime: python27
api_version: 1
threadsafe: false

instance_class: B2
basic_scaling:
  max_instances: 2
  idle_timeout: 10m

handlers:
- url: /actions/.*
  script: my_module.application
  login: admin
- url: /.*
  script: my_module.application

builtins:
- appstats: off

libraries:
- name: webob
  version: latest
- name: setuptools
  version: latest

includes:
- mapreduce/include.yaml

I think what is happening is that it's hitting the idle timeout and shutting down. I need requests to the module to turn it back on again. How do I do that?

Let me know if you need more info, I'm an app engine noob at this stage. Any help would be greatly appreciated.

3
You need to have a handler deal with /_ah/start warmup requests otherwise an instance willl shut down, however the system should still start up new instances unless you startup time is too long. Is there any particular reason you are using basic scaling rather than automatic scaling ? I build pretty much all of my appengine apps using pyramid - Tim Hoffman
Also any particular reason you don't have threadsafe: true ? - Tim Hoffman
@TimHoffman: re threadsafe: You can put htat down to noobery. I wasn't sure if some of the things I was doing in the app itself were threadsafe and figured I'd play it safe. Re /_ah/ stuff, my application isn't handling it. Would you suggest I make a view that just returns nothing? If you could post some specific code that would be very useful. And re basic scaling, it's because the module is pretty much only accessed via cron. The work it does is very intermittent - Sheena

3 Answers

2
votes

When a module start, App Engine call the url /_ah/start. You mustn't handle this request. In you my_module.application you need to add in the handler who match this request :

    def get(self):
        # Let module start
        if "X-Appengine-Cron" in self.request.headers or "X-AppEngine-TaskName" in self.request.headers  or "X-Appengine-Failfast" in self.request.headers:
            return
2
votes

Even if you hit the idle timeout, AppEngine will spin a new instance when new request is coming in.

Use Cloud Debugger to inspect the state of your application. The debugger makes it easier to view the application state and understand what happens after your app has been running for while.

2
votes

Check the docs on startup state https://cloud.google.com/appengine/docs/python/modules/#Python_Instance_states

you current default handler /.* should be able deal with a /_ah/start if youe handler can gracefully deal with a 404.

Thats how I handle startups. Goes through the main handler which can deal with non existent url requests using the default pyramid not found.

I have a config.add_notfound_view(notfound) registered.