logs node uptime and parses it for the DHT

This commit is contained in:
Arvid Norberg 2008-05-10 05:51:58 +00:00
parent 3fe96818d3
commit aa626f1422
4 changed files with 65 additions and 13 deletions

View File

@ -44,17 +44,30 @@ struct node_entry
node_entry(node_id const& id_, udp::endpoint addr_) node_entry(node_id const& id_, udp::endpoint addr_)
: id(id_) : id(id_)
, addr(addr_) , addr(addr_)
, fail_count(0) {} , fail_count(0)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = time_now();
#endif
}
node_entry(udp::endpoint addr_) node_entry(udp::endpoint addr_)
: id(0) : id(0)
, addr(addr_) , addr(addr_)
, fail_count(0) {} , fail_count(0)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = time_now();
#endif
}
node_id id; node_id id;
udp::endpoint addr; udp::endpoint addr;
// the number of times this node has failed to // the number of times this node has failed to
// respond in a row // respond in a row
int fail_count; int fail_count;
#ifdef TORRENT_DHT_VERBOSE_LOGGING
ptime first_seen;
#endif
}; };
} } // namespace libtorrent::dht } } // namespace libtorrent::dht

View File

@ -55,7 +55,10 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
//TORRENT_DECLARE_LOG(table); #ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_DECLARE_LOG(table);
#endif
typedef std::vector<node_entry> bucket_t; typedef std::vector<node_entry> bucket_t;

View File

@ -1,11 +1,15 @@
import sys import sys
import os import os
up_time_quanta = 60
f = open(sys.argv[1]) f = open(sys.argv[1])
histogram = {} announce_histogram = {}
node_uptime_histogram = {}
for i in xrange(0, 50): histogram[i] = 0 for i in xrange(0, 50): announce_histogram[i] = 0
for i in xrange(0, 5000, up_time_quanta): node_uptime_histogram[i] = 0
counter = 0; counter = 0;
@ -14,20 +18,30 @@ for line in f:
if counter % 1000 == 0: if counter % 1000 == 0:
print '\r%d' % counter, print '\r%d' % counter,
try: try:
if not 'distance:' in line: continue; if 'distance:' in line:
l = line.split(' ') l = line.split(' ')
d = int(l[4]) d = int(l[4])
histogram[d] += 1 announce_histogram[d] += 1
if 'NODE FAILED' in line:
l = line.split(' ')
if int(l[9]) != 1: continue;
d = int(l[11])
node_uptime_histogram[d - (d % up_time_quanta)] += 1
except: except:
print line.split(' ') print line.split(' ')
out = open('dht_announce_distribution.dat', 'w+') out = open('dht_announce_distribution.dat', 'w+')
for k,v in histogram.items(): for k,v in announce_histogram.items():
print >>out, '%d %d' % (k, v) print >>out, '%d %d' % (k, v)
out.close() out.close()
out = open('dht_announce_distribution.gnuplot', 'w+') out = open('dht_node_uptime_distribution.dat', 'w+')
for k,v in node_uptime_histogram.items():
print >>out, '%d %d' % (k + up_time_quanta/2, v)
out.close()
out = open('dht.gnuplot', 'w+')
out.write(''' out.write('''
set term png size 1200,700 small set term png size 1200,700 small
set output "dht_announce_distribution.png" set output "dht_announce_distribution.png"
@ -39,8 +53,17 @@ plot "dht_announce_distribution.dat" using 1:2 title "announces" with boxes
set terminal postscript set terminal postscript
set output "dht_announce_distribution.ps" set output "dht_announce_distribution.ps"
replot replot
''')
set term png size 1200,700 small
set output "dht_node_uptime_distribution.png"
set title "node up time"
set ylabel "# of nodes"
set xlabel "uptime (seconds)"
set boxwidth %f
set style fill solid border -1 pattern 2
plot "dht_node_uptime_distribution.dat" using 1:2 title "nodes" with boxes
''' % up_time_quanta)
out.close() out.close()
os.system('gnuplot dht_announce_distribution.gnuplot'); os.system('gnuplot dht.gnuplot');

View File

@ -50,6 +50,10 @@ using boost::uint8_t;
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_DEFINE_LOG(table)
#endif
routing_table::routing_table(node_id const& id, int bucket_size routing_table::routing_table(node_id const& id, int bucket_size
, dht_settings const& settings) , dht_settings const& settings)
: m_bucket_size(bucket_size) : m_bucket_size(bucket_size)
@ -222,6 +226,15 @@ void routing_table::node_failed(node_id const& id)
if (rb.empty()) if (rb.empty())
{ {
++i->fail_count; ++i->fail_count;
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(table) << " NODE FAILED"
" id: " << id <<
" ip: " << i->addr <<
" fails: " << i->fail_count <<
" up-time: " << total_seconds(time_now() - i->first_seen);
#endif
if (i->fail_count >= m_settings.max_fail_count) if (i->fail_count >= m_settings.max_fail_count)
{ {
b.erase(i); b.erase(i);