Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

5

How are the caches cleaned in multi-process mode (i.e. under Gunicorn)?

By
Nicolas Bessi
on 2/5/13, 10:23 AM 8,714 views

When developing I use @tools.ormcache() or @tool.ormcache_multi(multi=x) to gain performance. From time to time I need to clean caches. For this I use my_model.clear_caches().

When we are in Gunicorn mode does clean_caches notify all worker to automatically clean their own cache, or do I have to do some other calls? Is there some latency?

This is not really clear or maybe I missed some documentation.

7
Vo Minh Thu
On 2/5/13, 5:15 PM

Each registry (i.e. the self.pool variable on any model instance) is kept in sync across workers through the database. Two sequences in database are used, one for the caches and one for the registry itself (e.g. to keep track of the fact a module has been installed), and each worker checks those sequences.

Whenever the sequences have a different value than what the worker was assuming, the workers will either clean their caches or reload the registry (thus loading any newly installed module, as it would have been flagged as "installed" in ir.module.module).

The check on the sequences is done right when a new RPC call is done. Sequences are updated at the end of an RPC call. So there is some latency between a cache invalidation on a worker and the corresponding invalidation on another worker. But this is in fact ok: when the signaling occurs, it is itself part of the database transaction associated to the RPC call. Since the check is done right at the beginning of a new RPC call, that call/transaction will see correctly cleaned caches and updated registry.

See Guewen Baconnier's answer for the few places where the logic is implemented.

To have all that signaling occur, the openerp.multi_process symbol must be set to True. This should be set in the configuration file used with Gunicorn or other WSGI servers.

In trunk, the oe web command sets also openerp.multi_process to True so that multiple oe web processes can be run side by side.

4

Guewen Baconnier - Software Developer, Camptocamp

--Guewen Baconnier - Software Developer, Camptocamp--
2658
| 6 7 8
Lausanne, Switzerland
--Guewen Baconnier - Software Developer, Camptocamp--

Guewen works at Camptocamp as an Odoo developer since 2010. He is the lead developer of the Odoo Connector framework and the Magento Connector. He is a delegate member of the OCA, a committer and an active contributor to the OCA projects.

 

Guewen Baconnier - Software Developer, Camptocamp
On 2/5/13, 11:43 AM

From what I can read, when clear_caches is called, it sets _any_cache_cleared to true on the pool registry.

This attribute is used to know if a model cache has been cleared so it can be signaled to the other processes (see openerp.modules.registry, methods check_registry_signaling and signal_caches_change).

The check of signaling is done before each RPC request on models (openerp.service.web_services.objects_proxy) or print of a report (openerp.service.web_services.report_spool) and the signaling is done after the request or the print of the report. ir.cron calls the check and signaling itself (openerp.addons.base.ir_cron) too.

The signaling use a sequence in the database: base_cache_signaling. Each time the sequence is increased, it means that the caches have to be cleared.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/5/13, 10:23 AM
Seen: 8714 times
Last updated: 3/16/15, 8:10 AM