XL: Make allocations simpler avoid redundant allocs. (#1961)

- Reduce 10MiB buffers for loopy calls to use 128KiB.
- start using 128KiB buffer where needed.
This commit is contained in:
Harshavardhana
2016-06-24 02:06:23 -07:00
committed by GitHub
parent ff9fc22c72
commit e8990e42c2
11 changed files with 374 additions and 179 deletions

View File

@@ -17,6 +17,7 @@
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
@@ -346,9 +347,10 @@ func reorderDisks(bootstrapDisks []StorageAPI, formatConfigs []*formatConfigV1)
// loadFormat - loads format.json from disk.
func loadFormat(disk StorageAPI) (format *formatConfigV1, err error) {
var buffer []byte
buffer, err = readAll(disk, minioMetaBucket, formatConfigFile)
if err != nil {
// Allocate staging buffer of 32KiB for copyBuffer.
buf := make([]byte, 32*1024)
var buffer = new(bytes.Buffer)
if err = copyBuffer(buffer, disk, minioMetaBucket, formatConfigFile, buf); err != nil {
// 'file not found' and 'volume not found' as
// same. 'volume not found' usually means its a fresh disk.
if err == errFileNotFound || err == errVolumeNotFound {
@@ -366,11 +368,15 @@ func loadFormat(disk StorageAPI) (format *formatConfigV1, err error) {
}
return nil, err
}
// Try to decode format json into formatConfigV1 struct.
format = &formatConfigV1{}
err = json.Unmarshal(buffer, format)
if err != nil {
d := json.NewDecoder(buffer)
if err = d.Decode(format); err != nil {
return nil, err
}
// Success.
return format, nil
}