Skip to content

Commit

Permalink
impove trace mem usage in Debug api (matrixorigin#11648)
Browse files Browse the repository at this point in the history
modification: reduce `context.Context` allocation in `trace.Debug`

improvment:
- mem cost reduced from 200+MB to a few Bytes. Test by benchmark: `BenchmarkWithoutConflict`

test cmd:
```
cd .../matrixone/pkg/lockservice
go test -test.bench BenchmarkWithoutConflict -test.run ^$ -test.benchtime 1s -test.memprofile ..../alloc.pprof
```

- improved pprof (alloc)
[improved_alloc.profile.pb.gz](https://github.com/matrixorigin/matrixone/files/12523543/improved_alloc.profile.pb.gz)

![image](https://github.com/matrixorigin/matrixone/assets/3927687/ec4b1d49-a730-4572-b49a-7b3b0e1b9aee)


- origin pprof (alloc)
[alloc.profile.pb.gz](https://github.com/matrixorigin/matrixone/files/12523525/alloc.profile.pb.gz)

![image](https://github.com/matrixorigin/matrixone/assets/3927687/26247882-de89-47a9-8273-3f1850c00a25)

Approved by: @zhangxu19830126
  • Loading branch information
xzxiong authored Sep 5, 2023
1 parent a35a9fc commit 1a8dd32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/util/export/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ func TestMergeTaskExecutorFactory(t *testing.T) {
ts, err := time.Parse("2006-01-02 15:04:05", targetDate+" 00:00:00")
require.Nil(t, err)

ctx := trace.Generate(context.TODO())

type args struct {
ctx context.Context
opts []MergeOption
Expand All @@ -329,7 +331,7 @@ func TestMergeTaskExecutorFactory(t *testing.T) {
{
name: "normal",
args: args{
ctx: context.Background(),
ctx: ctx,
opts: []MergeOption{WithFileService(fs)},
task: task.Task{
Metadata: task.TaskMetadata{
Expand Down
12 changes: 11 additions & 1 deletion pkg/util/trace/noop_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ func (t NoopTracer) Start(ctx context.Context, name string, opts ...SpanStartOpt
if _, ok := span.(NoopSpan); !ok {
// span is likely already a NoopSpan, but let's be sure
span = NoopSpan{}
return ContextWithSpan(ctx, span), span
} else if len(opts) > 0 {
var sc = SpanConfig{}
for _, opt := range opts {
opt.ApplySpanStart(&sc)
}
if sc.NewRoot {
span = NoopSpan{}
return ContextWithSpan(ctx, span), span
}
}
return ContextWithSpan(ctx, span), span
return ctx, span
}

func (t NoopTracer) Debug(ctx context.Context, name string, opts ...SpanStartOption) (context.Context, Span) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/trace/noop_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ func Test_NoopTracer_Start(t1 *testing.T) {
want: ContextWithSpan(context.Background(), NoopSpan{}),
want1: NoopSpan{},
},
{
name: "empty",
args: args{
ctx: context.Background(),
name: "NoopTracer_Start",
in2: []SpanStartOption{},
endIn: []SpanEndOption{},
},
want: context.Background(),
want1: NoopSpan{},
},
{
name: "NonRecording",
args: args{
Expand Down

0 comments on commit 1a8dd32

Please sign in to comment.