less writers

This commit is contained in:
Martin Geno 2018-01-19 16:12:27 +01:00 committed by Martin/Geno
parent 23600524a5
commit 22797a36d1
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
1 changed files with 11 additions and 8 deletions

View File

@ -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) {