bandwidth request block size optimization

This commit is contained in:
Arvid Norberg 2008-01-07 04:47:20 +00:00
parent 2ea40a51a9
commit 1d6e0f5bf6
8 changed files with 62 additions and 12 deletions

View File

@ -2262,6 +2262,13 @@ struct peer_info
web_seed = 1 web_seed = 1
}; };
int connection_type; int connection_type;
int remote_dl_rate;
int pending_disk_bytes;
int send_quota;
int receive_quota;
}; };
</pre> </pre>
<p>The <tt class="docutils literal"><span class="pre">flags</span></tt> attribute tells you in which state the peer is. It is set to <p>The <tt class="docutils literal"><span class="pre">flags</span></tt> attribute tells you in which state the peer is. It is set to
@ -2406,6 +2413,14 @@ In the case of a web seed, the server type and version will be a part of this
string.</p> string.</p>
<p><tt class="docutils literal"><span class="pre">connection_type</span></tt> can currently be one of <tt class="docutils literal"><span class="pre">standard_bittorrent</span></tt> or <p><tt class="docutils literal"><span class="pre">connection_type</span></tt> can currently be one of <tt class="docutils literal"><span class="pre">standard_bittorrent</span></tt> or
<tt class="docutils literal"><span class="pre">web_seed</span></tt>. These are currently the only implemented protocols.</p> <tt class="docutils literal"><span class="pre">web_seed</span></tt>. These are currently the only implemented protocols.</p>
<p><tt class="docutils literal"><span class="pre">remote_dl_rate</span></tt> is an estimate of the rate this peer is downloading at, in
bytes per second.</p>
<p><tt class="docutils literal"><span class="pre">pending_disk_bytes</span></tt> is the number of bytes this peer has pending in the
disk-io thread. Downloaded and waiting to be written to disk. This is what
is capped by <tt class="docutils literal"><span class="pre">session_settings::max_outstanding_disk_bytes_per_connection</span></tt>.</p>
<p><tt class="docutils literal"><span class="pre">send_quota</span></tt> and <tt class="docutils literal"><span class="pre">receive_quota</span></tt> are the number of bytes this peer has been
assigned to be allowed to send and receive until it has to request more quota
from the bandwidth manager.</p>
</div> </div>
<div class="section"> <div class="section">
<h1><a id="session-settings" name="session-settings">session_settings</a></h1> <h1><a id="session-settings" name="session-settings">session_settings</a></h1>

View File

@ -2251,6 +2251,13 @@ It contains the following fields::
web_seed = 1 web_seed = 1
}; };
int connection_type; int connection_type;
int remote_dl_rate;
int pending_disk_bytes;
int send_quota;
int receive_quota;
}; };
The ``flags`` attribute tells you in which state the peer is. It is set to The ``flags`` attribute tells you in which state the peer is. It is set to
@ -2389,6 +2396,17 @@ string.
``connection_type`` can currently be one of ``standard_bittorrent`` or ``connection_type`` can currently be one of ``standard_bittorrent`` or
``web_seed``. These are currently the only implemented protocols. ``web_seed``. These are currently the only implemented protocols.
``remote_dl_rate`` is an estimate of the rate this peer is downloading at, in
bytes per second.
``pending_disk_bytes`` is the number of bytes this peer has pending in the
disk-io thread. Downloaded and waiting to be written to disk. This is what
is capped by ``session_settings::max_outstanding_disk_bytes_per_connection``.
``send_quota`` and ``receive_quota`` are the number of bytes this peer has been
assigned to be allowed to send and receive until it has to request more quota
from the bandwidth manager.
session_settings session_settings
================ ================

View File

@ -306,7 +306,7 @@ int peer_index(libtorrent::tcp::endpoint addr, std::vector<libtorrent::peer_info
void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const& peers) void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const& peers)
{ {
using namespace libtorrent; using namespace libtorrent;
out << "IP down (total) up (total) sent-req recv flags source fail hshf sndb inactive wait disk block-progress " out << "IP down (total) up (total) sent-req recv flags source fail hshf sndb inactive wait disk quota block-progress "
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
"country " "country "
#endif #endif
@ -352,12 +352,13 @@ void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const
<< ((i->source & peer_info::dht)?"D":"_") << ((i->source & peer_info::dht)?"D":"_")
<< ((i->source & peer_info::lsd)?"L":"_") << ((i->source & peer_info::lsd)?"L":"_")
<< ((i->source & peer_info::resume_data)?"R":"_") << " " << ((i->source & peer_info::resume_data)?"R":"_") << " "
<< to_string(i->failcount, 4) << " " << to_string(i->failcount, 2) << " "
<< to_string(i->num_hashfails, 4) << " " << to_string(i->num_hashfails, 2) << " "
<< to_string(i->send_buffer_size, 4) << " " << to_string(i->send_buffer_size, 6) << " "
<< to_string(total_seconds(i->last_active), 8) << " " << to_string(total_seconds(i->last_active), 8) << " "
<< to_string(total_seconds(i->last_request), 4) << " " << to_string(total_seconds(i->last_request), 4) << " "
<< to_string(i->pending_disk_bytes, 4) << " "; << to_string(i->pending_disk_bytes, 6) << " "
<< to_string(i->send_quota, 5) << " ";
if (i->downloading_piece_index >= 0) if (i->downloading_piece_index >= 0)
{ {

View File

@ -155,6 +155,10 @@ namespace libtorrent
// number of bytes this peer has in // number of bytes this peer has in
// the disk write queue // the disk write queue
int pending_disk_bytes; int pending_disk_bytes;
// numbers used for bandwidth limiting
int send_quota;
int receive_quota;
}; };
} }

