View caching
What is the fastest way to execute code?

What happens when user requests address www.mydomain.com/shop ?

First of all: main controller from website_sale module will generate all required data for view rendering. Those values will be passed to qweb view renderer  for rendering a view with an ID website_sale.products.

If this view is not found in ormcache by qweb  renderer then the view needs to be compiled. For that the view arch needs to be fetched. But a page view is not a single fetch from a database. It needs to be resolved for a specific user / group, current language, etc. The resulting arch will be cached withing ormcache and feed to qweb compiler. After that, qweb compiler compiles it and caches compiled method in ormcache (view arch is essentially not needed to be cached anymore).

If ormcache is cleared, this cycle is repeated over again: first the arch is generated and qweb render method is compiled.

After invalidating ORM cache within all workers - application starts to throttle as it mostly used things aren't in cache and needs to be fetched from database and/or generated.
This results in mean response time across all Odoo workers until all workers have generated mostly accessed caches.

But why clear cache?

Ormcache is not persistent. So if Odoo server or any of the workers is restarted - cache is purged. Every worker may reach its life cycle end by request limit or memory limit.
And last but surely not least - cache may be cleared to maintain integrity of data. Just try to add an attribute value to a product.


To test out view caching, we have set up cache modules for 3 live site.

All sites has been configured with workers and request limit is set to 8192.

Site 1: is odoo v13.0 with 3 different domains and 5 languages.
Site 2: is odoo v13.0 with 2 languages and over 400k products.
Site 3: is odoo v12.0 with over 350k products.

Site 1 could have been 18.5%; site 2 12.8% and site 3 13.9% faster.
See the detailed statistics below.

Site 1 statistics


Site 2 statistics


Site 3 statistics


Time for conclusion

You will have about 10-25% speed improvement by just caching resolved xml views. Let alone all the CPU cycles and Postgres heap fetches / IOPS not spent.



This is a screenshot of site 2 ir_ui_view_cache_test module output graph grouped daily. Last 6 days (by starting view caching) view reading has only took 13.0 - 22.9 seconds per day! This is about 0.7% or less of original time it took for reading view data.


To start caching you'r Odoo views - grab a module from odoo apps store right now!

If you want to test the benefits before buying a module - a testing module can be found here.

And yes - the fastest way to execute code is not to execute it at all!


View caching
Alvar Vilu
10 November, 2020
Share this post
Archive
Sign in to leave a comment
The magic of using bin_size in contexts.