You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2023/01/04 18:10:12 UTC

[GitHub] [beam] shanemhansen opened a new pull request, #24881: Reduce lock contention for metrics hashName hasher

shanemhansen opened a new pull request, #24881:
URL: https://github.com/apache/beam/pull/24881

   The singleton hasher used by hashName can be highly contented and reduce overall multi-core throughput. This has been observed in applications that dynamically create lots of counters. This change adds a parallel benchmark to measure multi-core performance for applications. It also changes the singleton hasher to use sync.Pool and thus benefit from it's per-P cache:
   
   - https://www.sobyte.net/post/2022-03/think-in-sync-pool/
   
   In benchmarks this change can provide ~4x performance improvements in multicore situations.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] damccorm commented on a diff in pull request #24881: Reduce lock contention for metrics hashName hasher

Posted by GitBox <gi...@apache.org>.
damccorm commented on code in PR #24881:
URL: https://github.com/apache/beam/pull/24881#discussion_r1062615527


##########
sdks/go/pkg/beam/core/metrics/metrics_test.go:
##########
@@ -617,21 +617,23 @@ func TestPcolQueryResult(t *testing.T) {
 	}
 }
 
-// Run on @lostluck's desktop (2020/01/21) go1.13.4
+// Run on @shanemhansen's desktop (2022/01/03) go1.20 RC1 after changing hashName to use a pool of hashers
+// sync.Pool can return thread-local results eliminating the need for a lock and increasing throughput.
+// There are users in the wild who create an excessive number of Counters so a 4x improvement in throughput at the expense of
+// creating GOMAXPROCS hasher values seems reasonable.
 //
-// Allocs & bytes should be consistent within go versions, but ns/op is relative to the running machine.
-//
-// BenchmarkMetrics/counter_inplace-12              6054129               208 ns/op              48 B/op          1 allocs/op
-// BenchmarkMetrics/distribution_inplace-12         5707147               228 ns/op              48 B/op          1 allocs/op
-// BenchmarkMetrics/gauge_inplace-12                4742331               259 ns/op              48 B/op          1 allocs/op
-// BenchmarkMetrics/counter_predeclared-12         90147133                12.7 ns/op             0 B/op          0 allocs/op
-// BenchmarkMetrics/distribution_predeclared-12            55396678                21.6 ns/op             0 B/op          0 allocs/op
-// BenchmarkMetrics/gauge_predeclared-12                   18535839                60.5 ns/op             0 B/op          0 allocs/op
-// BenchmarkMetrics/counter_raw-12                         159581343                7.18 ns/op            0 B/op          0 allocs/op
-// BenchmarkMetrics/distribution_raw-12                    82724314                14.7 ns/op             0 B/op          0 allocs/op
-// BenchmarkMetrics/gauge_raw-12                           23292386                55.2 ns/op             0 B/op          0 allocs/op
-// BenchmarkMetrics/getStore-12                            309361303                3.78 ns/op            0 B/op          0 allocs/op
-// BenchmarkMetrics/getCounterSet-12                       287720998                3.98 ns/op            0 B/op          0 allocs/op
+// name                                 old time/op  new time/op  delta
+// Metrics/counter_inplace-12            376ns ±17%    88ns ± 7%  -76.66%  (p=0.008 n=5+5)
+// Metrics/distribution_inplace-12       394ns ± 3%   153ns ± 8%  -61.17%  (p=0.008 n=5+5)
+// Metrics/gauge_inplace-12              371ns ± 4%   258ns ± 1%  -30.37%  (p=0.008 n=5+5)

Review Comment:
   Nice



##########
sdks/go/pkg/beam/core/metrics/metrics_test.go:
##########
@@ -617,21 +617,23 @@ func TestPcolQueryResult(t *testing.T) {
 	}
 }
 
-// Run on @lostluck's desktop (2020/01/21) go1.13.4
+// Run on @shanemhansen's desktop (2022/01/03) go1.20 RC1 after changing hashName to use a pool of hashers
+// sync.Pool can return thread-local results eliminating the need for a lock and increasing throughput.
+// There are users in the wild who create an excessive number of Counters so a 4x improvement in throughput at the expense of
+// creating GOMAXPROCS hasher values seems reasonable.

Review Comment:
   We should probably cut some of this before merging.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] codecov[bot] commented on pull request #24881: Reduce lock contention for metrics hashName hasher

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #24881:
URL: https://github.com/apache/beam/pull/24881#issuecomment-1371262465

   # [Codecov](https://codecov.io/gh/apache/beam/pull/24881?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#24881](https://codecov.io/gh/apache/beam/pull/24881?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8c0142c) into [master](https://codecov.io/gh/apache/beam/commit/c46c6d373d7af23e90630f0d201da1389d106d91?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c46c6d3) will **increase** coverage by `0.00%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@           Coverage Diff           @@
   ##           master   #24881   +/-   ##
   =======================================
     Coverage   73.11%   73.11%           
   =======================================
     Files         731      731           
     Lines       97955    97958    +3     
   =======================================
   + Hits        71621    71624    +3     
     Misses      24979    24979           
     Partials     1355     1355           
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | go | `51.46% <100.00%> (+<0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/beam/pull/24881?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [sdks/go/pkg/beam/core/metrics/metrics.go](https://codecov.io/gh/apache/beam/pull/24881/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9nby9wa2cvYmVhbS9jb3JlL21ldHJpY3MvbWV0cmljcy5nbw==) | `60.54% <100.00%> (+0.24%)` | :arrow_up: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] lostluck commented on pull request #24881: Reduce lock contention for metrics hashName hasher

Posted by GitBox <gi...@apache.org>.
lostluck commented on PR #24881:
URL: https://github.com/apache/beam/pull/24881#issuecomment-1372478576

   It's been a while since I looked at sync.Pool, so there are probably other similar opportunities available (WRT general object re-use) elsewhere in the SDK. More often than not, each bundle gets its own instance of everything it needs, but there are one or two common resource locks we might be able to do better with.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] lostluck commented on a diff in pull request #24881: Reduce lock contention for metrics hashName hasher

Posted by GitBox <gi...@apache.org>.
lostluck commented on code in PR #24881:
URL: https://github.com/apache/beam/pull/24881#discussion_r1062686389


##########
sdks/go/pkg/beam/core/metrics/metrics_test.go:
##########
@@ -617,21 +617,23 @@ func TestPcolQueryResult(t *testing.T) {
 	}
 }
 
-// Run on @lostluck's desktop (2020/01/21) go1.13.4
+// Run on @shanemhansen's desktop (2022/01/03) go1.20 RC1 after changing hashName to use a pool of hashers
+// sync.Pool can return thread-local results eliminating the need for a lock and increasing throughput.
+// There are users in the wild who create an excessive number of Counters so a 4x improvement in throughput at the expense of
+// creating GOMAXPROCS hasher values seems reasonable.

Review Comment:
   I'm OK with keeping it. It's pedagogical.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] lostluck merged pull request #24881: Reduce lock contention for metrics hashName hasher

Posted by GitBox <gi...@apache.org>.
lostluck merged PR #24881:
URL: https://github.com/apache/beam/pull/24881


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] github-actions[bot] commented on pull request #24881: Reduce lock contention for metrics hashName hasher

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #24881:
URL: https://github.com/apache/beam/pull/24881#issuecomment-1371283250

   Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
   
   R: @damccorm for label go.
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review comments).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org