Skip to content

Conversation

@kevinGC
Copy link
Contributor

@kevinGC kevinGC commented Oct 8, 2025

This has been useful to me for quick testing to see whether changes are performant. Compared to other benchmarks in record_test, this:

  • Exercises TCP, which is more realistic than byte.Buffer
  • Runs the reader and writer in parallel rather than sequentually

Since it only runs locally, it can be run easily. For example:

$ go test -run="^$" -bench="BenchmarkTCP" ./credentials/alts/internal/conn
goos: linux
goarch: amd64
pkg: google.golang.org/grpc/credentials/alts/internal/conn
cpu: AMD Ryzen Threadripper PRO 3945WX 12-Cores
BenchmarkTCP/size=1_KiB-12                   100          10058898 ns/op                 0 Mbps         97.34 cpu-usec/op               97.34 sys-usec/op                0 usr-usec/op
BenchmarkTCP/size=4_KiB-12                   100          10069605 ns/op                 2.979 Mbps            146.2 cpu-usec/op               104.7 sys-usec/op                41.42 usr-usec/op
BenchmarkTCP/size=64_KiB-12                  100          10510067 ns/op                47.57 Mbps            1116 cpu-usec/op         859.7 sys-usec/op               256.7 usr-usec/op
BenchmarkTCP/size=512_KiB-12                 100          13707500 ns/op               291.8 Mbps             8167 cpu-usec/op        6872 sys-usec/op        1295 usr-usec/op
BenchmarkTCP/size=1_MiB-12                   100          17343824 ns/op               461.3 Mbps            16276 cpu-usec/op       13361 sys-usec/op        2915 usr-usec/op
BenchmarkTCP/size=4_MiB-12                    32          39019702 ns/op               820.1 Mbps            64387 cpu-usec/op       51945 sys-usec/op       12443 usr-usec/op
PASS
ok      google.golang.org/grpc/credentials/alts/internal/conn   7.487s

RELEASE NOTES: none

@codecov
Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.87%. Comparing base (9ff80a7) to head (18751a6).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8636      +/-   ##
==========================================
- Coverage   81.96%   81.87%   -0.09%     
==========================================
  Files         415      416       +1     
  Lines       40694    40789      +95     
==========================================
+ Hits        33355    33397      +42     
- Misses       5950     6019      +69     
+ Partials     1389     1373      -16     

see 41 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@easwars
Copy link
Contributor

easwars commented Oct 10, 2025

@gtcooke94 Could you please review this? Thanks.

@easwars easwars added Type: Testing Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. labels Oct 10, 2025
@easwars easwars added this to the 1.77 Release milestone Oct 10, 2025
@gtcooke94
Copy link
Contributor

Just want to check, the purpose here is quick performance checks on ALTS internals?

@kevinGC
Copy link
Contributor Author

kevinGC commented Oct 13, 2025

Yep, just ALTS internals. This is helpful for benchmarking performance changes, and I've been using it for looking at throughput + memory allocation behavior. I find it useful, and it'd be a lot easier for me to have it upstreamed here. But no offense if the project would rather not add it -- I can live with that.

@gtcooke94 gtcooke94 requested a review from rockspore October 13, 2025 20:13
This has been useful to me for quick testing to see whether changes are
performant. Compared to other benchmarks in record_test, this:

- Exercises TCP, which is more realistic than byte.Buffer
- Runs the reader and writer in parallel rather than sequentually

Since it only runs locally, it can be run easily. For example:

```
$ go test -run="^$" -bench="BenchmarkTCP" ./credentials/alts/internal/conn
goos: linux
goarch: amd64
pkg: google.golang.org/grpc/credentials/alts/internal/conn
cpu: AMD Ryzen Threadripper PRO 3945WX 12-Cores
BenchmarkTCP/size=1_KiB-12                   100          10058898 ns/op                 0 Mbps         97.34 cpu-usec/op               97.34 sys-usec/op                0 usr-usec/op
BenchmarkTCP/size=4_KiB-12                   100          10069605 ns/op                 2.979 Mbps            146.2 cpu-usec/op               104.7 sys-usec/op                41.42 usr-usec/op
BenchmarkTCP/size=64_KiB-12                  100          10510067 ns/op                47.57 Mbps            1116 cpu-usec/op         859.7 sys-usec/op               256.7 usr-usec/op
BenchmarkTCP/size=512_KiB-12                 100          13707500 ns/op               291.8 Mbps             8167 cpu-usec/op        6872 sys-usec/op        1295 usr-usec/op
BenchmarkTCP/size=1_MiB-12                   100          17343824 ns/op               461.3 Mbps            16276 cpu-usec/op       13361 sys-usec/op        2915 usr-usec/op
BenchmarkTCP/size=4_MiB-12                    32          39019702 ns/op               820.1 Mbps            64387 cpu-usec/op       51945 sys-usec/op       12443 usr-usec/op
PASS
ok      google.golang.org/grpc/credentials/alts/internal/conn   7.487s
```
@easwars
Copy link
Contributor

easwars commented Oct 16, 2025

@gtcooke94 : Looks like this is good for another pass.

@easwars easwars assigned easwars and unassigned gtcooke94 Oct 27, 2025
}

// newTCPConnPair returns a pair of conns backed by TCP over loopback.
func newTCPConnPair(rp string, clientProtected []byte, serverProtected []byte) (*conn, *conn, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that this function is intended to only be used from the newly added benchmark, you could consider making it a helper function by passing testing.B as the first parameter and calling b.Helper().

Also, please consider replacing calls to panic with calls to b.Fatal or b.Fatalf.

}

// newTCPConnPair returns a pair of conns backed by TCP over loopback.
func newTCPConnPair(rp string, clientProtected []byte, serverProtected []byte) (*conn, *conn, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Please consider replacing rp with recordProtocol as really short variable names make more sense where the scope of the variable is much smaller. This seems to be a reasonable large function, and rp is used way down below.

Also, clientProtected []byte, serverProtected []byte could be shortened as clientProtected, serverProtected []byte


func benchmarkTCP(b *testing.B, size int) {
// Initialize the connection.
client, server, err := newTCPConnPair(rekeyRecordProtocol, nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the last two arguments are always expected to be nil, we could remove those parameters and pass nil to NewConn from newTCPConnPair.

<-listenChan
clientTCP, err := net.DialTimeout("tcp4", address, 5*time.Second)
if err != nil {
return nil, nil, fmt.Errorf("failed to Dial: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

These calls to fmt.Errorf could also be replaced with calls to b.Fatalf and remove the error return value from this function. So, the caller of this function will not have to handle the error and call b.Fatal.


// Get the ending rusage.
var endUsage unix.Rusage
if err := unix.Getrusage(unix.RUSAGE_SELF, &endUsage); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to use more portable alternatives. The sys/unix package will probably only build on unix and unix-like systems.

Options that I see are:

@easwars easwars assigned kevinGC and unassigned easwars Oct 27, 2025
@easwars easwars changed the title add simple TCP-based ALTS benchmark credentials/alts: add simple TCP-based ALTS benchmark Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. Status: Requires Reporter Clarification Type: Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants