1
0
mirror of https://github.com/gluster/glusterd2.git synced 2026-02-05 12:45:38 +01:00

Do not allocate memory manually while creating RPC buffer

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>
This commit is contained in:
Aravinda VK
2018-12-18 18:09:49 +05:30
committed by Madhu Rajanna
parent 500e5912a1
commit 0827c74916

View File

@@ -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
@@ -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
}