Remove jinja2_cache (#11996)
- Why I did it As part of Persistent log level HLD , LOGLEVEL_DB content is moved to CONFIG_DB. In addition, it was decided to remove jinja2_cache which currently appear on LOGLEVEL_DB This cache was added to speed up template rendering in start scripts. There were a lot of them rendered during system start. This caused a delay in warm boot LAG restore time. It was tested and verified that with and without the cache we don't see any difference in this timing now. It is probably due to a lot of other optimizations done to sonic-cfggen. Since there is no noticeable improvement made by j2 cache now it is safe to remove it. - How I did it Remove redis_bcc.py file and and remove the bytcode_cache from sonic-sfggen - How to verify it Warm boot was tested with \ without this jinja2_cache and it there is no difference in performance
This commit is contained in:
parent
e662008f72
commit
f30fc76278
@ -1,29 +0,0 @@
|
||||
import jinja2
|
||||
|
||||
from base64 import b64encode, b64decode
|
||||
|
||||
class RedisBytecodeCache(jinja2.BytecodeCache):
|
||||
""" A bytecode cache for jinja2 template that stores bytecode in Redis """
|
||||
|
||||
REDIS_HASH = 'JINJA2_CACHE'
|
||||
|
||||
def __init__(self, client):
|
||||
self._client = client
|
||||
try:
|
||||
self._client.connect(self._client.LOGLEVEL_DB, retry_on=False)
|
||||
except Exception:
|
||||
self._client = None
|
||||
|
||||
def load_bytecode(self, bucket):
|
||||
if self._client is None:
|
||||
return
|
||||
code = self._client.get(self._client.LOGLEVEL_DB, self.REDIS_HASH, bucket.key)
|
||||
if code is not None:
|
||||
bucket.bytecode_from_string(b64decode(code.encode()))
|
||||
|
||||
def dump_bytecode(self, bucket):
|
||||
if self._client is None:
|
||||
return
|
||||
self._client.set(self._client.LOGLEVEL_DB, self.REDIS_HASH,
|
||||
bucket.key, b64encode(bucket.bytecode_to_string()).decode())
|
||||
|
@ -43,7 +43,6 @@ py_modules = [
|
||||
'minigraph',
|
||||
'openconfig_acl',
|
||||
'portconfig',
|
||||
'redis_bcc',
|
||||
]
|
||||
if sys.version_info.major == 3:
|
||||
# Python 3-only modules
|
||||
|
@ -31,10 +31,9 @@ from config_samples import generate_sample_config, get_available_config
|
||||
from functools import partial
|
||||
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type
|
||||
from portconfig import get_port_config, get_breakout_mode
|
||||
from redis_bcc import RedisBytecodeCache
|
||||
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id, is_multi_asic
|
||||
from sonic_py_common import device_info
|
||||
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
|
||||
from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
|
||||
|
||||
|
||||
PY3x = sys.version_info >= (3, 0)
|
||||
@ -241,8 +240,7 @@ def _get_jinja2_env(paths):
|
||||
Retreive Jinj2 env used to render configuration templates
|
||||
"""
|
||||
loader = jinja2.FileSystemLoader(paths)
|
||||
redis_bcc = RedisBytecodeCache(SonicV2Connector(host='127.0.0.1'))
|
||||
env = jinja2.Environment(loader=loader, trim_blocks=True, bytecode_cache=redis_bcc)
|
||||
env = jinja2.Environment(loader=loader, trim_blocks=True)
|
||||
env.filters['sort_by_port_index'] = sort_by_port_index
|
||||
env.filters['ipv4'] = is_ipv4
|
||||
env.filters['ipv6'] = is_ipv6
|
||||
|
Loading…
Reference in New Issue
Block a user