diff --git a/include/libtorrent/kademlia/node_entry.hpp b/include/libtorrent/kademlia/node_entry.hpp index ede402cf4..e31a60e3f 100644 --- a/include/libtorrent/kademlia/node_entry.hpp +++ b/include/libtorrent/kademlia/node_entry.hpp @@ -44,17 +44,30 @@ struct node_entry node_entry(node_id const& id_, udp::endpoint addr_) : id(id_) , addr(addr_) - , fail_count(0) {} + , fail_count(0) + { +#ifdef TORRENT_DHT_VERBOSE_LOGGING + first_seen = time_now(); +#endif + } node_entry(udp::endpoint addr_) : id(0) , addr(addr_) - , fail_count(0) {} + , fail_count(0) + { +#ifdef TORRENT_DHT_VERBOSE_LOGGING + first_seen = time_now(); +#endif + } node_id id; udp::endpoint addr; // the number of times this node has failed to // respond in a row int fail_count; +#ifdef TORRENT_DHT_VERBOSE_LOGGING + ptime first_seen; +#endif }; } } // namespace libtorrent::dht diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index d2068dd75..e3f2e7ded 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -55,7 +55,10 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace dht { -//TORRENT_DECLARE_LOG(table); +#ifdef TORRENT_DHT_VERBOSE_LOGGING +TORRENT_DECLARE_LOG(table); +#endif + typedef std::vector bucket_t; diff --git a/parse_dht_log.py b/parse_dht_log.py index ba5ddbcdd..51af6525e 100644 --- a/parse_dht_log.py +++ b/parse_dht_log.py @@ -1,11 +1,15 @@ import sys import os +up_time_quanta = 60 + 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; @@ -14,20 +18,30 @@ for line in f: if counter % 1000 == 0: print '\r%d' % counter, try: - if not 'distance:' in line: continue; - l = line.split(' ') + if 'distance:' in line: + l = line.split(' ') - d = int(l[4]) - histogram[d] += 1 + d = int(l[4]) + 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: print line.split(' ') 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) 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(''' set term png size 1200,700 small 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 output "dht_announce_distribution.ps" 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() -os.system('gnuplot dht_announce_distribution.gnuplot'); +os.system('gnuplot dht.gnuplot'); diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index c3477a9d1..6c4d93f2b 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -50,6 +50,10 @@ using boost::uint8_t; 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 , dht_settings const& settings) : m_bucket_size(bucket_size) @@ -222,6 +226,15 @@ void routing_table::node_failed(node_id const& id) if (rb.empty()) { ++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) { b.erase(i);