View File

@ -234,12 +234,11 @@ namespace libtorrent
void request_bandwidth(int channel void request_bandwidth(int channel
, boost::intrusive_ptr<peer_connection> const& p , boost::intrusive_ptr<peer_connection> const& p
, bool non_prioritized); , bool non_prioritized, int max_block_size);
void perform_bandwidth_request(int channel void perform_bandwidth_request(int channel
, boost::intrusive_ptr<peer_connection> const& p , boost::intrusive_ptr<peer_connection> const& p
, int block_size , int block_size, bool non_prioritized);
, bool non_prioritized);
void expire_bandwidth(int channel, int amount); void expire_bandwidth(int channel, int amount);
void assign_bandwidth(int channel, int amount, int blk); void assign_bandwidth(int channel, int amount, int blk);

View File

@ -2033,6 +2033,8 @@ namespace libtorrent
void peer_connection::timed_out() void peer_connection::timed_out()
{ {
TORRENT_ASSERT(m_connecting);
TORRENT_ASSERT(m_connection_ticket >= 0);
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << time_now_string() << " CONNECTION TIMED OUT: " << m_remote.address().to_string() (*m_ses.m_logger) << time_now_string() << " CONNECTION TIMED OUT: " << m_remote.address().to_string()
<< "\n"; << "\n";
@ -2152,6 +2154,8 @@ namespace libtorrent
p.pid = pid(); p.pid = pid();
p.ip = remote(); p.ip = remote();
p.pending_disk_bytes = m_outstanding_writing_bytes; p.pending_disk_bytes = m_outstanding_writing_bytes;
p.send_quota = m_bandwidth_limit[upload_channel].quota_left();
p.receive_quota = m_bandwidth_limit[download_channel].quota_left();
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
p.country[0] = m_country[0]; p.country[0] = m_country[0];
@ -2560,7 +2564,8 @@ namespace libtorrent
m_requested_write_quota = true; m_requested_write_quota = true;
#endif #endif
t->request_bandwidth(upload_channel, self() t->request_bandwidth(upload_channel, self()
, !(is_interesting() && !has_peer_choked())); , !(is_interesting() && !has_peer_choked())
, m_send_buffer.size());
} }
return; return;
} }
@ -2617,7 +2622,8 @@ namespace libtorrent
TORRENT_ASSERT(!m_requested_read_quota); TORRENT_ASSERT(!m_requested_read_quota);
m_requested_read_quota = true; m_requested_read_quota = true;
#endif #endif
t->request_bandwidth(download_channel, self(), m_non_prioritized); t->request_bandwidth(download_channel, self(), m_non_prioritized
, m_download_queue.size() * 16 * 1024 + 30);
} }
return; return;
} }
@ -3031,6 +3037,7 @@ namespace libtorrent
== m_ses.m_bandwidth_manager[i]->is_in_history(this) == m_ses.m_bandwidth_manager[i]->is_in_history(this)
|| m_bandwidth_limit[i].throttle() == bandwidth_limit::inf); || m_bandwidth_limit[i].throttle() == bandwidth_limit::inf);
} }
std::set<piece_block> unique; std::set<piece_block> unique;
std::copy(m_download_queue.begin(), m_download_queue.end(), std::inserter(unique, unique.begin())); std::copy(m_download_queue.begin(), m_download_queue.end(), std::inserter(unique, unique.begin()));
std::copy(m_request_queue.begin(), m_request_queue.end(), std::inserter(unique, unique.begin())); std::copy(m_request_queue.begin(), m_request_queue.end(), std::inserter(unique, unique.begin()));

View File

@ -1061,6 +1061,10 @@ namespace libtorrent
// since that is the size of the pool allocator's buffers // since that is the size of the pool allocator's buffers
TORRENT_ASSERT(r.length <= 16 * 1024 || buffer != 0); TORRENT_ASSERT(r.length <= 16 * 1024 || buffer != 0);
m_io_thread.add_job(j, handler); m_io_thread.add_job(j, handler);
#ifndef NDEBUG
boost::recursive_mutex::scoped_lock l(m_mutex);
TORRENT_ASSERT(slot_for(r.piece) >= 0);
#endif
} }
void piece_manager::async_write( void piece_manager::async_write(

View File

@ -2273,11 +2273,13 @@ namespace libtorrent
void torrent::request_bandwidth(int channel void torrent::request_bandwidth(int channel
, boost::intrusive_ptr<peer_connection> const& p , boost::intrusive_ptr<peer_connection> const& p
, bool non_prioritized) , bool non_prioritized, int max_block_size)
{ {
TORRENT_ASSERT(max_block_size > 0);
TORRENT_ASSERT(m_bandwidth_limit[channel].throttle() > 0); TORRENT_ASSERT(m_bandwidth_limit[channel].throttle() > 0);
TORRENT_ASSERT(p->max_assignable_bandwidth(channel) > 0); TORRENT_ASSERT(p->max_assignable_bandwidth(channel) > 0);
int block_size = m_bandwidth_limit[channel].throttle() / 10; int block_size = (std::min)(m_bandwidth_limit[channel].throttle() / 10
, max_block_size);
if (block_size <= 0) block_size = 1; if (block_size <= 0) block_size = 1;
if (m_bandwidth_limit[channel].max_assignable() > 0) if (m_bandwidth_limit[channel].max_assignable() > 0)