From 22797a36d1a099d001dc673de4d4bbe719747b5e Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Fri, 19 Jan 2018 16:12:27 +0100 Subject: [PATCH] less writers --- database/yanic/main.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/database/yanic/main.go b/database/yanic/main.go index fbbb8f7..5451b1c 100644 --- a/database/yanic/main.go +++ b/database/yanic/main.go @@ -5,7 +5,6 @@ package yanic */ import ( "bufio" - "bytes" "compress/flate" "encoding/json" "log" @@ -55,8 +54,8 @@ func (conn *Connection) InsertNode(node *runtime.Node) { Statistics: node.Statistics, Neighbours: node.Neighbours, } - var b bytes.Buffer - writer := bufio.NewWriter(&b) + + writer := bufio.NewWriterSize(conn.conn, 8192) flater, err := flate.NewWriter(writer, flate.BestCompression) if err != nil { @@ -70,13 +69,17 @@ func (conn *Connection) InsertNode(node *runtime.Node) { if node.Nodeinfo != nil && node.Nodeinfo.NodeID != "" { nodeid = node.Nodeinfo.NodeID } - log.Printf("[database-yanic] could not send %s node: %s", nodeid, err) + log.Printf("[database-yanic] could not encode %s node: %s", nodeid, err) return } - flater.Flush() - writer.Flush() - conn.conn.Write(b.Bytes()) - + err = flater.Flush() + if err != nil { + log.Printf("[database-yanic] could not compress: %s", err) + } + err = writer.Flush() + if err != nil { + log.Printf("[database-yanic] could not send: %s", err) + } } func (conn *Connection) InsertLink(link *runtime.Link, time time.Time) {