package pb import ( "strconv" "testing" util_mem "github.com/seaweedfs/seaweedfs/weed/util/mem" "google.golang.org/grpc/mem" ) // The proto codec takes its buffers from the process-wide default pool. func TestGrpcBufferPoolIsTheDefault(t *testing.T) { if mem.DefaultBufferPool() != (util_mem.SlotPool{}) { t.Fatal("gRPC's default buffer pool is not the slot pool") } } // gRPC's default pool zeroes the whole buffer on every Get, and between 32 KB and 1 MB that buffer // is 1 MB. Compares it with the slot pool. func BenchmarkGrpcBufferPoolGet(b *testing.B) { defaultTiers, err := mem.NewBinaryTieredBufferPool(8, 12, 14, 15, 20) if err != nil { b.Fatal(err) } for _, size := range []int{40 << 10, 100 << 10, 300 << 10, 3 << 20} { for _, p := range []struct { name string pool mem.BufferPool }{{"grpc-default", defaultTiers}, {"slots", util_mem.SlotPool{}}} { b.Run(p.name+"/"+strconv.Itoa(size>>10)+"KB", func(b *testing.B) { b.SetBytes(int64(size)) for i := 0; i < b.N; i++ { p.pool.Put(p.pool.Get(size)) } }) } } }