refactor(meta): add bench testcase for inode marshal. #1000114612

Signed-off-by: Victor1319 <zengxuewei@oppo.com>
This commit is contained in:
Victor1319 2025-05-13 16:49:38 +08:00 committed by zhumingze1108
parent 6f209ae5e9
commit 388b1cb7cf
12 changed files with 64 additions and 24 deletions

View File

@ -6,8 +6,10 @@ import (
"github.com/cubefs/cubefs/util/buf"
)
const inodeBufSize = 40960 // size about 128G
const dentryBufSize = 1024
const (
inodeBufSize = 40960 // size about 128G
dentryBufSize = 1024
)
var inodeBufPool = sync.Pool{
New: func() interface{} {

View File

@ -573,7 +573,6 @@ func (d *Dentry) Marshal() (result []byte, err error) {
// Marshal marshals a dentry into a byte array.
func (d *Dentry) MarshalV2(buff *buf.ByteBufExt) (err error) {
keyBuf := GetDentryBuf()
defer PutDentryBuf(keyBuf)
d.MarshalKeyV2(keyBuf)
@ -732,7 +731,6 @@ func (d *Dentry) MarshalKey() (k []byte) {
}
func (d *Dentry) MarshalKeyV2(buff *buf.ByteBufExt) {
if err := buff.PutUint64(d.ParentId); err != nil {
panic(err)
}
@ -792,7 +790,6 @@ func (d *Dentry) MarshalValue() []byte {
}
func (d *Dentry) MarshalValueV2(buff *buf.ByteBufExt) {
if err := buff.PutUint64(d.Inode); err != nil {
panic(err)
}
@ -826,8 +823,6 @@ func (d *Dentry) MarshalValueV2(buff *buf.ByteBufExt) {
writeBinary(&seq)
}
}
return
}
func (d *Dentry) UnmarshalValue(val []byte) (err error) {

View File

@ -35,7 +35,6 @@ func dentryDqual(d1, d2 *Dentry) bool {
}
func TestDentryMarshalCompitable(t *testing.T) {
snap := NewDentrySnap(1024)
snap.dentryList = append(snap.dentryList, &Dentry{
Name: "old_name",
@ -65,7 +64,6 @@ func TestDentryMarshalCompitable(t *testing.T) {
}
func TestDentryMarshal(t *testing.T) {
d := &Dentry{
ParentId: 1,
Name: "test",

View File

@ -685,11 +685,12 @@ func (i *Inode) Unmarshal(data []byte) (err error) {
return proto.ErrBufferSizeExceedMaximum
}
keyBytes := make([]byte, keyLen)
if _, err = buff.Read(keyBytes); err != nil {
keyBytes, err := buff.Next(int(keyLen))
if err != nil {
err = errors.NewErrorf("[Unmarshal] read keyBytes: %s", err.Error())
return
}
if err = i.UnmarshalKey(keyBytes); err != nil {
err = errors.NewErrorf("[Unmarshal] UnmarshalKey: %s", err.Error())
return
@ -940,7 +941,6 @@ func (i *Inode) MarshalInodeValue(buff *buf.ByteBufExt) {
if err = buff.PutUint64(i.getVer()); err != nil {
panic(err)
}
}
if err = buff.PutUint32(i.StorageClass); err != nil {
@ -1064,7 +1064,6 @@ func (i *Inode) MarshalValueV2(buff *buf.ByteBufExt) {
}
}
i.RUnlock()
return
}
func UnmarshalInodeFiledError(errFieldName string, originErr error) (err error) {
@ -1327,7 +1326,6 @@ func (i *Inode) UnmarshalInodeValue(buff *bytes.Buffer) (err error) {
}
func (i *Inode) UnmarshalInodeValueV2(buff *buf.ReadByteBuff) (err error) {
if i.Type, err = buff.ReadUint32(); err != nil {
err = UnmarshalInodeFiledError("Type", err)
return

View File

@ -4,8 +4,10 @@ import (
"bytes"
"os"
"testing"
"unsafe"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -164,8 +166,11 @@ func TestV4MigrationInodeCopyDirectly(t *testing.T) {
assert.True(t, ino.Equal(temp))
}
func TestInodeMarshal(t *testing.T) {
func TestInodeAlign(t *testing.T) {
t.Logf("inode dentry size %d", unsafe.Sizeof(Inode{}))
}
func TestInodeMarshal(t *testing.T) {
checkInodeMarshal := func(a *Inode, t *testing.T) {
data, err := a.Marshal()
if err != nil {
@ -329,6 +334,8 @@ func BenchmarkInodeMarshal(b *testing.B) {
oldIno.StorageClass = proto.StorageClass_Replica_SSD
oldIno.HybridCloudExtents.sortedEks = NewSortedExtentsFromEks([]proto.ExtentKey{{FileOffset: 100}})
log.SetLogLevelV2(log.WarnLevel)
buff := GetInodeBuf()
defer PutInodeBuf(buff)
@ -342,3 +349,41 @@ func BenchmarkInodeMarshal(b *testing.B) {
}
}
}
func BenchmarkInodeUnmarshal(b *testing.B) {
oldIno := NewInode(1024, 0)
oldIno.Uid = 101
oldIno.Gid = 102
oldIno.Generation = 104
oldIno.CreateTime = 105
oldIno.AccessTime = 106
oldIno.ModifyTime = 107
oldIno.NLink = 108
oldIno.Flag = 109
oldIno.StorageClass = proto.StorageClass_Replica_SSD
oldIno.HybridCloudExtents.sortedEks = NewSortedExtentsFromEks([]proto.ExtentKey{{FileOffset: 100}})
buff := GetInodeBuf()
defer PutInodeBuf(buff)
log.SetLogLevelV2(log.WarnLevel)
err := oldIno.MarshalV2(buff)
if err != nil {
b.Fatal(err)
}
data := buff.Bytes()
newInode := NewInode(0, 0)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
err = newInode.Unmarshal(data)
if err != nil {
b.Fail()
}
}
_ = newInode
}

View File

@ -759,7 +759,7 @@ func (mp *metaPartition) sendExtentsToChan(eks []proto.ExtentKey) (err error) {
if err != nil {
return fmt.Errorf("[delExtents] marshal binary fail, %s", err.Error())
}
val := buf.Bytes()
if !isSnap {
_, err = mp.submit(opFSMSentToChan, val)

View File

@ -44,7 +44,6 @@ func TestStoreDentry(t *testing.T) {
}
func TestStoreDentryCompitable(t *testing.T) {
oldCrc := uint32(713290320)
// old date is marshal byte for dtree by old version
oldData := []byte{0, 0, 0, 34, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 101, 116, 101, 115, 116, 95, 48, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 201, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 102, 116, 101, 115, 116, 95, 49, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 202, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 103, 116, 101, 115, 116, 95, 50, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 203, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 104, 116, 101, 115, 116, 95, 51, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 204, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 105, 116, 101, 115, 116, 95, 52, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 205, 0, 0, 0, 0}
@ -124,7 +123,6 @@ func TestStoreInode(t *testing.T) {
}
func TestStoreInodeCompitable(t *testing.T) {
oldCrc := uint32(4195506950)
// old date is marshal byte for dtree by version 3.5.0
oldData := []byte{0, 0, 0, 155, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 139, 128, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 102, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0, 0, 0, 0, 0, 106, 0, 0, 0, 0, 0, 0, 0, 107, 0, 0, 0, 7, 116, 101, 115, 116, 32, 111, 112, 0, 0, 0, 108, 0, 0, 0, 109, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0, 139, 128, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 102, 0, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0, 0, 0, 0, 0, 106, 0, 0, 0, 0, 0, 0, 0, 107, 0, 0, 0, 7, 116, 101, 115, 116, 32, 111, 112, 0, 0, 0, 108, 0, 0, 0, 109, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 106, 0, 0, 0, 139, 128, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 102, 0, 0, 0, 0, 0, 0, 0, 102, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0, 0, 0, 0, 0, 106, 0, 0, 0, 0, 0, 0, 0, 107, 0, 0, 0, 7, 116, 101, 115, 116, 32, 111, 112, 0, 0, 0, 108, 0, 0, 0, 109, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

View File

@ -45,7 +45,6 @@ func (se *SortedExtents) String() string {
}
func (se *SortedExtents) MarshalBinary(buf *buf.ByteBufExt, v3 bool) error {
se.RLock()
defer se.RUnlock()

View File

@ -29,9 +29,11 @@ import (
"github.com/cubefs/cubefs/util/log"
)
const DefaultDpRepairBlockSize = 128 * util.KB
const ExtentKeyVerLen = 49
const ExtentLength = 40
const (
DefaultDpRepairBlockSize = 128 * util.KB
ExtentKeyVerLen = 49
ExtentLength = 40
)
var (
ExtentKeyHeader = []byte("EKV2")

View File

@ -33,4 +33,4 @@ func TestFileBCachePool(t *testing.T) {
//secondVal = buf.BCachePool.Get()
//// check put and get
//require.Same(t, oldAddr, &secondVal[0])
}
}

View File

@ -9,7 +9,6 @@ import (
)
func TestByteBufEx(t *testing.T) {
buff := NewByteBufEx(7)
if buff.Cap() != 7 {
t.Fail()

View File

@ -539,6 +539,10 @@ func SetLogLevel(w http.ResponseWriter, r *http.Request) {
buildSuccessResp(w, "set log level success")
}
func SetLogLevelV2(level Level) {
gLog.level = level
}
func buildSuccessResp(w http.ResponseWriter, data interface{}) {
buildJSONResp(w, http.StatusOK, data, "")
}