added an option to save a little bit of RAM by not collecting full detailed stats

This commit is contained in:
Arvid Norberg 2010-02-08 05:43:54 +00:00
parent 3a9a133e55
commit 1a97405189
6 changed files with 85 additions and 8 deletions

View File

@ -230,6 +230,9 @@ feature.compose <ipv6>off : <define>TORRENT_USE_IPV6=0 ;
feature need-librt : no yes : composite propagated link-incompatible ;
feature full-stats : on off : composite propagated link-incompatible ;
feature.compose <full-stats>off : <define>TORRENT_DISABLE_FULL_STATS ;
feature pool-allocators : on off : composite propagated link-incompatible ;
feature.compose <pool-allocators>off : <define>TORRENT_DISABLE_POOL_ALLOCATOR ;

View File

@ -354,6 +354,12 @@ Build features:
| | API. Generates build errors when deprecated |
| | functions are used. |
+--------------------------+----------------------------------------------------+
| ``full-stats`` | * ``on`` - default, collects stats for IP overhead |
| | and DHT and trackers. This uses a little bit |
| | extra memory for each peer and torrent. |
| | * ``off`` - only collects the standard stats for |
| | upload and download rate. |
+--------------------------+----------------------------------------------------+
.. _MaxMind: http://www.maxmind.com/app/api

View File

@ -168,6 +168,15 @@ support, you need to patch parts of boost.
Also make sure to optimize for size when compiling.
reduce statistics
-----------------
You can save some memory for each connection and each torrent by reducing the
number of separate rates kept track of by libtorrent. If you build with ``full-stats=off``
(or ``-DTORRENT_DISABLE_FULL_STATS``) you will save a few hundred bytes for each
connection and torrent. It might make a difference if you have a very large number
of peers or torrents.
play nice with the disk
=======================

View File

@ -1112,14 +1112,16 @@ namespace libtorrent
{
upload_payload,
upload_protocol,
download_payload,
download_protocol,
#ifndef TORRENT_DISABLE_FULL_STATS
upload_ip_protocol,
upload_dht_protocol,
upload_tracker_protocol,
download_payload,
download_protocol,
download_ip_protocol,
download_dht_protocol,
download_tracker_protocol,
#endif
num_channels
};

View File

