One of the main issue with ormcache is that the invalidation clears everything, meaning that some value, slow to compute but with a long lifetime, can be removed from the cache because an easy to invalidate value is cleared, like after writting or creating a product has an example. Most example in the code will try to invalidate the cache of the models doing something like `env['ir.qweb'].clear_caches()` but it is finally equivalent to `env.registry.clear_cache()`, and cross worker. The idea is to have multiple cache, maybe with specific sizes for a specific purpose. Having one per model is maybe a bad idea because it will be difficult to size the LRU correcly, and it is too dynamic. Checking invalidation may be expensive. The proposed solution is closed allow a limited number of named caches, using onse sequence per cache. This is actually close to the cache_longterm. We want to discourage using a specific cache for one use case in the buisness code. Adding a cache shouldn't be something easy, doable in stable. Note that we could also change the invalisation mecanism using an insert only table. We an check the sequence of this table, but also fetch all invalidation messages. Another possible improvement, especially if we have more than x cache is to have a global sequence, checking signaling would mean to check the main sequence, and only the other ones if the main one changed. Note that this poc is inspired from the long term cache but not all use case where applie yet. Part-of: odoo/odoo#119813
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import logging
|
|
import re
|
|
import time
|
|
|
|
from odoo.tests import tagged
|
|
from odoo.tests.common import TransactionCase
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
@tagged('-at_install', 'post_install')
|
|
class TestIrHttpPerformances(TransactionCase):
|
|
|
|
def test_routing_map_performance(self):
|
|
self.env.registry.clear_cache('routing')
|
|
# if the routing map was already generated it is possible that some compiled regex are in cache.
|
|
# we want to mesure the cold state, when the worker just spawned, we need to empty the re cache
|
|
re._cache.clear()
|
|
|
|
self.env.registry.clear_cache('routing')
|
|
start = time.time()
|
|
self.env['ir.http'].routing_map()
|
|
duration = time.time() - start
|
|
_logger.info('Routing map web generated in %.3fs', duration)
|
|
|
|
# generate the routing map of another website, to check if we can benefit from anything computed by the previous routing map
|
|
start = time.time()
|
|
self.env['ir.http'].routing_map(key=1)
|
|
duration = time.time() - start
|
|
_logger.info('Routing map website1 generated in %.3fs', duration)
|