Le cache des paths est dans l'OptionDescription

Utilisation des slots pour la Config

Il faut 566Mo de mémoire pour charger 50 variantes de 100 serveurs chacuns (5000 serveurs en tout).

ref #5111
This commit is contained in:
Emmanuel Garette 2013-03-27 16:16:15 +01:00
parent 899f864f8d
commit d00153787d
3 changed files with 23 additions and 21 deletions

View File

@ -33,11 +33,10 @@ from tiramisu.value import Values
# ____________________________________________________________
class Config(object):
"main configuration management entry"
# __slots__ = ('__dict__', '_cfgimpl_toplevel', '_cfgimpl_descr', '_cfgimpl_subconfigs',
# '_cfgimpl_parent', '_cfgimpl_all_paths', '_cfgimpl_warnings',
# '_cfgimpl_toplevel', '_cfgimpl_slots', '_cfgimpl_build_all_paths')
_cfgimpl_toplevel = None
__slots__ = ('_cfgimpl_descr', '_cfgimpl_subconfigs',
'_cfgimpl_parent', '_cfgimpl_warnings', '_cfgimpl_permissive',
'_cfgimpl_context', '_cfgimpl_settings', '_cfgimpl_values',
'_cfgimpl_slots', '_cfgimpl_build_all_paths')
def __init__(self, descr, parent=None, context=None, valid_opt_names=True):
""" Configuration option management master class
@ -62,14 +61,13 @@ class Config(object):
self._cfgimpl_settings = Setting()
self._cfgimpl_settings.valid_opt_names = valid_opt_names
self._cfgimpl_values = Values(self._cfgimpl_context)
self._cfgimpl_all_paths = {}
#self._cfgimpl_all_paths = {}
else:
if context is None:
raise ConfigError("cannot find a value for this config")
valid_opt_names = context._cfgimpl_settings.valid_opt_names
"warnings are a great idea, let's make up a better use of it"
self._cfgimpl_warnings = []
self._cfgimpl_toplevel = self._cfgimpl_get_toplevel()
if valid_opt_names:
# some api members shall not be used as option's names !
#methods = getmembers(self, ismethod)
@ -82,9 +80,9 @@ class Config(object):
self._cfgimpl_build_all_paths()
def _cfgimpl_build_all_paths(self):
if self._cfgimpl_all_paths == None:
raise ConfigError('cache paths must not be None')
self._cfgimpl_descr.build_cache(self._cfgimpl_all_paths)
# if self._cfgimpl_all_paths == None:
# raise ConfigError('cache paths must not be None')
self._cfgimpl_descr.build_cache() #self._cfgimpl_all_paths)
def cfgimpl_get_settings(self):
return self._cfgimpl_context._cfgimpl_settings
@ -156,7 +154,8 @@ class Config(object):
def __setattr__(self, name, value):
"attribute notation mechanism for the setting of the value of an option"
if name.startswith('_cfgimpl_'):
self.__dict__[name] = value
#self.__dict__[name] = value
object.__setattr__(self, name, value)
return
if '.' in name:
homeconfig, name = self.cfgimpl_get_home_by_path(name)

View File

@ -424,6 +424,7 @@ class OptionDescription(BaseType, BaseInformation):
self._build()
self.properties = [] # 'hidden', 'disabled'...
self.informations = {}
self._cache_paths = {}
def getdoc(self):
return self.doc
@ -474,7 +475,9 @@ class OptionDescription(BaseType, BaseInformation):
paths.append('.'.join(currpath + [attr]))
return paths
def build_cache(self, paths, currpath=None):
def build_cache(self, currpath=None):
if currpath is None and self._cache_paths != {}:
return
if currpath is None:
currpath = []
for option in self._children:
@ -483,10 +486,10 @@ class OptionDescription(BaseType, BaseInformation):
continue
if isinstance(option, OptionDescription):
currpath.append(attr)
option.build_cache(paths, currpath=currpath)
option.build_cache(currpath=currpath)
currpath.pop()
else:
paths[option] = str('.'.join(currpath + [attr]))
self._cache_paths[option] = str('.'.join(currpath + [attr]))
# ____________________________________________________________
def set_group_type(self, group_type):