@ -172,38 +172,50 @@ namespace libtorrent
void sent_syn(bool ipv6)
{
#ifndef TORRENT_DISABLE_FULL_STATS
m_stat[upload_ip_protocol].add(ipv6 ? 60 : 40);
#endif
}
void received_synack(bool ipv6)
{
#ifndef TORRENT_DISABLE_FULL_STATS
// we received SYN-ACK and also sent ACK back
m_stat[download_ip_protocol].add(ipv6 ? 60 : 40);
m_stat[upload_ip_protocol].add(ipv6 ? 60 : 40);
#endif
}
void received_dht_bytes(int bytes)
{
#ifndef TORRENT_DISABLE_FULL_STATS
TORRENT_ASSERT(bytes >= 0);
m_stat[download_dht_protocol].add(bytes);
#endif
}
void sent_dht_bytes(int bytes)
{
#ifndef TORRENT_DISABLE_FULL_STATS
TORRENT_ASSERT(bytes >= 0);
m_stat[upload_dht_protocol].add(bytes);
#endif
}
void received_tracker_bytes(int bytes)
{
#ifndef TORRENT_DISABLE_FULL_STATS
TORRENT_ASSERT(bytes >= 0);
m_stat[download_tracker_protocol].add(bytes);
#endif
}
void sent_tracker_bytes(int bytes)
{
#ifndef TORRENT_DISABLE_FULL_STATS
TORRENT_ASSERT(bytes >= 0);
m_stat[upload_tracker_protocol].add(bytes);
#endif
}
void received_bytes(int bytes_payload, int bytes_protocol)
@ -228,6 +240,7 @@ namespace libtorrent
// account for the overhead caused by it
void trancieve_ip_packet(int bytes_transferred, bool ipv6)
{
#ifndef TORRENT_DISABLE_FULL_STATS
// one TCP/IP packet header for the packet
// sent or received, and one for the ACK
// The IPv4 header is 20 bytes
@ -238,14 +251,24 @@ namespace libtorrent
const int overhead = (std::max)(1, (bytes_transferred + packet_size - 1) / packet_size) * header;
m_stat[download_ip_protocol].add(overhead);
m_stat[upload_ip_protocol].add(overhead);
#endif
}
#ifndef TORRENT_DISABLE_FULL_STATS
int upload_ip_overhead() const { return m_stat[upload_ip_protocol].counter(); }
int download_ip_overhead() const { return m_stat[download_ip_protocol].counter(); }
int upload_dht() const { return m_stat[upload_dht_protocol].counter(); }
int download_dht() const { return m_stat[download_dht_protocol].counter(); }
int download_tracker() const { return m_stat[download_tracker_protocol].counter(); }
int upload_tracker() const { return m_stat[upload_tracker_protocol].counter(); }
#else
int upload_ip_overhead() const { return 0; }
int download_ip_overhead() const { return 0; }
int upload_dht() const { return 0; }
int download_dht() const { return 0; }
int download_tracker() const { return 0; }
int upload_tracker() const { return 0; }
#endif
void set_window(int w)
{
@ -264,8 +287,11 @@ namespace libtorrent
{
return int((m_stat[upload_payload].rate_sum()
+ m_stat[upload_protocol].rate_sum()
#ifndef TORRENT_DISABLE_FULL_STATS
+ m_stat[upload_ip_protocol].rate_sum()
+ m_stat[upload_dht_protocol].rate_sum())
+ m_stat[upload_dht_protocol].rate_sum()
#endif
)
/ m_stat[0].window());
}
@ -273,8 +299,11 @@ namespace libtorrent
{
return int((m_stat[download_payload].rate_sum()
+ m_stat[download_protocol].rate_sum()
#ifndef TORRENT_DISABLE_FULL_STATS
+ m_stat[download_ip_protocol].rate_sum()
+ m_stat[download_dht_protocol].rate_sum())
+ m_stat[download_dht_protocol].rate_sum()
#endif
)
/ m_stat[0].window());
}
@ -282,18 +311,24 @@ namespace libtorrent
{
return m_stat[upload_payload].total()
+ m_stat[upload_protocol].total()
#ifndef TORRENT_DISABLE_FULL_STATS
+ m_stat[upload_ip_protocol].total()
+ m_stat[upload_dht_protocol].total()
+ m_stat[upload_tracker_protocol].total();
+ m_stat[upload_tracker_protocol].total()
#endif
;
}
size_type total_download() const
{
return m_stat[download_payload].total()
+ m_stat[download_protocol].total()
#ifndef TORRENT_DISABLE_FULL_STATS
+ m_stat[download_ip_protocol].total()
+ m_stat[download_dht_protocol].total()
+ m_stat[download_tracker_protocol].total();
+ m_stat[download_tracker_protocol].total()
#endif
;
}
int upload_payload_rate() const
@ -339,14 +374,16 @@ namespace libtorrent
{
upload_payload,
upload_protocol,
download_payload,
download_protocol,
#ifndef TORRENT_DISABLE_FULL_STATS
upload_ip_protocol,
upload_dht_protocol,
upload_tracker_protocol,
download_payload,
download_protocol,
download_ip_protocol,
download_dht_protocol,
download_tracker_protocol,
#endif
num_channels
};

View File

@ -2987,6 +2987,7 @@ namespace aux {
s.payload_upload_rate = m_stat.transfer_rate(stat::upload_payload);
s.total_payload_upload = m_stat.total_transfer(stat::upload_payload);
#ifndef TORRENT_DISABLE_FULL_STATS
// IP-overhead
s.ip_overhead_download_rate = m_stat.transfer_rate(stat::download_ip_protocol);
s.total_ip_overhead_download = m_stat.total_transfer(stat::download_ip_protocol);
@ -3004,6 +3005,25 @@ namespace aux {
s.total_tracker_download = m_stat.total_transfer(stat::download_tracker_protocol);
s.tracker_upload_rate = m_stat.transfer_rate(stat::upload_tracker_protocol);
s.total_tracker_upload = m_stat.total_transfer(stat::upload_tracker_protocol);
#else
// IP-overhead
s.ip_overhead_download_rate = 0;
s.total_ip_overhead_download = 0;
s.ip_overhead_upload_rate = 0;
s.total_ip_overhead_upload = 0;
// DHT protocol
s.dht_download_rate = 0;
s.total_dht_download = 0;
s.dht_upload_rate = 0;
s.total_dht_upload = 0;
// tracker
s.tracker_download_rate = 0;
s.total_tracker_download = 0;
s.tracker_upload_rate = 0;
s.total_tracker_upload = 0;
#endif
#ifndef TORRENT_DISABLE_DHT
if (m_dht)