From 000afa179f63955b34c548ecd08df2eded2f4138 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Thu, 13 Sep 2018 17:27:25 -0700 Subject: [PATCH] add batch size 64k --- p2p/helper.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/p2p/helper.go b/p2p/helper.go index 493f4831d..3e52aa37d 100644 --- a/p2p/helper.go +++ b/p2p/helper.go @@ -24,6 +24,8 @@ content (n bytes) - actual message content */ +const BATCH_SIZE = 1 << 16 + // Read the message type and content size, and return the actual content. func ReadMessageContent(conn net.Conn) ([]byte, error) { var ( @@ -65,12 +67,12 @@ func ReadMessageContent(conn net.Conn) ([]byte, error) { //log.Printf("The content size is %d bytes.", bytesToRead) //// Read the content in chunk of 1024 bytes - tmpBuf := make([]byte, 1024) + tmpBuf := make([]byte, BATCH_SIZE) ILOOP: for { timeoutDuration := 1 * time.Second conn.SetReadDeadline(time.Now().Add(timeoutDuration)) - if bytesToRead < 1024 { + if bytesToRead < BATCH_SIZE { // Read the last number of bytes less than 1024 tmpBuf = make([]byte, bytesToRead) }