2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-08-29 06:18:15 +00:00

Change the stdout/stderr/trace logs to not buffer things over time

If something went completely off the rails, it could easily fill up lots of memory with log entries in the 2 seconds it
would buffer.  For now disable the buffering on key debug logs, as the main purpose was reducing IOPs in the per-node
console logs anyway.  A future behavior may be to also limit the size and/or number of outstanding log entries before
committing to disk.
This commit is contained in:
Jarrod Johnson
2017-04-11 14:39:29 -04:00
parent 236d889d5d
commit 563a2b11c3
2 changed files with 10 additions and 6 deletions

View File

@@ -505,11 +505,12 @@ class Logger(object):
else:
return object.__new__(cls)
def __init__(self, logname, console=False, tenant=None):
def __init__(self, logname, console=False, tenant=None, buffered=True):
if hasattr(self, 'initialized'):
# we are just a copy of the same object
return
self.initialized = True
self.buffered = buffered
self.filepath = confluent.config.configmanager.get_global("logdirectory")
if self.filepath is None:
if os.name == 'nt':
@@ -727,8 +728,11 @@ class Logger(object):
else:
self.logentries.append(
[ltype, timestamp, logdata, event, eventdata])
if self.writer is None:
self.writer = eventlet.spawn_after(2, self.writedata)
if self.buffered:
if self.writer is None:
self.writer = eventlet.spawn_after(2, self.writedata)
else:
self.writedata()
def closelog(self):
self.handler.close()
@@ -746,6 +750,6 @@ def log(logdata=None, ltype=None, event=0, eventdata=None):
def logtrace():
global tracelog
if tracelog is None:
tracelog = Logger('trace')
tracelog = Logger('trace', buffered=False)
tracelog.log(traceback.format_exc(), ltype=DataTypes.event,
event=Events.stacktrace)

View File

@@ -77,8 +77,8 @@ def _daemonize():
os.open(os.devnull, os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
sys.stdout = log.Logger('stdout')
sys.stderr = log.Logger('stderr')
sys.stdout = log.Logger('stdout', buffered=False)
sys.stderr = log.Logger('stderr', buffered=False)
def _updatepidfile():