Reduce tds buffer size to match packetsize #584
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We noticed that when connecting to many databases, the amount of memory being utilized by the
newTdsBuffer()
func was rather significant, especially in comparison to the business logic that utilized the connections. I was able to use pprof to figure out that thenewTdsBuffer()
func was the source of the memory utilization and that these 2 buffers get initialized to a fairly large size. This reduces the size of the buffers to match the packetsize, significantly reducing the amount of memory used for the buffers in the majority use case.I added a benchmark in order to help illustrate the difference in utilization before and after. Below are
the results on my machine before and after this change. In the default case (packetSize = 4096) this resulted in a 64% reduction in bytes allocated per operation. This number includes the overall execution and checking of the results as they are inside the benchmark
.Run()
Before:
After:
The tests look good locally after the change except for 2 of the TVP tests, but those also failed before the change so I don't believe this change introduces any regressions there.
The *testing.T pointers have been changed in a few places to the interface testing.TB which both testing.T and testing.B implement to allow for using both.