-
Notifications
You must be signed in to change notification settings - Fork 895
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-3090 Optimize logging truncation for large documents #1699
GODRIVER-3090 Optimize logging truncation for large documents #1699
Conversation
Still looking for additional ways of optimizing |
API Change Report./x/bsonx/bsoncorecompatible changesArray.StringN: added |
db567c8
to
9ac506c
Compare
cd8abc2
to
8b0fffb
Compare
2a5d78b
to
b5594d4
Compare
3e03205
to
404a0ba
Compare
c03274a
to
4d09943
Compare
2c91ade
to
cea0ce1
Compare
f203bd9
to
3f451a2
Compare
92fc4a1
to
ece7e4b
Compare
a00bdfb
to
e976b8d
Compare
1378066
to
81feb4f
Compare
706f85d
to
16e33d4
Compare
328046a
to
7efcb73
Compare
f8d970a
to
bcfa73a
Compare
960d045
to
33fe16e
Compare
if buf.Len() == n { | ||
return buf.String() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addition of this code, fixed a bug that was making truncation 11 instead of the length of 10 in one of the test cases.
It also improved the benchmarking speed of truncating massive arrays.
Before Change-
BenchmarkRawString/massive_arrays_StringN-10 642 1860169 ns/op 632576 B/op 411 allocs/op
After Change-
BenchmarkRawString/massive_arrays_StringN-10 105404 10738 ns/op 15744 B/op 396 allocs/op
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @timothy-kim-mongo 🔧 . If you replace the _StringN
benchmarks with the old solution:
str := bsoncore.Document(bs).String()
bsoncoreutil.Truncate(str, 1024)
and report allocations, you get a 3000x allocation improvement!
BenchmarkRawString/massive_arrays_StringN-10_old 39 31489319 ns/op 60814318 B/op 1200137 allocs/op
BenchmarkRawString/massive_arrays_StringN-10 117501 10122 ns/op 15744 B/op 396 allocs/op
565c053
to
64959f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
GODRIVER-3090
Summary
The goal of this pull request is to optimize the logging truncation process for large documents in the Go Driver. This optimization aims to improve driver performance when handling and truncating large extensive BSON documents and payloads, specifically addressing issues related to logging large documents, which can adversely affect driver performance and can cause resource containment and are critical for maintaining application performance and operational efficiency.
Key changes introduced include the implementation of a StringN method for bsoncore.Document. This method allows BSON documents to be stringified up to a specified byte limit (N), incorporating precise truncation logic that accounts for multi-byte characters. By leveraging the existing logging truncation algorithm, the method ensures accurate and efficient handling of BSON documents in extended JSON format, thereby maintaining data integrity and aligning with BSON specifications.
Furthermore, the pull request updates various BSON element string methods (Array.StringN, Value.StringN, etc.) to utilize the new StringN functionality. This ensures consistent and optimized truncation across different BSON element types, such as arrays and nested documents, when exceeding specified byte limits. Comprehensive unit tests and benchmark tests accompany these changes, validating the performance improvements in terms of reduced execution time (ns/op), decreased memory allocations (B/op), and enhanced efficiency in handling large BSON payloads.
Therefore, this pull request significantly improves driver performance by optimizing BSON document truncation for logging purposes. It addresses scalability challenges and enhances the reliability of the MongoDB Go Driver in handling large BSON payloads, thereby benefiting applications with critical logging and operational needs.