Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Processor #9

Merged
merged 2 commits into from
Mar 11, 2024
Merged

Introduce Processor #9

merged 2 commits into from
Mar 11, 2024

Conversation

pellared
Copy link
Owner

@pellared pellared commented Mar 11, 2024

Introducing a Processor has no impact on the performance.

$ benchstat old.txt new.txt
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
                    │   old.txt    │               new.txt               │
                    │    sec/op    │    sec/op     vs base               │
/no_attrs/Simple-16   451.4n ±  4%   453.2n ±  3%       ~ (p=0.684 n=10)
/no_attrs/Batch-16    470.7n ±  6%   436.2n ±  2%  -7.33% (p=0.000 n=10)
/3_attrs/Simple-16    653.2n ±  5%   661.8n ±  7%       ~ (p=0.280 n=10)
/3_attrs/Batch-16     687.9n ±  6%   660.4n ±  8%       ~ (p=0.436 n=10)
/5_attrs/Simple-16    767.1n ±  4%   779.6n ±  3%       ~ (p=0.165 n=10)
/5_attrs/Batch-16     833.2n ±  3%   772.5n ±  4%  -7.28% (p=0.000 n=10)
/10_attrs/Simple-16   2.076µ ±  3%   2.026µ ±  6%       ~ (p=0.210 n=10)
/10_attrs/Batch-16    2.489µ ±  7%   2.347µ ±  5%       ~ (p=0.063 n=10)
/40_attrs/Simple-16   6.010µ ±  4%   6.459µ ± 13%  +7.46% (p=0.005 n=10)
/40_attrs/Batch-16    8.201µ ± 10%   7.848µ ±  5%       ~ (p=0.165 n=10)
geomean               1.316µ         1.288µ        -2.12%

                    │    old.txt     │                new.txt                │
                    │      B/op      │     B/op      vs base                 │
/no_attrs/Simple-16     0.000 ± 0%       0.000 ± 0%       ~ (p=1.000 n=10) ¹
/no_attrs/Batch-16      0.000 ± 0%       0.000 ± 0%       ~ (p=1.000 n=10) ¹
/3_attrs/Simple-16      0.000 ± 0%       0.000 ± 0%       ~ (p=1.000 n=10) ¹
/3_attrs/Batch-16       1.000 ± 0%       1.000 ±  ?       ~ (p=0.303 n=10)
/5_attrs/Simple-16      0.000 ± 0%       0.000 ± 0%       ~ (p=1.000 n=10) ¹
/5_attrs/Batch-16       1.000 ± 0%       1.000 ± 0%       ~ (p=1.000 n=10) ¹
/10_attrs/Simple-16   1.392Ki ± 0%     1.392Ki ± 0%       ~ (p=1.000 n=10) ¹
/10_attrs/Batch-16    1.396Ki ± 0%     1.394Ki ± 0%  -0.14% (p=0.000 n=10)
/40_attrs/Simple-16   6.692Ki ± 0%     6.692Ki ± 0%       ~ (p=1.000 n=10) ¹
/40_attrs/Batch-16    6.705Ki ± 0%     6.699Ki ± 0%  -0.08% (p=0.000 n=10)
geomean                            ²                 -0.02%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                    │   old.txt    │               new.txt               │
                    │  allocs/op   │ allocs/op   vs base                 │
/no_attrs/Simple-16   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
/no_attrs/Batch-16    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
/3_attrs/Simple-16    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
/3_attrs/Batch-16     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
/5_attrs/Simple-16    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
/5_attrs/Batch-16     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
/10_attrs/Simple-16   9.000 ± 0%     9.000 ± 0%       ~ (p=1.000 n=10) ¹
/10_attrs/Batch-16    9.000 ± 0%     9.000 ± 0%       ~ (p=1.000 n=10) ¹
/40_attrs/Simple-16   13.00 ± 0%     13.00 ± 0%       ~ (p=1.000 n=10) ¹
/40_attrs/Batch-16    13.00 ± 0%     13.00 ± 0%       ~ (p=1.000 n=10) ¹
geomean                          ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

Yet it makes implementing decorators that e.g. alters a log record simpler.

Without Processor:

var pool = sync.Pool{
	New: func() any {
		b := make([]Record, 0, 1)
		return &b
	},
}

type timestampDecorator struct {
	Exporter
}

func (e timestampDecorator) Export(ctx context.Context, records []Record) error {
	bPtr := pool.Get().(*[]Record)
	defer func() {
		*bPtr = (*bPtr)[:0]
		pool.Put(bPtr)
	}()
	b := *bPtr

	for _, r := range records {
		r = r.Clone()
		r.SetObservedTimestamp(time.Date(1988, time.November, 17, 0, 0, 0, 0, time.UTC))
		b = append(b, r)
	}

	return e.Exporter.Export(ctx, b)
}

With Processor:

type timestampDecorator struct {
	Exporter
}

func (e timestampDecorator) Export(ctx context.Context, records []Record) error {
	bPtr := pool.Get().(*[]Record)
	defer func() {
		*bPtr = (*bPtr)[:0]
		pool.Put(bPtr)
	}()
	b := *bPtr

	for _, r := range records {
		r = r.Clone()
		r.SetObservedTimestamp(testTimestamp)
		b = append(b, r)
	}

	return e.Exporter.Export(ctx, b)
}

@pellared pellared merged commit 876ddd6 into sdk-log-prototype Mar 11, 2024
22 of 24 checks passed
@pellared pellared changed the title Introduce Log processor Introduce Processor Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant