Skip to content

Commit

Permalink
Cherry-pick to stable-23-3: [Filestore] add UncompressedBytesWritten,…
Browse files Browse the repository at this point in the history
… CompressedBytesWritten counters to metrics (#1718) (#1727)
  • Loading branch information
SvartMetal authored Aug 6, 2024
1 parent 22f17c4 commit 067d486
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cloud/filestore/config/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,8 @@ message TStorageConfig
// Enables usage of GetNodeAttrBatch requests instead of GetNodeAttr when
// appropriate.
optional bool GetNodeAttrBatchEnabled = 358;

// Blob compression experiment params.
optional uint32 BlobCompressionRate = 364;
optional string BlobCompressionCodec = 365;
}
2 changes: 2 additions & 0 deletions cloud/filestore/libs/storage/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ namespace {
xxx(MultiTabletForwardingEnabled, bool, false )\
xxx(GetNodeAttrBatchEnabled, bool, false )\
xxx(AllowFileStoreForceDestroy, bool, false )\
xxx(BlobCompressionRate, ui32, 0 )\
xxx(BlobCompressionCodec, TString, "lz4" )\
// FILESTORE_STORAGE_CONFIG

#define FILESTORE_DECLARE_CONFIG(name, type, value) \
Expand Down
3 changes: 3 additions & 0 deletions cloud/filestore/libs/storage/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ class TStorageConfig
void DumpHtml(IOutputStream& out) const;
void DumpOverridesHtml(IOutputStream& out) const;

ui32 GetBlobCompressionRate() const;
TString GetBlobCompressionCodec() const;

const NProto::TStorageConfig& GetStorageConfigProto() const;
};

Expand Down
1 change: 1 addition & 0 deletions cloud/filestore/libs/storage/tablet/tablet_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TIndexTabletActor::TIndexTabletActor(
)
, Config(std::move(config))
, UseNoneCompactionPolicy(useNoneCompactionPolicy)
, BlobCodec(NBlockCodecs::Codec(Config->GetBlobCompressionCodec()))
{
UpdateLogTag();
}
Expand Down
13 changes: 13 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@

#include <atomic>

namespace NBlockCodecs {

////////////////////////////////////////////////////////////////////////////////

struct ICodec;

} // namespace NBlockCodecs

namespace NCloud::NFileStore::NStorage {

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -126,6 +134,9 @@ class TIndexTabletActor final
std::atomic<i64> IdleTime{0};
TBusyIdleTimeCalculatorAtomics BusyIdleCalc;

std::atomic<i64> UncompressedBytesWritten{0};
std::atomic<i64> CompressedBytesWritten{0};

NMetrics::TDefaultWindowCalculator MaxUsedQuota{0};
using TLatHistogram =
NMetrics::THistogram<NMetrics::EHistUnit::HU_TIME_MICROSECONDS>;
Expand Down Expand Up @@ -244,6 +255,8 @@ class TIndexTabletActor final

ui32 BackpressureErrorCount = 0;

const NBlockCodecs::ICodec* BlobCodec;

public:
TIndexTabletActor(
const NActors::TActorId& owner,
Expand Down
7 changes: 7 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_actor_counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ void TIndexTabletActor::TMetrics::Register(
FsRegistry,
{CreateLabel("request", "WriteData"), CreateLabel("histogram", "ThrottlerDelay")});

REGISTER_AGGREGATABLE_SUM(
UncompressedBytesWritten,
EMetricType::MT_DERIVATIVE);
REGISTER_AGGREGATABLE_SUM(
CompressedBytesWritten,
EMetricType::MT_DERIVATIVE);

#define REGISTER_REQUEST(name) \
REGISTER_AGGREGATABLE_SUM( \
name.Count, \
Expand Down
16 changes: 16 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_actor_writeblob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ void TIndexTabletActor::HandleWriteBlob(
return;
}

const auto compRate = Config->GetBlobCompressionRate();
if (BlobCodec && compRate && blob.BlobId.GetHash() % compRate == 0) {
TString out;
out.ReserveAndResize(
BlobCodec->MaxCompressedLength(blob.BlobContent));
const size_t sz = BlobCodec->Compress(
blob.BlobContent,
out.begin());
Metrics.UncompressedBytesWritten.fetch_add(
blob.BlobContent.Size(),
std::memory_order_relaxed);
Metrics.CompressedBytesWritten.fetch_add(
sz,
std::memory_order_relaxed);
}

auto blobId = MakeBlobId(TabletID(), blob.BlobId);

auto proxy = Info()->BSProxyIDForChannel(
Expand Down
83 changes: 83 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_ut_counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,89 @@ Y_UNIT_TEST_SUITE(TIndexTabletTest_Counters)

UNIT_ASSERT_DOUBLES_EQUAL(sz, (network * reportInterval), sz / 100);
}

Y_UNIT_TEST(ShouldReportCompressionMetrics)
{
NProto::TStorageConfig storageConfig;
storageConfig.SetBlobCompressionRate(1);
storageConfig.SetWriteBlobThreshold(1);

TTestEnv env({}, std::move(storageConfig));
auto registry = env.GetRegistry();

env.CreateSubDomain("nfs");
ui32 nodeIdx = env.CreateNode("nfs");
ui64 tabletId = env.BootIndexTablet(nodeIdx);

TIndexTabletClient tablet(env.GetRuntime(), nodeIdx, tabletId);
tablet.InitSession("client", "session");
const auto nodeId =
CreateNode(tablet, TCreateNodeArgs::File(RootNodeId, "test"));
const auto handle = CreateHandle(tablet, nodeId);

tablet.WriteData(handle, 0, 4_KB, 'a');

TTestRegistryVisitor visitor;
registry->Visit(TInstant::Zero(), visitor);
visitor.ValidateExpectedCounters({
{
{
{"sensor", "UncompressedBytesWritten"},
{"filesystem", "test"}
},
4_KB // expected
},
{
{
{"sensor", "CompressedBytesWritten"},
{"filesystem", "test"}
},
34 // expected
},
});
}

Y_UNIT_TEST(ShouldNotReportCompressionMetricsForAllBlobs)
{
NProto::TStorageConfig storageConfig;
storageConfig.SetBlobCompressionRate(2);
storageConfig.SetWriteBlobThreshold(1);

TTestEnv env({}, std::move(storageConfig));
auto registry = env.GetRegistry();

env.CreateSubDomain("nfs");
ui32 nodeIdx = env.CreateNode("nfs");
ui64 tabletId = env.BootIndexTablet(nodeIdx);

TIndexTabletClient tablet(env.GetRuntime(), nodeIdx, tabletId);
tablet.InitSession("client", "session");
const auto nodeId =
CreateNode(tablet, TCreateNodeArgs::File(RootNodeId, "test"));
const auto handle = CreateHandle(tablet, nodeId);

for (int i = 0; i < 10; i++)
tablet.WriteData(handle, 0, 4_KB, 'a');

TTestRegistryVisitor visitor;
registry->Visit(TInstant::Zero(), visitor);
visitor.ValidateExpectedCountersWithPredicate({
{
{
{"sensor", "UncompressedBytesWritten"},
{"filesystem", "test"}
},
[](i64 val) { return val > 0 && val < 40960; } // expected
},
{
{
{"sensor", "CompressedBytesWritten"},
{"filesystem", "test"},
},
[](i64 val) { return val > 0 && val < 370; } // expected
},
});
}
}

} // namespace NCloud::NFileStore::NStorage
19 changes: 19 additions & 0 deletions cloud/filestore/libs/storage/testlib/test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,25 @@ void TTestRegistryVisitor::ValidateExpectedCounters(
}
}

void TTestRegistryVisitor::ValidateExpectedCountersWithPredicate(
const TVector<
std::pair<TVector<TLabel>, std::function<bool(i64)>>
>& expectedCounters)
{
for (const auto& [labels, predicate]: expectedCounters) {
const auto labelsStr = LabelsToString(labels);

int matchingCountersCount = 0;
for (const auto& entry: MetricsEntries) {
if (entry.Matches(labels)) {
++matchingCountersCount;
UNIT_ASSERT(predicate(entry.Value));
}
}
UNIT_ASSERT_VALUES_EQUAL_C(matchingCountersCount, 1, labelsStr);
}
}

void TTestRegistryVisitor::ValidateExpectedHistogram(
const TVector<std::pair<TVector<TLabel>, i64>>& expectedCounters,
bool checkEqual)
Expand Down
6 changes: 6 additions & 0 deletions cloud/filestore/libs/storage/testlib/test_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <util/generic/string.h>

#include <functional>

namespace NCloud::NFileStore::NStorage {

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -204,6 +206,10 @@ class TTestRegistryVisitor
const TVector<TMetricsEntry>& GetEntries() const;
void ValidateExpectedCounters(
const TVector<std::pair<TVector<TLabel>, i64>>& expectedCounters);
void ValidateExpectedCountersWithPredicate(
const TVector<
std::pair<TVector<TLabel>, std::function<bool(i64)>>
>& expectedCounters);
void ValidateExpectedHistogram(
const TVector<std::pair<TVector<TLabel>, i64>>& expectedCounters,
bool checkEqual);
Expand Down

0 comments on commit 067d486

Please sign in to comment.