mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 11:05:45 +00:00
logtail: remove LowMemory mode
Fixes tailscale/tailscale#13685 logtail currently has a LowMemory flag, which is enabled upon initialization on memory-constrained platforms like iOS. This flag reduces the ring buffer size from 256 log lines to 64. It was introduced over four years ago, back when Tailscale supported iOS 14 and earlier, where network extensions were limited to 15 MB of RAM. Since the memory limit has now increased to 50 MB on all supported iOS versions (with our minimum requirement being iOS 15.0), the need to conserve a few kilobytes of RAM by reducing buffer entries and the size of each flush is minimal. The additional code paths are more things we need to maintain over time... with little benefit. This PR removes that. To be merged after we cut the first 1.77 unstable, as this might be a risky change. Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
This commit is contained in:
parent
8fdffb8da0
commit
810c84b659
@ -45,9 +45,6 @@
|
||||
// Note that JSON log messages can be as large as maxSize.
|
||||
const maxTextSize = 16 << 10
|
||||
|
||||
// lowMemRatio reduces maxSize and maxTextSize by this ratio in lowMem mode.
|
||||
const lowMemRatio = 4
|
||||
|
||||
// bufferSize is the typical buffer size to retain.
|
||||
// It is large enough to handle most log messages,
|
||||
// but not too large to be a notable waste of memory if retained forever.
|
||||
@ -72,7 +69,6 @@ type Config struct {
|
||||
BaseURL string // if empty defaults to "https://log.tailscale.io"
|
||||
HTTPC *http.Client // if empty defaults to http.DefaultClient
|
||||
SkipClientTime bool // if true, client_time is not written to logs
|
||||
LowMemory bool // if true, logtail minimizes memory use
|
||||
Clock tstime.Clock // if set, Clock.Now substitutes uses of time.Now
|
||||
Stderr io.Writer // if set, logs are sent here instead of os.Stderr
|
||||
StderrLevel int // max verbosity level to write to stderr; 0 means the non-verbose messages only
|
||||
@ -118,11 +114,7 @@ func NewLogger(cfg Config, logf tslogger.Logf) *Logger {
|
||||
cfg.Stderr = os.Stderr
|
||||
}
|
||||
if cfg.Buffer == nil {
|
||||
pendingSize := 256
|
||||
if cfg.LowMemory {
|
||||
pendingSize = 64
|
||||
}
|
||||
cfg.Buffer = NewMemoryBuffer(pendingSize)
|
||||
cfg.Buffer = NewMemoryBuffer(256)
|
||||
}
|
||||
var procID uint32
|
||||
if cfg.IncludeProcID {
|
||||
@ -155,7 +147,6 @@ func NewLogger(cfg Config, logf tslogger.Logf) *Logger {
|
||||
stderrLevel: int64(cfg.StderrLevel),
|
||||
httpc: cfg.HTTPC,
|
||||
url: cfg.BaseURL + "/c/" + cfg.Collection + "/" + cfg.PrivateID.String() + urlSuffix,
|
||||
lowMem: cfg.LowMemory,
|
||||
buffer: cfg.Buffer,
|
||||
skipClientTime: cfg.SkipClientTime,
|
||||
drainWake: make(chan struct{}, 1),
|
||||
@ -188,7 +179,6 @@ type Logger struct {
|
||||
stderrLevel int64 // accessed atomically
|
||||
httpc *http.Client
|
||||
url string
|
||||
lowMem bool
|
||||
skipClientTime bool
|
||||
netMonitor *netmon.Monitor
|
||||
buffer Buffer
|
||||
@ -325,13 +315,6 @@ func (l *Logger) drainPending() (b []byte) {
|
||||
}()
|
||||
|
||||
maxLen := maxSize
|
||||
if l.lowMem {
|
||||
// When operating in a low memory environment, it is better to upload
|
||||
// in multiple operations than it is to allocate a large body and OOM.
|
||||
// Even if maxLen is less than maxSize, we can still upload an entry
|
||||
// that is up to maxSize if we happen to encounter one.
|
||||
maxLen /= lowMemRatio
|
||||
}
|
||||
for len(b) < maxLen {
|
||||
line, err := l.buffer.TryReadLine()
|
||||
switch {
|
||||
@ -683,9 +666,6 @@ func (l *Logger) appendText(dst, src []byte, skipClientTime bool, procID uint32,
|
||||
// Append the text string, which may be truncated.
|
||||
// Invalid UTF-8 will be mangled with the Unicode replacement character.
|
||||
max := maxTextSize
|
||||
if l.lowMem {
|
||||
max /= lowMemRatio
|
||||
}
|
||||
dst = append(dst, `"text":`...)
|
||||
dst = appendTruncatedString(dst, src, max)
|
||||
return append(dst, "}\n"...)
|
||||
|
Loading…
Reference in New Issue
Block a user