Skip heavy operations if there is no jsonlog writers

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-03-30 14:30:01 -07:00 committed by unclejack
parent dd54d0419c
commit 61ad4654f5

View file

@ -34,8 +34,6 @@ func (w *BroadcastWriter) AddWriter(writer io.WriteCloser, stream string) {
// Write writes bytes to all writers. Failed writers will be evicted during // Write writes bytes to all writers. Failed writers will be evicted during
// this call. // this call.
func (w *BroadcastWriter) Write(p []byte) (n int, err error) { func (w *BroadcastWriter) Write(p []byte) (n int, err error) {
var timestamp string
created := time.Now().UTC()
w.Lock() w.Lock()
if writers, ok := w.streams[""]; ok { if writers, ok := w.streams[""]; ok {
for sw := range writers { for sw := range writers {
@ -44,11 +42,19 @@ func (w *BroadcastWriter) Write(p []byte) (n int, err error) {
delete(writers, sw) delete(writers, sw)
} }
} }
// exit if there is no more writers
if len(w.streams) == 1 {
w.buf.Reset()
w.Unlock()
return len(p), nil
}
} }
if w.jsLogBuf == nil { if w.jsLogBuf == nil {
w.jsLogBuf = new(bytes.Buffer) w.jsLogBuf = new(bytes.Buffer)
w.jsLogBuf.Grow(1024) w.jsLogBuf.Grow(1024)
} }
var timestamp string
created := time.Now().UTC()
w.buf.Write(p) w.buf.Write(p)
for { for {
if n := w.buf.Len(); n == 0 { if n := w.buf.Len(); n == 0 {