Skip to content

Commit 1e2f01d

Browse files
committed
use copyBuffer
1 parent cf1c17f commit 1e2f01d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

code/go/0chain.net/blobbercore/filestore/storage.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const (
5656
PreCommitDir = "precommit"
5757
MerkleChunkSize = 64
5858
ChunkSize = 64 * KB
59+
BufferSize = 10 * MB
5960
)
6061

6162
func (fs *FileStore) WriteFile(allocID, conID string, fileData *FileInputData, infile multipart.File) (*FileOutputData, error) {
@@ -245,7 +246,8 @@ func (fs *FileStore) CommitWrite(allocID, conID string, fileData *FileInputData)
245246
fileSize := rStat.Size()
246247
start := time.Now()
247248
hasher := GetNewCommitHasher(fileSize)
248-
_, err = io.Copy(hasher, r)
249+
buffer := make([]byte, BufferSize)
250+
_, err = io.CopyBuffer(hasher, r, buffer)
249251
if err != nil {
250252
return false, common.NewError("read_write_error", err.Error())
251253
}

code/go/0chain.net/blobbercore/handler/file_command_upload.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ func (cmd *UploadFileCommand) IsValidated(ctx context.Context, req *http.Request
5454
fileChanger := &allocation.UploadFileChanger{}
5555

5656
uploadMetaString := req.FormValue(UploadMeta)
57+
elapsedReadForm := time.Since(start)
5758
err := json.Unmarshal([]byte(uploadMetaString), fileChanger)
5859
if err != nil {
5960
return common.NewError("invalid_parameters",
6061
"Invalid parameters. Error parsing the meta data for upload."+err.Error())
6162
}
62-
elapsedUnmarshal := time.Since(start)
63+
elapsedUnmarshal := time.Since(start) - elapsedReadForm
6364

6465
if fileChanger.Path == "/" {
6566
return common.NewError("invalid_path", "Invalid path. Cannot upload to root directory")
@@ -99,7 +100,7 @@ func (cmd *UploadFileCommand) IsValidated(ctx context.Context, req *http.Request
99100
}
100101

101102
cmd.fileChanger = fileChanger
102-
logging.Logger.Info("isValidated", zap.Duration("elapsedUnmarshal", elapsedUnmarshal), zap.Duration("elapsedRefExist", elapsedRefExist), zap.Duration("elapsed", time.Since(start)))
103+
logging.Logger.Info("isValidated", zap.Duration("elapsedReamForm", elapsedReadForm), zap.Duration("elapsedUnmarshal", elapsedUnmarshal), zap.Duration("elapsedRefExist", elapsedRefExist), zap.Duration("elapsed", time.Since(start)))
103104
return nil
104105
}
105106

0 commit comments

Comments
 (0)