report stats on the number of dht request observers that are currently allocated

This commit is contained in:
Arvid Norberg 2010-11-06 07:12:57 +00:00
parent d3a8916f02
commit 1c7e5506e9
9 changed files with 47 additions and 16 deletions

View File

@ -655,8 +655,9 @@ struct has the following members::
int dht_nodes; int dht_nodes;
int dht_node_cache; int dht_node_cache;
int dht_torrents; int dht_torrents;
int dht_global_nodes; size_type dht_global_nodes;
std::vector<dht_lookup> active_requests; std::vector<dht_lookup> active_requests;
int dht_total_allocations;
}; };
``has_incoming_connections`` is false as long as no incoming connections have been ``has_incoming_connections`` is false as long as no incoming connections have been
@ -720,6 +721,9 @@ network.
``active_requests`` is a vector of the currently running DHT lookups. ``active_requests`` is a vector of the currently running DHT lookups.
``dht_total_allocations`` is the number of nodes allocated dynamically for a
particular DHT lookup. This represents roughly the amount of memory used
by the DHT.
get_cache_status() get_cache_status()
------------------ ------------------

View File

@ -1483,8 +1483,9 @@ int main(int argc, char* argv[])
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
if (show_dht_status) if (show_dht_status)
{ {
snprintf(str, sizeof(str), "DHT nodes: %d DHT cached nodes: %d total DHT size: %"PRId64"\n" snprintf(str, sizeof(str), "DHT nodes: %d DHT cached nodes: %d total DHT size: %"PRId64" total observers: %d\n"
, sess_stat.dht_nodes, sess_stat.dht_node_cache, sess_stat.dht_global_nodes); , sess_stat.dht_nodes, sess_stat.dht_node_cache, sess_stat.dht_global_nodes
, sess_stat.dht_total_allocations);
out += str; out += str;
for (std::vector<dht_lookup>::iterator i = sess_stat.active_requests.begin() for (std::vector<dht_lookup>::iterator i = sess_stat.active_requests.begin()

View File

@ -89,8 +89,10 @@ public:
void check_invariant() const; void check_invariant() const;
#endif #endif
boost::pool<>& allocator() const void* allocate_observer();
{ return m_pool_allocator; } void free_observer(void* ptr);
int num_allocated_observers() const { return m_allocated_observers; }
private: private:
@ -112,6 +114,7 @@ private:
routing_table& m_table; routing_table& m_table;
ptime m_timer; ptime m_timer;
node_id m_random_number; node_id m_random_number;
int m_allocated_observers;
bool m_destructing; bool m_destructing;
}; };

View File

@ -66,9 +66,11 @@ struct traversal_algorithm : boost::noncopyable
enum flags_t { prevent_request = 1, short_timeout = 2 }; enum flags_t { prevent_request = 1, short_timeout = 2 };
void failed(observer_ptr o, int flags = 0); void failed(observer_ptr o, int flags = 0);
virtual ~traversal_algorithm(); virtual ~traversal_algorithm();
boost::pool<>& allocator() const;
void status(dht_lookup& l); void status(dht_lookup& l);
void* allocate_observer();
void free_observer(void* ptr);
virtual char const* name() const { return "traversal_algorithm"; } virtual char const* name() const { return "traversal_algorithm"; }
virtual void start(); virtual void start();

View File

@ -104,6 +104,7 @@ namespace libtorrent
int dht_torrents; int dht_torrents;
size_type dht_global_nodes; size_type dht_global_nodes;
std::vector<dht_lookup> active_requests; std::vector<dht_lookup> active_requests;
int dht_total_allocations;
#endif #endif
int peerlist_size; int peerlist_size;

View File

@ -366,9 +366,8 @@ namespace
TORRENT_LOG(node) << " distance: " << (160 - distance_exp(ih, i->first.id)); TORRENT_LOG(node) << " distance: " << (160 - distance_exp(ih, i->first.id));
#endif #endif
void* ptr = node.m_rpc.allocator().malloc(); void* ptr = node.m_rpc.allocate_observer();
if (ptr == 0) return; if (ptr == 0) return;
node.m_rpc.allocator().set_next_size(10);
observer_ptr o(new (ptr) announce_observer(algo, i->first.ep(), i->first.id)); observer_ptr o(new (ptr) announce_observer(algo, i->first.ep(), i->first.id));
#ifdef TORRENT_DEBUG #ifdef TORRENT_DEBUG
o->m_in_constructor = false; o->m_in_constructor = false;
@ -397,9 +396,8 @@ void node_impl::add_node(udp::endpoint node)
{ {
// ping the node, and if we get a reply, it // ping the node, and if we get a reply, it
// will be added to the routing table // will be added to the routing table
void* ptr = m_rpc.allocator().malloc(); void* ptr = m_rpc.allocate_observer();
if (ptr == 0) return; if (ptr == 0) return;
m_rpc.allocator().set_next_size(10);
// create a dummy traversal_algorithm // create a dummy traversal_algorithm
// this is unfortunately necessary for the observer // this is unfortunately necessary for the observer
@ -470,6 +468,7 @@ void node_impl::status(session_status& s)
m_table.status(s); m_table.status(s);
s.dht_torrents = int(m_map.size()); s.dht_torrents = int(m_map.size());
s.active_requests.clear(); s.active_requests.clear();
s.dht_total_allocations = m_rpc.num_allocated_observers();
for (std::set<traversal_algorithm*>::iterator i = m_running_requests.begin() for (std::set<traversal_algorithm*>::iterator i = m_running_requests.begin()
, end(m_running_requests.end()); i != end; ++i) , end(m_running_requests.end()); i != end; ++i)
{ {

View File

@ -76,9 +76,9 @@ void intrusive_ptr_release(observer const* o)
TORRENT_ASSERT(o != 0); TORRENT_ASSERT(o != 0);
if (--o->m_refs == 0) if (--o->m_refs == 0)
{ {
boost::pool<>& p = o->m_algorithm->allocator(); boost::intrusive_ptr<traversal_algorithm> ta = o->m_algorithm;
(const_cast<observer*>(o))->~observer(); (const_cast<observer*>(o))->~observer();
p.free(const_cast<observer*>(o)); ta->free_observer(const_cast<observer*>(o));
} }
} }
@ -172,6 +172,7 @@ rpc_manager::rpc_manager(node_id const& our_id
, m_table(table) , m_table(table)
, m_timer(time_now()) , m_timer(time_now())
, m_random_number(generate_id()) , m_random_number(generate_id())
, m_allocated_observers(0)
, m_destructing(false) , m_destructing(false)
{ {
std::srand(time(0)); std::srand(time(0));
@ -215,6 +216,21 @@ rpc_manager::~rpc_manager()
} }
} }
void* rpc_manager::allocate_observer()
{
m_pool_allocator.set_next_size(10);
void* ret = m_pool_allocator.malloc();
if (ret) ++m_allocated_observers;
return ret;
}
void rpc_manager::free_observer(void* ptr)
{
if (!ptr) return;
--m_allocated_observers;
m_pool_allocator.free(ptr);
}
#ifdef TORRENT_DEBUG #ifdef TORRENT_DEBUG
size_t rpc_manager::allocation_size() const size_t rpc_manager::allocation_size() const
{ {

View File

@ -59,8 +59,7 @@ observer_ptr traversal_algorithm::new_observer(void* ptr
void traversal_algorithm::add_entry(node_id const& id, udp::endpoint addr, unsigned char flags) void traversal_algorithm::add_entry(node_id const& id, udp::endpoint addr, unsigned char flags)
{ {
TORRENT_ASSERT(m_node.m_rpc.allocation_size() >= sizeof(find_data_observer)); TORRENT_ASSERT(m_node.m_rpc.allocation_size() >= sizeof(find_data_observer));
m_node.m_rpc.allocator().set_next_size(10); void* ptr = m_node.m_rpc.allocate_observer();
void* ptr = m_node.m_rpc.allocator().malloc();
if (ptr == 0) if (ptr == 0)
{ {
#ifdef TORRENT_DHT_VERBOSE_LOGGING #ifdef TORRENT_DHT_VERBOSE_LOGGING
@ -113,9 +112,14 @@ void traversal_algorithm::start()
add_requests(); add_requests();
} }
boost::pool<>& traversal_algorithm::allocator() const void* traversal_algorithm::allocate_observer()
{ {
return m_node.m_rpc.allocator(); return m_node.m_rpc.allocate_observer();
}
void traversal_algorithm::free_observer(void* ptr)
{
m_node.m_rpc.free_observer(ptr);
} }
void traversal_algorithm::traverse(node_id const& id, udp::endpoint addr) void traversal_algorithm::traverse(node_id const& id, udp::endpoint addr)

View File

@ -3566,6 +3566,7 @@ namespace aux {
s.dht_node_cache = 0; s.dht_node_cache = 0;
s.dht_torrents = 0; s.dht_torrents = 0;
s.dht_global_nodes = 0; s.dht_global_nodes = 0;
s.dht_total_allocations = 0;
} }
#endif #endif