Use nano::transport::traffic_type for bandwidth limiter selection
This commit is contained in:
parent
7eb72ccd46
commit
4d5664a1e1
4 changed files with 15 additions and 43 deletions
|
|
@ -7,49 +7,35 @@
|
||||||
|
|
||||||
nano::bandwidth_limiter::bandwidth_limiter (nano::bandwidth_limiter::config config_a) :
|
nano::bandwidth_limiter::bandwidth_limiter (nano::bandwidth_limiter::config config_a) :
|
||||||
config_m{ config_a },
|
config_m{ config_a },
|
||||||
limiter_standard (config_m.standard_limit, config_m.standard_burst_ratio),
|
limiter_generic{ config_m.standard_limit, config_m.standard_burst_ratio },
|
||||||
limiter_bootstrap{ config_m.bootstrap_limit, config_m.bootstrap_burst_ratio }
|
limiter_bootstrap{ config_m.bootstrap_limit, config_m.bootstrap_burst_ratio }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::rate_limiter & nano::bandwidth_limiter::select_limiter (nano::bandwidth_limit_type type)
|
nano::rate_limiter & nano::bandwidth_limiter::select_limiter (nano::transport::traffic_type type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case bandwidth_limit_type::bootstrap:
|
case nano::transport::traffic_type::bootstrap:
|
||||||
return limiter_bootstrap;
|
return limiter_bootstrap;
|
||||||
case bandwidth_limit_type::standard:
|
case nano::transport::traffic_type::generic:
|
||||||
|
return limiter_generic;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debug_assert (false);
|
debug_assert (false, "missing traffic type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return limiter_standard;
|
return limiter_generic;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nano::bandwidth_limiter::should_pass (std::size_t buffer_size, nano::bandwidth_limit_type type)
|
bool nano::bandwidth_limiter::should_pass (std::size_t buffer_size, nano::transport::traffic_type type)
|
||||||
{
|
{
|
||||||
auto & limiter = select_limiter (type);
|
auto & limiter = select_limiter (type);
|
||||||
return limiter.should_pass (buffer_size);
|
return limiter.should_pass (buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::bandwidth_limit_type type)
|
void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::transport::traffic_type type)
|
||||||
{
|
{
|
||||||
auto & limiter = select_limiter (type);
|
auto & limiter = select_limiter (type);
|
||||||
limiter.reset (limit, burst_ratio);
|
limiter.reset (limit, burst_ratio);
|
||||||
}
|
|
||||||
|
|
||||||
nano::bandwidth_limit_type nano::to_bandwidth_limit_type (const nano::transport::traffic_type & traffic_type)
|
|
||||||
{
|
|
||||||
switch (traffic_type)
|
|
||||||
{
|
|
||||||
case nano::transport::traffic_type::generic:
|
|
||||||
return nano::bandwidth_limit_type::standard;
|
|
||||||
break;
|
|
||||||
case nano::transport::traffic_type::bootstrap:
|
|
||||||
return nano::bandwidth_limit_type::bootstrap;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
debug_assert (false);
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,19 +5,6 @@
|
||||||
|
|
||||||
namespace nano
|
namespace nano
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Enumeration for different bandwidth limits for different traffic types
|
|
||||||
*/
|
|
||||||
enum class bandwidth_limit_type
|
|
||||||
{
|
|
||||||
/** For all message */
|
|
||||||
standard,
|
|
||||||
/** For bootstrap (asc_pull_ack, asc_pull_req) traffic */
|
|
||||||
bootstrap
|
|
||||||
};
|
|
||||||
|
|
||||||
nano::bandwidth_limit_type to_bandwidth_limit_type (nano::transport::traffic_type const &);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that tracks and manages bandwidth limits for IO operations
|
* Class that tracks and manages bandwidth limits for IO operations
|
||||||
*/
|
*/
|
||||||
|
|
@ -41,23 +28,23 @@ public:
|
||||||
* Check whether packet falls withing bandwidth limits and should be allowed
|
* Check whether packet falls withing bandwidth limits and should be allowed
|
||||||
* @return true if OK, false if needs to be dropped
|
* @return true if OK, false if needs to be dropped
|
||||||
*/
|
*/
|
||||||
bool should_pass (std::size_t buffer_size, bandwidth_limit_type);
|
bool should_pass (std::size_t buffer_size, nano::transport::traffic_type type);
|
||||||
/**
|
/**
|
||||||
* Reset limits of selected limiter type to values passed in arguments
|
* Reset limits of selected limiter type to values passed in arguments
|
||||||
*/
|
*/
|
||||||
void reset (std::size_t limit, double burst_ratio, bandwidth_limit_type = bandwidth_limit_type::standard);
|
void reset (std::size_t limit, double burst_ratio, nano::transport::traffic_type type = nano::transport::traffic_type::generic);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Returns reference to limiter corresponding to the limit type
|
* Returns reference to limiter corresponding to the limit type
|
||||||
*/
|
*/
|
||||||
nano::rate_limiter & select_limiter (bandwidth_limit_type);
|
nano::rate_limiter & select_limiter (nano::transport::traffic_type type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const config config_m;
|
const config config_m;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nano::rate_limiter limiter_standard;
|
nano::rate_limiter limiter_generic;
|
||||||
nano::rate_limiter limiter_bootstrap;
|
nano::rate_limiter limiter_bootstrap;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ void nano::transport::channel::send (nano::message & message_a, std::function<vo
|
||||||
auto buffer = message_a.to_shared_const_buffer ();
|
auto buffer = message_a.to_shared_const_buffer ();
|
||||||
|
|
||||||
bool is_droppable_by_limiter = (drop_policy_a == nano::transport::buffer_drop_policy::limiter);
|
bool is_droppable_by_limiter = (drop_policy_a == nano::transport::buffer_drop_policy::limiter);
|
||||||
bool should_pass = node.outbound_limiter.should_pass (buffer.size (), to_bandwidth_limit_type (traffic_type));
|
bool should_pass = node.outbound_limiter.should_pass (buffer.size (), traffic_type);
|
||||||
bool pass = !is_droppable_by_limiter || should_pass;
|
bool pass = !is_droppable_by_limiter || should_pass;
|
||||||
|
|
||||||
node.stats.inc (pass ? nano::stat::type::message : nano::stat::type::drop, to_stat_detail (message_a.type ()), nano::stat::dir::out, /* aggregate all */ true);
|
node.stats.inc (pass ? nano::stat::type::message : nano::stat::type::drop, to_stat_detail (message_a.type ()), nano::stat::dir::out, /* aggregate all */ true);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ namespace nano::transport
|
||||||
enum class traffic_type
|
enum class traffic_type
|
||||||
{
|
{
|
||||||
generic,
|
generic,
|
||||||
/** For bootstrap (asc_pull_ack, asc_pull_req) traffic */
|
bootstrap, // Ascending bootstrap (asc_pull_ack, asc_pull_req) traffic
|
||||||
bootstrap
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue