You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New connections each create a unique logger. These loggers end up in logging.Logger.manager.loggerDict which is not cleaned up, causing memory
usage to increase with each new connection created. We have a number of long-
lived processes which create many connections and this issue is causing steady
growth in memory usage.
I do not believe this is the intended use of the python logging libraries. As I
understand it, the Connection class should always use the same Logger instance
and add/remove a new handler if instance specific behavior is desired.
Connection Logger Creation
logger_name='vertica_{0}_{1}'.format(id(self), str(uuid.uuid4())) # must be a unique valueself._logger=logging.getLogger(logger_name)
@Benjamin-liv We mitigated the issue by wrapping connections in a context manager that performs necessary cleanup.
importvertica_python@contextlib.contextmanagerdefvertica_connect(**options):
"""Create a new Vertica Connection with the provided options. This is a context manager wrapping vertica_python.connect. This should be used in all places where one would normally use the library function. This can be removed when https://github.com/vertica/vertica-python/issues/476 is addressed. Args: **options: Options to pass to vertica_python.connect. Returns: vertica_python.vertica.connection.Connection: New connection instance. """cnn=vertica_python.connect(**options)
logger_name=cnn._logger.nametry:
withcnn:
yieldcnnfinally:
# XXX vertica_python connections each create a unique logger that# is not cleaned up appropriately. Remove it here to prevent memory leaking.dellogging.Logger.manager.loggerDict[logger_name]
Issue Description
New connections each create a unique logger. These loggers end up in
logging.Logger.manager.loggerDict
which is not cleaned up, causing memoryusage to increase with each new connection created. We have a number of long-
lived processes which create many connections and this issue is causing steady
growth in memory usage.
I do not believe this is the intended use of the python logging libraries. As I
understand it, the Connection class should always use the same Logger instance
and add/remove a new handler if instance specific behavior is desired.
Connection Logger Creation
Uncollected Logger Instances
Uncollected Allocations After 50 Connections (tracemalloc)
The text was updated successfully, but these errors were encountered: