Skip to content

Instantly share code, notes, and snippets.

@brantburnett
Created October 22, 2024 21:42
Show Gist options
  • Save brantburnett/1496880160fb9ec1ab9ecb756eddef23 to your computer and use it in GitHub Desktop.
Save brantburnett/1496880160fb9ec1ab9ecb756eddef23 to your computer and use it in GitHub Desktop.
Recent Couchbase .NET SDK Improvements for Documentation

ExcludeLegacyMetrics

https://github.com/couchbase/couchbase-net-client/commit/ef52763720ea9f92aa449a2fdbed7206181086ec

Recent improvements to the tagging of metrics produced by Couchbase.Extensions.Tracing.Otel have caused some of the preexisting metrics to be duplicative.

  • db.couchbase.operations.count is included in the db.couchbase.operations histogram
  • db.couchbase.operations.status is now available on the db.couchbase.operations histogram via the outcome tag
  • db.couchbase.timeouts is now available on the db.couchbase.operations histogram via the outcome tag as AmbiguousTimeout and UnambiguousTimeout

To reduce costs, these metrics may be excluded when adding Couchbase instrumentation to the OpenTelemetry metrics builder.

metricsBuilder.AddCouchbaseInstrumentation(options =>
{
    options.ExcludeLegacyMetrics = true;
}

ReadOnlyMemory Transcoding

Previous work was done on RawBinaryTranscoder to support more efficient use of memory buffers. When performing mutations, the binary data may be supplied using a Memory<byte> or ReadOnlyMemory<byte> rather than a byte[], which may be acquired from the ArrayPool and sliced. For decoding, you may request ContentAs<IMemoryOwner<byte>> to get the content using a buffer from the ArrayPool (it's important for the consumer to Dispose this buffer when done to return it to the pool).

Existing Documentation: https://docs.couchbase.com/dotnet-sdk/current/howtos/transcoders-nonjson.html#rawbinarytranscoder

This support has now been extended to the RawJsonTranscoder for cases where the consumer is serializing/deserializing their own JSON via: https://github.com/couchbase/couchbase-net-client/commit/13b2d7a0914c30e6069d55ae73164c107d09e8ef

IMutateInResult and ILookupInResult Dispose

https://github.com/couchbase/couchbase-net-client/commit/3a7ac880ab9533a30454e653e3903986c4733c4c

Returned IMutateInResult and ILookupInResult values are now disposable. It is important for consumers to dispose of these or there may be GC-related performance penalties, especially under load. All examples should be updated to show a Dispose or using statement.

The penalty is related to GC generations. Both of these types gain some significant performance an heap allocation gains by sharing buffers from the ArrayPool rather than making byte[] copies for each operation. However, this means that they may receive an older backing array from the pool that lives in the Gen2 heap. Failure to Dispose, returning the array to the pool, means that it will eventually be garbage collected, but not until the next Gen2 garbage collection cycle. This cycle is rare and expensive, and the increased memory pressure from other operations not having access to buffers not returned to the pool may cause it to occur more often. It may also increase the overall memory footprint under load.

In Flight Operation Limit

https://github.com/couchbase/couchbase-net-client/commit/130bd69e6183fbfd07e63a0bc1f947521e3c89b4 https://github.com/couchbase/couchbase-net-client/commit/c090e626724e13faca67bfc592dfe638e45319c2

In flight operation limits provide backpressure to connections, especially in the case of large numbers of small GET requests with large response bodies. It ensures that no single TCP connection has too many operations in flight at once. When there is too much pressure on connections to a single node, the connection autoscaler may then recognize this an add more connections up to MaxKvConnections. The value currently defaults to 16 but may be adjusted via TuningOptions. This is most likely to be necessary on high latency connections, such as remote connections to Capella from other regions or the edge.

Keyed Dependency Injection

https://github.com/couchbase/couchbase-net-client/commit/7df255e6d63eb7d6d3b434bf46df7d3246c88af0

Coming soon...

Named Interface Dependency Injection Without Dynamic Type Generation

https://github.com/couchbase/couchbase-net-client/commit/0952119a800f47e225fe31055db7ddeb8c2e1561

Coming soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment