Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Do not allocate memory manually while creating RPC buffer
Browse files Browse the repository at this point in the history
Sunrpc Read buffer was created by allocating `1MiB` each time when
client connects. Go can automatically expand the buffer when required
so now empty buffer is initialized.(`1MiB` per brick connect is `1GB`
for 1000 bricks)

Signed-off-by: Aravinda VK <avishwan@redhat.com>
  • Loading branch information
aravindavk authored and Madhu-1 committed Dec 19, 2018
1 parent 500e591 commit 0827c74
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/sunrpc/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func ReadFullRecord(conn io.Reader) ([]byte, error) {
// In almost all cases, RPC message contain only one fragment which
// is not too big in size. But set a cap on buffer size to prevent
// rogue clients from filling up memory.
record := bytes.NewBuffer(make([]byte, 0, maxRecordSize))
record := bytes.NewBuffer([]byte{})
var fragmentHeader uint32
for {
// Read record fragment header
Expand All @@ -112,7 +112,7 @@ func ReadFullRecord(conn io.Reader) ([]byte, error) {
return nil, ErrInvalidFragmentSize
}

if int(fragmentSize) > (record.Cap() - record.Len()) {
if int(fragmentSize) > (maxRecordSize - record.Len()) {
return nil, ErrRPCMessageSizeExceeded
}

Expand Down

0 comments on commit 0827c74

Please sign in to comment.