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

[chore] [exporterhelper] Integrate capacity limiting into the communication channel #9232

Merged
merged 1 commit into from
May 4, 2024

Conversation

dmitryax
Copy link
Member

@dmitryax dmitryax commented Jan 6, 2024

Integrate capacity limiting into internal channels used by both memory and persistent queues. Otherwise, with the independent capacity limiter, it's hard to ensure that queue size is always accurate going forward.

Benchmarks before:

goos: darwin
goarch: arm64
Benchmark_QueueUsage_1000_requests-10      	    3252	    325010 ns/op	  246059 B/op	      10 allocs/op
Benchmark_QueueUsage_100000_requests-10    	      39	  29811116 ns/op	24002870 B/op	      10 allocs/op
Benchmark_QueueUsage_10000_items-10        	    3404	    349753 ns/op	  246052 B/op	      10 allocs/op
Benchmark_QueueUsage_1M_items-10           	      40	  29415583 ns/op	24002858 B/op	      10 allocs/op
BenchmarkPersistentQueue_TraceSpans
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_1-10         	  338180	      3836 ns/op	    2851 B/op	      78 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_10-10        	   81369	     15822 ns/op	   14598 B/op	     289 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_10_#spansPerTrace:_10-10       	   13066	     90155 ns/op	  130087 B/op	    2417 allocs/op

Benchmarks after:

Benchmark_QueueUsage_1000_requests-10      	    4210	    278175 ns/op	  246055 B/op	      10 allocs/op
Benchmark_QueueUsage_100000_requests-10    	      42	  25835945 ns/op	24002968 B/op	      10 allocs/op
Benchmark_QueueUsage_10000_items-10        	    4376	    279571 ns/op	  246056 B/op	      10 allocs/op
Benchmark_QueueUsage_1M_items-10           	      42	  26483907 ns/op	24002995 B/op	      10 allocs/op
BenchmarkPersistentQueue_TraceSpans
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_1-10         	  328268	      4251 ns/op	    2854 B/op	      78 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_10-10        	  101683	     12238 ns/op	   14582 B/op	     289 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_10_#spansPerTrace:_10-10       	   13382	     86464 ns/op	  130154 B/op	    2417 allocs/op

@dmitryax dmitryax requested a review from a team as a code owner January 6, 2024 03:44
Copy link

codecov bot commented Jan 6, 2024

Codecov Report

Attention: Patch coverage is 88.18182% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 91.86%. Comparing base (67d3718) to head (999718d).

Files Patch % Lines
exporter/internal/queue/persistent_queue.go 77.96% 10 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9232      +/-   ##
==========================================
- Coverage   91.87%   91.86%   -0.02%     
==========================================
  Files         360      361       +1     
  Lines       16717    16722       +5     
==========================================
+ Hits        15359    15361       +2     
- Misses       1020     1024       +4     
+ Partials      338      337       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmitryax dmitryax changed the title [chore] [exporterhelper] Integrate capacity limiting into a helper queue [chore] [exporterhelper] Integrate capacity limiting into the communication channel Jan 6, 2024
@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch 3 times, most recently from e7abbb5 to f994b06 Compare January 8, 2024 19:10
@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch 2 times, most recently from e57ef73 to 92d5cca Compare January 31, 2024 19:28
@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch 7 times, most recently from 65d4ef3 to f45b7e6 Compare February 10, 2024 06:43
@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch 4 times, most recently from 86baed4 to 8827d63 Compare February 12, 2024 21:33
@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch 3 times, most recently from 308ee38 to cd3b7c6 Compare February 23, 2024 17:08
Copy link
Contributor

github-actions bot commented Mar 9, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Mar 9, 2024
@dmitryax dmitryax removed the Stale label Mar 9, 2024
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Mar 26, 2024
@dmitryax dmitryax removed the Stale label Mar 26, 2024
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Apr 11, 2024
@dmitryax dmitryax removed the Stale label Apr 11, 2024
Copy link
Contributor

github-actions bot commented May 1, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label May 1, 2024
@dmitryax dmitryax removed the Stale label May 1, 2024
@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch from cd3b7c6 to 04e3a1f Compare May 2, 2024 04:20
exporter/internal/queue/bounded_memory_queue.go Outdated Show resolved Hide resolved
exporter/internal/queue/sized_elements_channel.go Outdated Show resolved Hide resolved

// withPreloadElements puts the elements into the queue with the given size. It's used by the persistent queue to
// initialize the queue with the elements recovered from the disk.
func withPreloadElements[T any](els []T, totalSize int64) sizedElementsChannelOption[T] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify this, probably next PR, we need to have 2 sizes for persistent:

  • in memory size which is fixed and smaller than the storage;
  • storage size which is how much to store in the storage;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good 👍

