make performance counters able to blend in values, reducing a peer_connection -> session dependency on a sliding average state (this can be used for disk stats too)

This commit is contained in:
Arvid Norberg 2014-07-29 16:35:03 +00:00
parent 7c9c25e359
commit 02f3e48eaa
6 changed files with 23 additions and 16 deletions

View File

@ -409,12 +409,6 @@ namespace libtorrent
void set_port_filter(port_filter const& f);
port_filter const& get_port_filter() const;
void request_latency_sample(int us)
{
m_request_latency.add_sample(us);
m_stats_counters.set_value(counters::request_latency, m_request_latency.mean());
}
// TODO: move the login info into the tracker_request object
void queue_tracker_request(tracker_request& req
, std::string login, boost::weak_ptr<request_callback> c
@ -1224,10 +1218,6 @@ namespace libtorrent
counters m_stats_counters;
// the sliding average of the latency (in microseconds) from an
// incoming request to sending the data back over the socket
sliding_average<50> m_request_latency;
#ifdef TORRENT_UPNP_LOGGING
std::ofstream m_upnp_log;
#endif

View File

@ -241,8 +241,6 @@ namespace libtorrent { namespace aux
virtual int peak_up_rate() const = 0;
virtual void request_latency_sample(int us) = 0;
enum torrent_list_index
{
// this is the set of (subscribed) torrents that have changed

View File

@ -388,6 +388,7 @@ namespace libtorrent
boost::int64_t operator[](int i) const;
void set_value(int c, boost::int64_t value);
void blend_stats_counter(int c, boost::int64_t value, int ratio);
private:

View File

@ -5189,10 +5189,7 @@ namespace libtorrent
, r.piece, r.start, r.length);
#endif
// TODO: 3 it would be nice if the sliding_average state required
// for this would be baked into the counters object, in which case this
// would not be a session_impl dependency.
m_ses.request_latency_sample(disk_rtt);
m_counters.blend_stats_counter(counters::request_latency, disk_rtt, 5);
// we probably just pulled this piece into the cache.
// if it's rare enough to make it into the suggested piece

View File

@ -71,6 +71,22 @@ namespace libtorrent {
return m_stats_counter[c] += value;
}
// ratio is a vaue between 0 and 100 representing the percentage the value
// is blended in at.
void counters::blend_stats_counter(int c, boost::int64_t value, int ratio)
{
TORRENT_ASSERT(c >= 0);
TORRENT_ASSERT(c < num_counters);
TORRENT_ASSERT(ratio >= 0);
TORRENT_ASSERT(ratio <= 100);
TORRENT_ASSERT(num_stats_counters);
// TODO: 2 to make this thread safe, use compare_exchange_weak
boost::uint64_t current = m_stats_counter[c];
m_stats_counter[c] = (current * (100-ratio) + value * ratio) / 100;
}
void counters::set_value(int c, boost::int64_t value)
{
TORRENT_ASSERT(c >= 0);

View File

@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
// TODO: 3 this function could just use the static metrics array
// instead of taking it as an argument. Also, document it
int find_metric_idx(std::vector<stats_metric> const& metrics
, char const* name)
{
@ -48,6 +50,9 @@ namespace libtorrent
return i->value_index;
}
// TODO: 3 the type of counter does not need to be stored in this array.
// when the user asks for the list of counters, that field could be
// generated based on the range of the counter index.
#define METRIC(category, name, type) { #category "." #name, counters:: name, stats_metric:: type},
const static stats_metric metrics[] =
{