Skip to content

Commit

Permalink
Configs for direct copy throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
drbasic committed Jan 20, 2025
1 parent 6d531ee commit 20281ad
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 32 deletions.
19 changes: 19 additions & 0 deletions cloud/blockstore/config/disk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ message TStorageDiscoveryConfig

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

message TDiskAgentThrottlingConfig
{
// Host limits.
optional string InfraThrottlingConfigPath = 1;
optional uint32 DefaultNetworkMbitThroughput = 2;

// Fraction of network throughput utilized for migrations and shadow
// disk fill.
optional double DirectCopyBandwidthFraction = 3;

// Maximum bandwidth for one device in MiB/s.
optional uint64 MaxDeviceBandwidthMiB = 4;
}

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

message TDiskAgentConfig
{
optional bool Enabled = 1;
Expand Down Expand Up @@ -275,6 +291,9 @@ message TDiskAgentConfig
}

repeated TPathToSerialNumber PathToSerialNumberMapping = 37;

// Settings for traffic shaping.
optional TDiskAgentThrottlingConfig ThrottlingConfig = 38;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 0 additions & 4 deletions cloud/blockstore/config/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,4 @@ message TStorageServiceConfig

// Enable buttons for device state changing, when they in error state.
optional bool EnableToChangeErrorStatesFromDiskRegistryMonpage = 398;

// Fraction of network throughput utilized for migrations and shadow
// disk fill.
optional double DirectCopyBandwidthFraction = 399;
}
1 change: 1 addition & 0 deletions cloud/blockstore/libs/disk_agent/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ void TBootstrap::InitRdmaServer(NRdma::TRdmaConfig& config)

bool TBootstrap::InitKikimrService()
{
Configs->Log = Log;
Configs->InitKikimrConfig();
Configs->InitServerConfig();
Configs->InitFeaturesConfig();
Expand Down
58 changes: 51 additions & 7 deletions cloud/blockstore/libs/disk_agent/config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include <cloud/blockstore/libs/spdk/iface/config.h>
#include <cloud/blockstore/libs/storage/core/config.h>
#include <cloud/blockstore/libs/storage/disk_registry_proxy/model/config.h>

#include <cloud/storage/core/libs/common/proto_helpers.h>
#include <cloud/storage/core/libs/features/features_config.h>
#include <cloud/storage/core/libs/kikimr/actorsystem.h>
#include <cloud/storage/core/libs/version/version.h>

#include <library/cpp/json/json_reader.h>
#include <library/cpp/protobuf/util/pb_io.h>

#include <util/datetime/base.h>
Expand All @@ -23,8 +23,54 @@

namespace NCloud::NBlockStore::NServer {

namespace {

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

std::optional<NJson::TJsonValue> ReadJsonFile(
TLog& Log,
const TString& filename)
{
if (filename.empty()) {
return {};
}

try {
TFileInput in(filename);
return NJson::ReadJsonTree(&in, true);
} catch (...) {
STORAGE_ERROR(
"Failed to read file: " << filename.Quote() << " with error: "
<< CurrentExceptionMessage().c_str());
return {};
}
}

ui32 ReadNetworkMbitThroughput(
TLog& Log,
const NProto::TDiskAgentConfig& diskAgentConfig)
{
const auto& config = diskAgentConfig.GetThrottlingConfig();
ui32 networkThroughput = config.GetDefaultNetworkMbitThroughput();

if (auto json = ReadJsonFile(Log, config.GetInfraThrottlingConfigPath())) {
try {
if (auto* value = json->GetValueByPath("interfaces.[0].eth0.speed"))
{
networkThroughput = FromString<ui64>(value->GetStringSafe());
}
} catch (...) {
STORAGE_ERROR(
"Failed to read NetworkMbitThroughput. Error: "
<< CurrentExceptionMessage().c_str());
}
}

return networkThroughput;
}

} // namespace

void TConfigInitializer::ApplyCMSConfigs(NKikimrConfig::TAppConfig cmsConfig)
{
if (cmsConfig.HasBlobStorageConfig()) {
Expand Down Expand Up @@ -167,10 +213,11 @@ void TConfigInitializer::InitDiskAgentConfig()
SetupDiskAgentConfig(diskAgentConfig);
ApplySpdkEnvConfig(diskAgentConfig.GetSpdkEnvConfig());

const ui32 networkMbitThroughput = ReadNetworkMbitThroughput(Log, diskAgentConfig);
DiskAgentConfig = std::make_shared<NStorage::TDiskAgentConfig>(
std::move(diskAgentConfig),
Rack,
NetworkMbitThroughput);
networkMbitThroughput);
}

void TConfigInitializer::InitDiskRegistryProxyConfig()
Expand All @@ -184,10 +231,6 @@ void TConfigInitializer::InitDiskRegistryProxyConfig()
std::move(config));
}

void TConfigInitializer::InitNetworkThroughput() {

}

void TConfigInitializer::InitServerConfig()
{
NProto::TServerAppConfig appConfig;
Expand Down Expand Up @@ -432,10 +475,11 @@ void TConfigInitializer::ApplyDiskAgentConfig(const TString& text)
DiskAgentConfig->GetStorageDiscoveryConfig());
}

const ui32 networkMbitThroughput = ReadNetworkMbitThroughput(Log, config);
DiskAgentConfig = std::make_shared<NStorage::TDiskAgentConfig>(
std::move(config),
Rack,
NetworkMbitThroughput);
networkMbitThroughput);
}

void TConfigInitializer::ApplyDiskRegistryProxyConfig(const TString& text)
Expand Down
5 changes: 3 additions & 2 deletions cloud/blockstore/libs/disk_agent/config_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <contrib/ydb/core/protos/blobstorage.pb.h>
#include <contrib/ydb/core/protos/config.pb.h>

#include <library/cpp/logger/log.h>

namespace NCloud::NBlockStore::NServer {

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -35,10 +37,10 @@ struct TConfigInitializer
TDiagnosticsConfigPtr DiagnosticsConfig;
NSpdk::TSpdkEnvConfigPtr SpdkEnvConfig;
NFeatures::TFeaturesConfigPtr FeaturesConfig;
ui32 NetworkMbitThroughput = 0;
NRdma::TRdmaConfigPtr RdmaConfig;

TString Rack;
TLog Log;

TConfigInitializer(TOptionsPtr options)
: Options(std::move(options))
Expand All @@ -52,7 +54,6 @@ struct TConfigInitializer
void InitStorageConfig();
void InitDiskAgentConfig();
void InitDiskRegistryProxyConfig();
void InitNetworkThroughput();
void InitServerConfig();
void InitSpdkEnvConfig();
void InitFeaturesConfig();
Expand Down
1 change: 0 additions & 1 deletion cloud/blockstore/libs/storage/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ TDuration MSeconds(ui32 value)
xxx(VolumeProxyCacheRetryDuration, TDuration, Seconds(15) )\
\
xxx(UseDirectCopyRange, bool, false )\
xxx(DirectCopyBandwidthFraction, double, 0.5 )\
xxx(MaxShadowDiskFillBandwidth, ui32, 512 )\
xxx(MaxShadowDiskFillIoDepth, ui32, 1 )\
xxx(BackgroundOperationsTotalBandwidth, ui32, 1024 )\
Expand Down
1 change: 0 additions & 1 deletion cloud/blockstore/libs/storage/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ class TStorageConfig
TString GetCachedDiskAgentSessionsPath() const;

bool GetUseDirectCopyRange() const;
double GetDirectCopyBandwidthFraction() const;
ui32 GetMaxShadowDiskFillBandwidth() const;
ui32 GetMaxShadowDiskFillIoDepth() const;
ui32 GetBackgroundOperationsTotalBandwidth() const;
Expand Down
7 changes: 0 additions & 7 deletions cloud/blockstore/libs/storage/disk_agent/disk_agent_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ namespace {

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

ui64 GetNetworkBandwidth(ui32 networkMbitThroughput, double directCopyBandwidthFraction) {
return (static_cast<ui64>(networkMbitThroughput) * 1_MB / 8) *
directCopyBandwidthFraction;
}

} // namespace

Expand All @@ -51,9 +47,6 @@ TDiskAgentActor::TDiskAgentActor(
, Logging(std::move(logging))
, RdmaServer(std::move(rdmaServer))
, NvmeManager(std::move(nvmeManager))
, BandwidthCalculator(
GetNetworkBandwidth(AgentConfig->GetNetworkMbitThroughput(),
Config->GetDirectCopyBandwidthFraction()))
{}

TDiskAgentActor::~TDiskAgentActor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TDiskAgentActor final
// Pending WaitReady requests
TDeque<TPendingRequest> PendingRequests;

TBandwidthCalculator BandwidthCalculator;
TBandwidthCalculator BandwidthCalculator {*AgentConfig};

ERegistrationState RegistrationState = ERegistrationState::NotStarted;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#include "bandwidth_calculator.h"

#include <cloud/blockstore/libs/storage/disk_agent/model/config.h>

namespace NCloud::NBlockStore::NStorage {

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

namespace {

constexpr auto WindowDuration = TDuration::Seconds(1);

TBandwidthCalculator::TBandwidthCalculator(ui64 maxTotalBandwidth)
: MaxTotalBandwidth(maxTotalBandwidth)
ui64 GetNetworkBandwidth(const TDiskAgentConfig& config)
{
return (static_cast<ui64>(config.GetNetworkMbitThroughput()) * 1_MB / 8) *
config.GetThrottlerConfig().GetDirectCopyBandwidthFraction();
}

} // namespace

TBandwidthCalculator::TBandwidthCalculator(const TDiskAgentConfig& config)
: MaxTotalBandwidth(GetNetworkBandwidth(config))
, MaxDeviceBandwidth(
config.GetThrottlerConfig().GetMaxDeviceBandwidthMiB() * 1_MB)
{}

TBandwidthCalculator::~TBandwidthCalculator() = default;
Expand All @@ -34,7 +48,11 @@ void TBandwidthCalculator::ClearHistory(TInstant deadline)

ui64 TBandwidthCalculator::GetRecommendedBandwidth() const
{
return MaxTotalBandwidth / DeviceLastRequest.size();
ui64 result = MaxTotalBandwidth / DeviceLastRequest.size();
if (MaxDeviceBandwidth) {
result = Min(MaxDeviceBandwidth, result);
}
return result;
}

} // namespace NCloud::NBlockStore::NStorage
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <cloud/blockstore/libs/storage/disk_agent/model/public.h>

#include <util/datetime/base.h>
#include <util/generic/hash.h>
#include <util/generic/list.h>
Expand All @@ -11,10 +13,12 @@ namespace NCloud::NBlockStore::NStorage {
class TBandwidthCalculator
{
const ui64 MaxTotalBandwidth;
const ui64 MaxDeviceBandwidth;

THashMap<TString, TInstant> DeviceLastRequest;

public:
explicit TBandwidthCalculator(ui64 maxTotalBandwidth);
explicit TBandwidthCalculator(const TDiskAgentConfig& config);
~TBandwidthCalculator();

// Returns the recommended bandwidth for the next request.
Expand Down
5 changes: 5 additions & 0 deletions cloud/blockstore/libs/storage/disk_agent/model/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class TDiskAgentConfig
return Config.GetPathToSerialNumberMapping();
}

const NProto::TDiskAgentThrottlingConfig& GetThrottlerConfig() const
{
return Config.GetThrottlingConfig();
}

ui32 GetNetworkMbitThroughput() const
{
return NetworkMbitThroughput;
Expand Down
10 changes: 7 additions & 3 deletions cloud/blockstore/libs/storage/disk_agent/spdk_initializer_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ TInitializeSpdkResult InitializeSpdkSync(
NProto::TDiskAgentConfig config)
{
return InitializeSpdk(
std::make_shared<NStorage::TDiskAgentConfig>(std::move(config), "rack"),
std::make_shared<TTestEnv>(),
ICachingAllocatorPtr()).GetValueSync();
std::make_shared<NStorage::TDiskAgentConfig>(
std::move(config),
"rack",
25000),
std::make_shared<TTestEnv>(),
ICachingAllocatorPtr())
.GetValueSync();
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ void TNonreplicatedPartitionMigrationCommonActor::HandleRangeMigrated(
LOG_DEBUG(
ctx,
TBlockStoreComponents::PARTITION,
"[%s] Range %s migrated. Recommended bandwidth: %lu",
"[%s] Range %s migrated. Recommended bandwidth: %.2f MiB",
DiskId.c_str(),
DescribeRange(msg->Range).c_str(),
msg->RecommendedBandwidth);
static_cast<double>(msg->RecommendedBandwidth) / 1_MB);

if (msg->AllZeroes) {
ChangedRangesMap.MarkNotChanged(msg->Range);
Expand Down
14 changes: 14 additions & 0 deletions example/0-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ FileDevices: {
BlockSize: 4096
}
ThrottlingConfig: {
InfraThrottlingConfigPath: "nbs/nbs-throttling.json"
DefaultNetworkMbitThroughput: 100
DirectCopyBandwidthFraction: 0.5
MaxDeviceBandwidthMiB: 15
}
EOF

cat > $BIN_DIR/nbs/nbs-location-$1.txt <<EOF
Expand Down Expand Up @@ -118,6 +125,13 @@ FileDevices: {
BlockSize: 512
PoolName: "local-ssd"
}
ThrottlingConfig: {
InfraThrottlingConfigPath: "nbs/nbs-throttling.json"
DefaultNetworkMbitThroughput: 100
DirectCopyBandwidthFraction: 0.5
}
EOF

cat > $BIN_DIR/nbs/nbs-location-0.txt <<EOF
Expand Down
10 changes: 10 additions & 0 deletions example/nbs/nbs-throttling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compute_cores_num": 16,
"interfaces": [
{
"eth0": {
"speed": "1000"
}
}
]
}

0 comments on commit 20281ad

Please sign in to comment.