timescale / promscale

[DEPRECATED] Promscale is a unified metric and trace observability backend for Prometheus, Jaeger and OpenTelemetry built on PostgreSQL and TimescaleDB.
https://www.timescale.com/promscale
Apache License 2.0
1.33k stars 169 forks source link

Use common array pool when unmarshalling protobufs #1791

Closed niksajakovljevic closed 1 year ago

niksajakovljevic commented 1 year ago

We reuse one bigger array and avoid allocating smaller arrays for each Timeseries. This results in less memory allocations.

Before: BenchmarkProtoUnmarshall-10 144 8194256 ns/op 22833242 B/op 150342 allocs/op

After: BenchmarkProtoUnmarshall-10 145 8174649 ns/op 32628033 B/op 100650 allocs/op

So the allocations are down by around 1/3, however memory usage is up for 1/3 due to larger arrays being allocated.

niksajakovljevic commented 1 year ago

This is potentially blocked on https://github.com/timescale/promscale/pull/1753 . Since now we keep array pool the trick that we were doing at https://github.com/timescale/promscale/blob/master/pkg/pgmodel/ingestor/ingestor.go#L236 will not play nicely any more. So either we clear the protobufs after the ingest (like proposed in #1753) or refactor to copy samples.

I am also a bit concerned about higher memory usage.

niksajakovljevic commented 1 year ago

Sharing memory profile of given optimization (left) and existing master (right).

Memory in use:

Screenshot 2022-12-13 at 17 45 03

Objects in use:

Screenshot 2022-12-13 at 17 45 22

It does seem that array pools don't have huge initial spike in memory. Also number of allocated objects is noticeably smaller.

niksajakovljevic commented 1 year ago

Surprisingly cluster benchmark is showing that this implementation uses more memory.

Screenshot 2022-12-23 at 14 58 55

I'll investigate further.

niksajakovljevic commented 1 year ago

Project got deprecated