github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/storage-datatypes_test.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "bytes" 22 "encoding/gob" 23 "io" 24 "testing" 25 "time" 26 27 "github.com/tinylib/msgp/msgp" 28 ) 29 30 func BenchmarkDecodeVolInfoMsgp(b *testing.B) { 31 v := VolInfo{ 32 Name: "uuid", 33 Created: time.Now(), 34 } 35 var buf bytes.Buffer 36 msgp.Encode(&buf, &v) 37 rd := msgp.NewEndlessReader(buf.Bytes(), b) 38 dc := msgp.NewReader(rd) 39 b.Log("Size:", buf.Len(), "bytes") 40 b.SetBytes(1) 41 b.ReportAllocs() 42 b.ResetTimer() 43 for i := 0; i < b.N; i++ { 44 err := v.DecodeMsg(dc) 45 if err != nil { 46 b.Fatal(err) 47 } 48 } 49 } 50 51 func BenchmarkDecodeDiskInfoMsgp(b *testing.B) { 52 v := DiskInfo{ 53 Total: 1000, 54 Free: 1000, 55 Used: 1000, 56 FSType: "xfs", 57 RootDisk: true, 58 Healing: true, 59 Endpoint: "http://localhost:9001/tmp/drive1", 60 MountPath: "/tmp/drive1", 61 ID: "uuid", 62 Error: "", 63 } 64 var buf bytes.Buffer 65 msgp.Encode(&buf, &v) 66 rd := msgp.NewEndlessReader(buf.Bytes(), b) 67 dc := msgp.NewReader(rd) 68 b.Log("Size:", buf.Len(), "bytes") 69 b.SetBytes(1) 70 b.ReportAllocs() 71 b.ResetTimer() 72 for i := 0; i < b.N; i++ { 73 err := v.DecodeMsg(dc) 74 if err != nil { 75 b.Fatal(err) 76 } 77 } 78 } 79 80 func BenchmarkDecodeDiskInfoGOB(b *testing.B) { 81 v := DiskInfo{ 82 Total: 1000, 83 Free: 1000, 84 Used: 1000, 85 FSType: "xfs", 86 RootDisk: true, 87 Healing: true, 88 Endpoint: "http://localhost:9001/tmp/drive1", 89 MountPath: "/tmp/drive1", 90 ID: "uuid", 91 Error: "", 92 } 93 94 var buf bytes.Buffer 95 gob.NewEncoder(&buf).Encode(v) 96 encoded := buf.Bytes() 97 b.Log("Size:", buf.Len(), "bytes") 98 b.SetBytes(1) 99 b.ReportAllocs() 100 b.ResetTimer() 101 for i := 0; i < b.N; i++ { 102 dec := gob.NewDecoder(bytes.NewBuffer(encoded)) 103 err := dec.Decode(&v) 104 if err != nil { 105 b.Fatal(err) 106 } 107 } 108 } 109 110 func BenchmarkEncodeDiskInfoMsgp(b *testing.B) { 111 v := DiskInfo{ 112 Total: 1000, 113 Free: 1000, 114 Used: 1000, 115 FSType: "xfs", 116 RootDisk: true, 117 Healing: true, 118 Endpoint: "http://localhost:9001/tmp/drive1", 119 MountPath: "/tmp/drive1", 120 ID: "uuid", 121 Error: "", 122 } 123 124 b.SetBytes(1) 125 b.ReportAllocs() 126 b.ResetTimer() 127 for i := 0; i < b.N; i++ { 128 err := msgp.Encode(io.Discard, &v) 129 if err != nil { 130 b.Fatal(err) 131 } 132 } 133 } 134 135 func BenchmarkEncodeDiskInfoGOB(b *testing.B) { 136 v := DiskInfo{ 137 Total: 1000, 138 Free: 1000, 139 Used: 1000, 140 FSType: "xfs", 141 RootDisk: true, 142 Healing: true, 143 Endpoint: "http://localhost:9001/tmp/drive1", 144 MountPath: "/tmp/drive1", 145 ID: "uuid", 146 Error: "", 147 } 148 149 enc := gob.NewEncoder(io.Discard) 150 b.SetBytes(1) 151 b.ReportAllocs() 152 b.ResetTimer() 153 for i := 0; i < b.N; i++ { 154 err := enc.Encode(&v) 155 if err != nil { 156 b.Fatal(err) 157 } 158 } 159 } 160 161 func BenchmarkDecodeFileInfoMsgp(b *testing.B) { 162 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{}}}}} 163 var buf bytes.Buffer 164 msgp.Encode(&buf, &v) 165 rd := msgp.NewEndlessReader(buf.Bytes(), b) 166 dc := msgp.NewReader(rd) 167 b.Log("Size:", buf.Len(), "bytes") 168 b.SetBytes(1) 169 b.ReportAllocs() 170 b.ResetTimer() 171 for i := 0; i < b.N; i++ { 172 err := v.DecodeMsg(dc) 173 if err != nil { 174 b.Fatal(err) 175 } 176 } 177 } 178 179 func BenchmarkDecodeFileInfoGOB(b *testing.B) { 180 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{}}}}} 181 var buf bytes.Buffer 182 gob.NewEncoder(&buf).Encode(v) 183 encoded := buf.Bytes() 184 b.Log("Size:", buf.Len(), "bytes") 185 b.SetBytes(1) 186 b.ReportAllocs() 187 b.ResetTimer() 188 for i := 0; i < b.N; i++ { 189 dec := gob.NewDecoder(bytes.NewBuffer(encoded)) 190 err := dec.Decode(&v) 191 if err != nil { 192 b.Fatal(err) 193 } 194 } 195 } 196 197 func BenchmarkEncodeFileInfoMsgp(b *testing.B) { 198 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{}}}}} 199 b.SetBytes(1) 200 b.ReportAllocs() 201 b.ResetTimer() 202 for i := 0; i < b.N; i++ { 203 err := msgp.Encode(io.Discard, &v) 204 if err != nil { 205 b.Fatal(err) 206 } 207 } 208 } 209 210 func BenchmarkEncodeFileInfoGOB(b *testing.B) { 211 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{}}}}} 212 enc := gob.NewEncoder(io.Discard) 213 b.SetBytes(1) 214 b.ReportAllocs() 215 b.ResetTimer() 216 for i := 0; i < b.N; i++ { 217 err := enc.Encode(&v) 218 if err != nil { 219 b.Fatal(err) 220 } 221 } 222 }