exporter/internal/queue/sized_elements_channel.go Outdated Show resolved Hide resolved
exporter/internal/queue/sized_elements_channel.go Outdated Show resolved Hide resolved
exporter/internal/queue/sized_elements_channel.go Outdated Show resolved Hide resolved
// syncSize updates the used size to 0 if the queue is empty.
// The caller must ensure that this call is not called concurrently with enqueue.
// It's used by the persistent queue to ensure the used value correctly reflects the reality which may not be always
// the case in case if the queue size is restored from the disk after a crash.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why? Because we don't calculate the size correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't flush the current queue size on the disk on every read/write. Should I mention that in the comment?

// enqueue puts the element into the queue with the given sized if there is enough capacity.
// Returns an error if the queue is full. The callback is called before the element is committed to the queue.
// If the callback returns an error, the element is not put into the queue and the error is returned.
func (vcq *sizedElementsChannel[T]) enqueue(el T, size int64, callback func() error) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment that size MUST be positive. We can even consider to change it to uint64? That my make the -size ugly to use with atomics, but I think it is ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comment. The atomic size field used to be in uint64, and then you asked to change it to int64 to simplify the subtraction. Do you think we should accept uint64 and convert it to int64?

exporter/internal/queue/sized_elements_channel.go Outdated Show resolved Hide resolved
exporter/internal/queue/persistent_queue.go Outdated Show resolved Hide resolved
opt(sech)
}
if sech.ch == nil {
sech.ch = make(chan T, capacity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a problem if we switch to use bytes, since it will be very large and lots of memory.

Copy link
Member Author

@dmitryax dmitryax May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. We can think of a solution outside of this PR?

@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch 2 times, most recently from d9d6892 to 4afa371 Compare May 3, 2024 18:42
Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it :)

@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch from 4afa371 to aae0856 Compare May 3, 2024 22:34
Integrate capacity limiting into internal channels used by both memory and persistent queues. Otherwise, with the independent capacity limiter, it's hard to ensure that queue size is always accurate going forward.
@dmitryax dmitryax force-pushed the itemized-queue-with-limiter branch from aae0856 to 999718d Compare May 4, 2024 05:07
@dmitryax dmitryax merged commit b7b7e51 into open-telemetry:main May 4, 2024
47 of 48 checks passed
@github-actions github-actions bot added this to the next release milestone May 4, 2024
@dmitryax dmitryax deleted the itemized-queue-with-limiter branch May 4, 2024 17:47
andrzej-stencel pushed a commit to andrzej-stencel/opentelemetry-collector that referenced this pull request May 27, 2024
…cation channel (open-telemetry#9232)

Integrate capacity limiting into internal channels used by both memory
and persistent queues. Otherwise, with the independent capacity limiter,
it's hard to ensure that queue size is always accurate going forward.

Benchmarks before:
```
goos: darwin
goarch: arm64
Benchmark_QueueUsage_1000_requests-10      	    3252	    325010 ns/op	  246059 B/op	      10 allocs/op
Benchmark_QueueUsage_100000_requests-10    	      39	  29811116 ns/op	24002870 B/op	      10 allocs/op
Benchmark_QueueUsage_10000_items-10        	    3404	    349753 ns/op	  246052 B/op	      10 allocs/op
Benchmark_QueueUsage_1M_items-10           	      40	  29415583 ns/op	24002858 B/op	      10 allocs/op
BenchmarkPersistentQueue_TraceSpans
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_1-10         	  338180	      3836 ns/op	    2851 B/op	      78 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_10-10        	   81369	     15822 ns/op	   14598 B/op	     289 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_10_#spansPerTrace:_10-10       	   13066	     90155 ns/op	  130087 B/op	    2417 allocs/op
```

Benchmarks after:
```
Benchmark_QueueUsage_1000_requests-10      	    4210	    278175 ns/op	  246055 B/op	      10 allocs/op
Benchmark_QueueUsage_100000_requests-10    	      42	  25835945 ns/op	24002968 B/op	      10 allocs/op
Benchmark_QueueUsage_10000_items-10        	    4376	    279571 ns/op	  246056 B/op	      10 allocs/op
Benchmark_QueueUsage_1M_items-10           	      42	  26483907 ns/op	24002995 B/op	      10 allocs/op
BenchmarkPersistentQueue_TraceSpans
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_1-10         	  328268	      4251 ns/op	    2854 B/op	      78 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_1_#spansPerTrace:_10-10        	  101683	     12238 ns/op	   14582 B/op	     289 allocs/op
BenchmarkPersistentQueue_TraceSpans/#traces:_10_#spansPerTrace:_10-10       	   13382	     86464 ns/op	  130154 B/op	    2417 allocs/op
```
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.

None yet

3 participants