On Friday, September 16, 2016 at 7:58:26 AM UTC-4, Przemysław Loesch wrote:
>
> Massimo thank you very much for your answer. I have one more question a 
> bit out of the topic.
> Is it a way to increase web2py efficiency when it is used only for 
> database transactions and user authorization? I don't use web2py html 
> helpers, forms, views processing etc. Complete GUI of my app is created in 
> javascript and calls web2py asynchronously just to get some data as json. 
> In these conditions is it a part of web2py which could be "turned off" eg. 
> by removing imports of unnecessary modules or by setting variables? So far 
> the speed the server responses is very good but soon I'll have much bigger 
> load and just want to be sure that server side process is as 
> straightforward as it can be.
>

There is not really much framework functionality you can turn off or forego 
in order to increase performance, but here are a few things to consider:

On a given request, if you don't need the session, you should call 
session.forget(response) in order to skip checking the session for changes. 
For a bigger benefit, you can completely disable sessions for particular 
routes by using the pattern-based re-write system and adding 
dict(web2py_disable_session=True) to any relevant routes (see this example 
<https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Python/web2py/app/optimized/models/app.py>).
 
Unfortunately, this doesn't work with the parameter-based rewrite system.

Whenever you fetch data using the DAL, if you don't need the .update_record 
or .delete_record methods, do .select(..., cacheable=True), which will 
slightly speed up the creation of the Row objects. More generally, you can 
specify your own custom processor via .select(..., 
processor=custom_processor), which allows you to forego the creation of a 
Rows object altogether -- instead, your custom processor receives the list 
of tuples returned by the database driver, and you can do whatever minimal 
processing you need.

You can also skip the Auth initialization code on any routes that will not 
need Auth or any auth.user data (actually, you can get auth.user data for 
logged in users directly from session.auth.user).

There's another trick to get a modest speedup -- put your controller code 
in a module, import it in a model file, and send the response directly from 
the model (see this example 
<https://github.com/TechEmpower/FrameworkBenchmarks/blob/5a4cf634bb6fe53634778beb86e9b1cf93a69e29/frameworks/Python/web2py/app/optimized/models/app.py>).
 
Probably only worth it on requests that are otherwise very fast (i.e., not 
involving the database).

There are, of course, many other things you can do to improve efficiency, 
such as compiling the app and caching as much as possible.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to