Question

I want my google app engine webapp2 app to start-up (create a new app instance) as quickly as possible. I was wondering what obvious slow downs I should watch out for (I know.. premature optimization, but I don't want to do a massive re-factor at the end if i can help it)

I have a folder hierarchy similar to this:

-root_folder
__init__.py
main.py
config.py
routes.py
models.py
gviz_api.py
... 20 more .py files
-web_folder
    __init__.py
    some_handlers.py
    more_handlers.py
    20 more.py files
    ..
-data_model_folder
    __init__.py
    some_models.py
    more_ndb_models.py
    10 more model files
-many more folders e.g. templates, simpleauth etc.

in main.py , I create an app instance with a router (the router is imported from routes.py). routes.py imports every single handler (assigning each route a handler). Every handler imports almost every datamodel. Will this mean my app is very slow to create a new app instance?

I'm expecting to have about 100 handlers and 30 data models by the end of my project, although many of them will be rarely used.

to import a data model (from inside some_handlers.py)

would just the following be fast enough:

from root_folder.data_model_folder.more_ndb_models import special_model

Should I be looking to use the config / registry ?

Was it helpful?

Solution

Usually, slowdowns are due to importing large frameworks, not large amount of application code. So I wouldn't worry too much about this, even if you have 100 .py files. (Trust me, 100 is not that much...) I'd also look into warmup requests.

I'm not a big fan of lazy import tricks -- they can cause complex failure modes in edge cases (i.e. hard to debug), and they don't benefit from the extra lenience App Engine gives to loading requests (check your logs for what it considers a loading request).

In particular, if you don't import all your model classes at the start, you run the risk of getting "No model class found for kind 'X'" errors.

OTHER TIPS

Webapp2 supports lazily-imported handlers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top