Saturday, November 26, 2011

How to make web2py faster

Avoid regenerating tables:
db = DAL('sqlite://storage.sqlite', migrate=runonce) 

Create indexes:
db.executesql('CREATE INDEX IF NOT EXISTS {table}_index ON {table} (id);'.format(table=table))

Compile byte code in admin

Serve static files direct from server

Move as much logic as possible from models into controllers and modules

Disable session if possible

Cache database queries and controller functions:
db().select(db.log.ALL, cache=(cache.ram, 60))

@cache(request.env.path_info, time_expire=5, cache_model=cache.ram)
def index():

No comments: