chore: use less locking in metrics hot paths - #213
Conversation
Pull Request Test Coverage Report for Build 19563538142Details
💛 - Coveralls |
| return actual.(*toggleCounters) | ||
| } | ||
|
|
||
| func (m *metrics) reinsertBucket(bucket api.Bucket) { |
There was a problem hiding this comment.
Previously the code just dropped variants on the floor when re-inserting. Needed to get fixed and now seems like a good time I guess so here's a fix
| atomic.AddInt64(&c.yes, int64(num)) | ||
| } else { | ||
| t.No += num | ||
| atomic.AddInt64(&c.no, int64(num)) |
There was a problem hiding this comment.
Wheee atomic primitives are awesome. We can do this on the hardware level and not sandwiched between the runtime and OS
| st.Expect(t, gock.IsDone(), true) | ||
| } | ||
|
|
||
| func TestReinsertingBucketsAlsoRestoresVariants(t *testing.T) { |
There was a problem hiding this comment.
New test for the re-insert variant logic
db94232 to
e39f515
Compare
2cf51a1 to
bd4c12b
Compare
e39f515 to
1c38a81
Compare
bd4c12b to
2b95c7f
Compare
FredrikOseberg
left a comment
There was a problem hiding this comment.
Some nits, otherwise LGTM
| } | ||
| } | ||
|
|
||
| tc := api.ToggleCount{ |
There was a problem hiding this comment.
toggleCount would be clearer
There was a problem hiding this comment.
Yep, took that suggestion. Uh... is there a pattern for this? The default Go community stance seems to be make variables as short and difficult to read as possible so I've accidentally followed that sometimes but I hate it. Is the a rule where we shouldn't do that?
|
|
||
| m.counters.Range(func(key, value any) bool { | ||
| name := key.(string) | ||
| c := value.(*toggleCounters) |
There was a problem hiding this comment.
counters? I find myself scrolling up to figure out what this variable is.
|
|
||
| func (m *metrics) reinsertBucket(bucket api.Bucket) { | ||
| for name, tc := range bucket.Toggles { | ||
| c := m.getOrCreateCounter(name) |
There was a problem hiding this comment.
Also fair, also patched
4adee3f to
19b67c5
Compare
* fix: variant strategies now correctly inherit stickiness from their strategy * chore: make metric count channels best effort send (#214)
09b1a34
into
fix/use-sync-pool-for-strategy-randomness
Yeets the locking in the metrics code in favor of sync primitives. Fixes a bug in the re-insertion code since I was in that space. Variants are still behind a mutex but that mutex is now smaller scoped and locked less often. We can probably remove that too but its a bigger PR and I want to keep this focused on the hot path