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 ( import (
"bufio" "bufio"
"bytes"
"compress/flate" "compress/flate"
"encoding/json" "encoding/json"
"log" "log"
@ -55,8 +54,8 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
Statistics: node.Statistics, Statistics: node.Statistics,
Neighbours: node.Neighbours, Neighbours: node.Neighbours,
} }
var b bytes.Buffer
writer := bufio.NewWriter(&b) writer := bufio.NewWriterSize(conn.conn, 8192)
flater, err := flate.NewWriter(writer, flate.BestCompression) flater, err := flate.NewWriter(writer, flate.BestCompression)
if err != nil { if err != nil {
@ -70,13 +69,17 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
if node.Nodeinfo != nil && node.Nodeinfo.NodeID != "" { if node.Nodeinfo != nil && node.Nodeinfo.NodeID != "" {
nodeid = 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 return
} }
flater.Flush() err = flater.Flush()
writer.Flush() if err != nil {
conn.conn.Write(b.Bytes()) 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) { func (conn *Connection) InsertLink(link *runtime.Link, time time.Time) {