storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/storage-datatypes_test.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package cmd
    18  
    19  import (
    20  	"bytes"
    21  	"encoding/gob"
    22  	"io/ioutil"
    23  	"testing"
    24  	"time"
    25  
    26  	"github.com/tinylib/msgp/msgp"
    27  )
    28  
    29  func BenchmarkDecodeVolInfoMsgp(b *testing.B) {
    30  	v := VolInfo{
    31  		Name:    "uuid",
    32  		Created: time.Now(),
    33  	}
    34  	var buf bytes.Buffer
    35  	msgp.Encode(&buf, &v)
    36  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
    37  	dc := msgp.NewReader(rd)
    38  	b.Log("Size:", buf.Len(), "bytes")
    39  	b.SetBytes(1)
    40  	b.ReportAllocs()
    41  	b.ResetTimer()
    42  	for i := 0; i < b.N; i++ {
    43  		err := v.DecodeMsg(dc)
    44  		if err != nil {
    45  			b.Fatal(err)
    46  		}
    47  	}
    48  }
    49  
    50  func BenchmarkDecodeDiskInfoMsgp(b *testing.B) {
    51  	v := DiskInfo{
    52  		Total:     1000,
    53  		Free:      1000,
    54  		Used:      1000,
    55  		FSType:    "xfs",
    56  		RootDisk:  true,
    57  		Healing:   true,
    58  		Endpoint:  "http://localhost:9001/tmp/disk1",
    59  		MountPath: "/tmp/disk1",
    60  		ID:        "uuid",
    61  		Error:     "",
    62  	}
    63  	var buf bytes.Buffer
    64  	msgp.Encode(&buf, &v)
    65  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
    66  	dc := msgp.NewReader(rd)
    67  	b.Log("Size:", buf.Len(), "bytes")
    68  	b.SetBytes(1)
    69  	b.ReportAllocs()
    70  	b.ResetTimer()
    71  	for i := 0; i < b.N; i++ {
    72  		err := v.DecodeMsg(dc)
    73  		if err != nil {
    74  			b.Fatal(err)
    75  		}
    76  	}
    77  }
    78  
    79  func BenchmarkDecodeDiskInfoGOB(b *testing.B) {
    80  	v := DiskInfo{
    81  		Total:     1000,
    82  		Free:      1000,
    83  		Used:      1000,
    84  		FSType:    "xfs",
    85  		RootDisk:  true,
    86  		Healing:   true,
    87  		Endpoint:  "http://localhost:9001/tmp/disk1",
    88  		MountPath: "/tmp/disk1",
    89  		ID:        "uuid",
    90  		Error:     "",
    91  	}
    92  
    93  	var buf bytes.Buffer
    94  	gob.NewEncoder(&buf).Encode(v)
    95  	encoded := buf.Bytes()
    96  	b.Log("Size:", buf.Len(), "bytes")
    97  	b.SetBytes(1)
    98  	b.ReportAllocs()
    99  	b.ResetTimer()
   100  	for i := 0; i < b.N; i++ {
   101  		dec := gob.NewDecoder(bytes.NewBuffer(encoded))
   102  		err := dec.Decode(&v)
   103  		if err != nil {
   104  			b.Fatal(err)
   105  		}
   106  	}
   107  }
   108  
   109  func BenchmarkEncodeDiskInfoMsgp(b *testing.B) {
   110  	v := DiskInfo{
   111  		Total:     1000,
   112  		Free:      1000,
   113  		Used:      1000,
   114  		FSType:    "xfs",
   115  		RootDisk:  true,
   116  		Healing:   true,
   117  		Endpoint:  "http://localhost:9001/tmp/disk1",
   118  		MountPath: "/tmp/disk1",
   119  		ID:        "uuid",
   120  		Error:     "",
   121  	}
   122  
   123  	b.SetBytes(1)
   124  	b.ReportAllocs()
   125  	b.ResetTimer()
   126  	for i := 0; i < b.N; i++ {
   127  		err := msgp.Encode(ioutil.Discard, &v)
   128  		if err != nil {
   129  			b.Fatal(err)
   130  		}
   131  	}
   132  }
   133  
   134  func BenchmarkEncodeDiskInfoGOB(b *testing.B) {
   135  	v := DiskInfo{
   136  		Total:     1000,
   137  		Free:      1000,
   138  		Used:      1000,
   139  		FSType:    "xfs",
   140  		RootDisk:  true,
   141  		Healing:   true,
   142  		Endpoint:  "http://localhost:9001/tmp/disk1",
   143  		MountPath: "/tmp/disk1",
   144  		ID:        "uuid",
   145  		Error:     "",
   146  	}
   147  
   148  	enc := gob.NewEncoder(ioutil.Discard)
   149  	b.SetBytes(1)
   150  	b.ReportAllocs()
   151  	b.ResetTimer()
   152  	for i := 0; i < b.N; i++ {
   153  		err := enc.Encode(&v)
   154  		if err != nil {
   155  			b.Fatal(err)
   156  		}
   157  	}
   158  }
   159  
   160  func BenchmarkDecodeFileInfoMsgp(b *testing.B) {
   161  	v := FileInfo{Volume: "testbucket", Name: "src/compress/zlib/reader_test.go", VersionID: "", IsLatest: true, Deleted: false, DataDir: "5e0153cc-621a-4267-8cb6-4919140d53b3", XLV1: false, ModTime: UTCNow(), Size: 3430, Mode: 0x0, Metadata: map[string]string{"X-Minio-Internal-Server-Side-Encryption-Iv": "jIJPsrkkVYYMvc7edBrNl+7zcM7+ZwXqMb/YAjBO/ck=", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Key-Id": "my-minio-key", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Sealed-Key": "IAAfAP2p7ZLv3UpLwBnsKkF2mtWba0qoY42tymK0szRgGvAxBNcXyHXYooe9dQpeeEJWgKUa/8R61oCy1mFwIg==", "X-Minio-Internal-Server-Side-Encryption-S3-Sealed-Key": "IAAfAPFYRDkHVirJBJxBixNj3PLWt78dFuUTyTLIdLG820J7XqLPBO4gpEEEWw/DoTsJIb+apnaem+rKtQ1h3Q==", "X-Minio-Internal-Server-Side-Encryption-Seal-Algorithm": "DAREv2-HMAC-SHA256", "content-type": "application/octet-stream", "etag": "20000f00e2c3709dc94905c6ce31e1cadbd1c064e14acdcd44cf0ac2db777eeedd88d639fcd64de16851ade8b21a9a1a"}, Parts: []ObjectPartInfo{{ETag: "", Number: 1, Size: 3430, ActualSize: 3398}}, Erasure: ErasureInfo{Algorithm: "reedsolomon", DataBlocks: 2, ParityBlocks: 2, BlockSize: 10485760, Index: 3, Distribution: []int{3, 4, 1, 2}, Checksums: []ChecksumInfo{{PartNumber: 1, Algorithm: 0x3, Hash: []uint8{}}}}}
   162  	var buf bytes.Buffer
   163  	msgp.Encode(&buf, &v)
   164  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
   165  	dc := msgp.NewReader(rd)
   166  	b.Log("Size:", buf.Len(), "bytes")
   167  	b.SetBytes(1)
   168  	b.ReportAllocs()
   169  	b.ResetTimer()
   170  	for i := 0; i < b.N; i++ {
   171  		err := v.DecodeMsg(dc)
   172  		if err != nil {
   173  			b.Fatal(err)
   174  		}
   175  	}
   176  }
   177  
   178  func BenchmarkDecodeFileInfoGOB(b *testing.B) {
   179  	v := FileInfo{Volume: "testbucket", Name: "src/compress/zlib/reader_test.go", VersionID: "", IsLatest: true, Deleted: false, DataDir: "5e0153cc-621a-4267-8cb6-4919140d53b3", XLV1: false, ModTime: UTCNow(), Size: 3430, Mode: 0x0, Metadata: map[string]string{"X-Minio-Internal-Server-Side-Encryption-Iv": "jIJPsrkkVYYMvc7edBrNl+7zcM7+ZwXqMb/YAjBO/ck=", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Key-Id": "my-minio-key", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Sealed-Key": "IAAfAP2p7ZLv3UpLwBnsKkF2mtWba0qoY42tymK0szRgGvAxBNcXyHXYooe9dQpeeEJWgKUa/8R61oCy1mFwIg==", "X-Minio-Internal-Server-Side-Encryption-S3-Sealed-Key": "IAAfAPFYRDkHVirJBJxBixNj3PLWt78dFuUTyTLIdLG820J7XqLPBO4gpEEEWw/DoTsJIb+apnaem+rKtQ1h3Q==", "X-Minio-Internal-Server-Side-Encryption-Seal-Algorithm": "DAREv2-HMAC-SHA256", "content-type": "application/octet-stream", "etag": "20000f00e2c3709dc94905c6ce31e1cadbd1c064e14acdcd44cf0ac2db777eeedd88d639fcd64de16851ade8b21a9a1a"}, Parts: []ObjectPartInfo{{ETag: "", Number: 1, Size: 3430, ActualSize: 3398}}, Erasure: ErasureInfo{Algorithm: "reedsolomon", DataBlocks: 2, ParityBlocks: 2, BlockSize: 10485760, Index: 3, Distribution: []int{3, 4, 1, 2}, Checksums: []ChecksumInfo{{PartNumber: 1, Algorithm: 0x3, Hash: []uint8{}}}}}
   180  	var buf bytes.Buffer
   181  	gob.NewEncoder(&buf).Encode(v)
   182  	encoded := buf.Bytes()
   183  	b.Log("Size:", buf.Len(), "bytes")
   184  	b.SetBytes(1)
   185  	b.ReportAllocs()
   186  	b.ResetTimer()
   187  	for i := 0; i < b.N; i++ {
   188  		dec := gob.NewDecoder(bytes.NewBuffer(encoded))
   189  		err := dec.Decode(&v)
   190  		if err != nil {
   191  			b.Fatal(err)
   192  		}
   193  	}
   194  }
   195  
   196  func BenchmarkEncodeFileInfoMsgp(b *testing.B) {
   197  	v := FileInfo{Volume: "testbucket", Name: "src/compress/zlib/reader_test.go", VersionID: "", IsLatest: true, Deleted: false, DataDir: "5e0153cc-621a-4267-8cb6-4919140d53b3", XLV1: false, ModTime: UTCNow(), Size: 3430, Mode: 0x0, Metadata: map[string]string{"X-Minio-Internal-Server-Side-Encryption-Iv": "jIJPsrkkVYYMvc7edBrNl+7zcM7+ZwXqMb/YAjBO/ck=", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Key-Id": "my-minio-key", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Sealed-Key": "IAAfAP2p7ZLv3UpLwBnsKkF2mtWba0qoY42tymK0szRgGvAxBNcXyHXYooe9dQpeeEJWgKUa/8R61oCy1mFwIg==", "X-Minio-Internal-Server-Side-Encryption-S3-Sealed-Key": "IAAfAPFYRDkHVirJBJxBixNj3PLWt78dFuUTyTLIdLG820J7XqLPBO4gpEEEWw/DoTsJIb+apnaem+rKtQ1h3Q==", "X-Minio-Internal-Server-Side-Encryption-Seal-Algorithm": "DAREv2-HMAC-SHA256", "content-type": "application/octet-stream", "etag": "20000f00e2c3709dc94905c6ce31e1cadbd1c064e14acdcd44cf0ac2db777eeedd88d639fcd64de16851ade8b21a9a1a"}, Parts: []ObjectPartInfo{{ETag: "", Number: 1, Size: 3430, ActualSize: 3398}}, Erasure: ErasureInfo{Algorithm: "reedsolomon", DataBlocks: 2, ParityBlocks: 2, BlockSize: 10485760, Index: 3, Distribution: []int{3, 4, 1, 2}, Checksums: []ChecksumInfo{{PartNumber: 1, Algorithm: 0x3, Hash: []uint8{}}}}}
   198  	b.SetBytes(1)
   199  	b.ReportAllocs()
   200  	b.ResetTimer()
   201  	for i := 0; i < b.N; i++ {
   202  		err := msgp.Encode(ioutil.Discard, &v)
   203  		if err != nil {
   204  			b.Fatal(err)
   205  		}
   206  	}
   207  }
   208  
   209  func BenchmarkEncodeFileInfoGOB(b *testing.B) {
   210  	v := FileInfo{Volume: "testbucket", Name: "src/compress/zlib/reader_test.go", VersionID: "", IsLatest: true, Deleted: false, DataDir: "5e0153cc-621a-4267-8cb6-4919140d53b3", XLV1: false, ModTime: UTCNow(), Size: 3430, Mode: 0x0, Metadata: map[string]string{"X-Minio-Internal-Server-Side-Encryption-Iv": "jIJPsrkkVYYMvc7edBrNl+7zcM7+ZwXqMb/YAjBO/ck=", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Key-Id": "my-minio-key", "X-Minio-Internal-Server-Side-Encryption-S3-Kms-Sealed-Key": "IAAfAP2p7ZLv3UpLwBnsKkF2mtWba0qoY42tymK0szRgGvAxBNcXyHXYooe9dQpeeEJWgKUa/8R61oCy1mFwIg==", "X-Minio-Internal-Server-Side-Encryption-S3-Sealed-Key": "IAAfAPFYRDkHVirJBJxBixNj3PLWt78dFuUTyTLIdLG820J7XqLPBO4gpEEEWw/DoTsJIb+apnaem+rKtQ1h3Q==", "X-Minio-Internal-Server-Side-Encryption-Seal-Algorithm": "DAREv2-HMAC-SHA256", "content-type": "application/octet-stream", "etag": "20000f00e2c3709dc94905c6ce31e1cadbd1c064e14acdcd44cf0ac2db777eeedd88d639fcd64de16851ade8b21a9a1a"}, Parts: []ObjectPartInfo{{ETag: "", Number: 1, Size: 3430, ActualSize: 3398}}, Erasure: ErasureInfo{Algorithm: "reedsolomon", DataBlocks: 2, ParityBlocks: 2, BlockSize: 10485760, Index: 3, Distribution: []int{3, 4, 1, 2}, Checksums: []ChecksumInfo{{PartNumber: 1, Algorithm: 0x3, Hash: []uint8{}}}}}
   211  	enc := gob.NewEncoder(ioutil.Discard)
   212  	b.SetBytes(1)
   213  	b.ReportAllocs()
   214  	b.ResetTimer()
   215  	for i := 0; i < b.N; i++ {
   216  		err := enc.Encode(&v)
   217  		if err != nil {
   218  			b.Fatal(err)
   219  		}
   220  	}
   221  }