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

GODRIVER-2907 Add bulk decryption benchmarks #1806

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

prestonvasquez
Copy link
Collaborator

@prestonvasquez prestonvasquez commented Sep 12, 2024

GODRIVER-2907

Summary

DRIVERS-2581 makes the mongocrypt_binary_t structure public, meaning we can initialize and assign the data and length directly:

mongocryptBinary := C.mongocrypt_binary_new() // Allocate memory 
if mongocryptBinary == nil {
	return nil
}

addr := (*C.uint8_t)(C.CBytes(data))

mongocryptBinary.data = unsafe.Pointer(addr)
mongocryptBinary.len = C.uint32_t(len(data))

Same with accessing the bytes:

C.GoBytes(unsafe.Pointer(b.wrapped.data), C.int(b.wrapped.len))

Initializing directly:

goos: darwin
goarch: arm64
pkg: go.mongodb.org/mongo-driver/v2/x/mongo/driver/mongocrypt
BenchmarkBulkDecryption
BenchmarkBulkDecryption/threadCount=1
BenchmarkBulkDecryption/threadCount=1-10                     536           2238040 ns/op           40984 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=1-10 left GOMAXPROCS set to 1
    binary_test.go:219: thread count: 1, median ops/sec: 447.20
BenchmarkBulkDecryption/threadCount=2
BenchmarkBulkDecryption/threadCount=2-10                    1036           1158261 ns/op           40984 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=2-10 left GOMAXPROCS set to 2
    binary_test.go:219: thread count: 2, median ops/sec: 855.48
BenchmarkBulkDecryption/threadCount=8
BenchmarkBulkDecryption/threadCount=8-10                    3078            377137 ns/op           40984 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=8-10 left GOMAXPROCS set to 8
    binary_test.go:219: thread count: 8, median ops/sec: 2579.93
BenchmarkBulkDecryption/threadCount=64
BenchmarkBulkDecryption/threadCount=64-10                   3235            356146 ns/op           40988 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=64-10 left GOMAXPROCS set to 64
    binary_test.go:219: thread count: 64, median ops/sec: 2718.71
PASS
ok      go.mongodb.org/mongo-driver/v2/x/mongo/driver/mongocrypt        53.710s

Using setter/accessor:

goos: darwin
goarch: arm64
pkg: go.mongodb.org/mongo-driver/v2/x/mongo/driver/mongocrypt
BenchmarkBulkDecryption
BenchmarkBulkDecryption/threadCount=1
BenchmarkBulkDecryption/threadCount=1-10                     541           2221445 ns/op           40984 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=1-10 left GOMAXPROCS set to 1
    binary_test.go:219: thread count: 1, median ops/sec: 449.99
BenchmarkBulkDecryption/threadCount=2
BenchmarkBulkDecryption/threadCount=2-10                    1027           1193342 ns/op           40984 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=2-10 left GOMAXPROCS set to 2
    binary_test.go:219: thread count: 2, median ops/sec: 858.41
BenchmarkBulkDecryption/threadCount=8
BenchmarkBulkDecryption/threadCount=8-10                    3458            332082 ns/op           40984 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=8-10 left GOMAXPROCS set to 8
    binary_test.go:219: thread count: 8, median ops/sec: 1928.17
BenchmarkBulkDecryption/threadCount=64
BenchmarkBulkDecryption/threadCount=64-10                   3604            330883 ns/op           40995 B/op          3 allocs/op
testing: BenchmarkBulkDecryption/threadCount=64-10 left GOMAXPROCS set to 64
    binary_test.go:219: thread count: 64, median ops/sec: 2997.64
PASS
ok      go.mongodb.org/mongo-driver/v2/x/mongo/driver/mongocrypt        53.582s

There does not appear to be extra cost to calling C from Go.

Background & Motivation

Reduce overhead of encryption callbacks by providing bulk-oriented encryption and decryption callbacks

@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Sep 12, 2024
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Sep 12, 2024

API Change Report

No changes found!


b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
decryptDocForBench(b, crypt, encryptedDoc)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't run for the prescribed 1 second because Go benchmarks are designed to automatically determine how long to run a benchmark to achieve stable results. From the docs:

The benchmark function must run the target code b.N times. It is called multiple times with b.N adjusted until the benchmark function lasts long enough to be timed reliably.

kevinAlbs
kevinAlbs previously approved these changes Sep 17, 2024
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM with minor comments.

x/mongo/driver/mongocrypt/binary_test.go Outdated Show resolved Hide resolved
x/mongo/driver/mongocrypt/binary_test.go Outdated Show resolved Hide resolved
x/mongo/driver/mongocrypt/binary_test.go Outdated Show resolved Hide resolved
x/mongo/driver/mongocrypt/binary_test.go Outdated Show resolved Hide resolved
Co-authored-by: Kevin Albertson <kevin.albertson@10gen.com>
Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants