Permalink
Browse files

back-port fix request queue size performance issue

  • Loading branch information...
arvidn committed Jul 20, 2015
1 parent 112d75e commit 578d353bce60b66ea886e623f5d0930411430d3c
Showing with 62 additions and 16 deletions.
  1. +1 −0 ChangeLog
  2. +13 −0 include/libtorrent/peer_connection.hpp
  3. +15 −0 src/peer_connection.cpp
  4. +1 −1 src/session.cpp
  5. +22 −12 src/utp_stream.cpp
  6. +10 −3 tools/parse_utp_log.py
View
@@ -1,5 +1,6 @@
1.0.6 release
* fix request queue size performance issue
* slightly improve UDP tracker performance
* fix http scrapes
* add missing port mapping functions to python binding
@@ -801,6 +801,12 @@ namespace libtorrent
// other peers to compare it to.
bool m_exceeded_limit:1;
// this is slow-start at the bittorrent layer. It affects how we increase
// desired queue size (i.e. the number of outstanding requests we keep).
// While the underlying transport protocol is in slow-start, the number of
// outstanding requests need to increase at the same pace to keep up.
bool m_slow_start:1;
// TODO: make these private as well
protected:
@@ -1025,6 +1031,12 @@ namespace libtorrent
// extended.
int m_timeout_extend;
// the number of payload bytes downloaded last second tick
boost::int32_t m_downloaded_last_second;
// the number of payload bytes uploaded last second tick
boost::int32_t m_uploaded_last_second;
// the number of bytes that the other
// end has to send us in order to respond
// to all outstanding piece requests we
@@ -1147,6 +1159,7 @@ namespace libtorrent
// the number of request we should queue up
// at the remote end.
// TODO: 2 rename this target queue size
boost::uint16_t m_desired_queue_size;
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
View
@@ -2320,6 +2320,10 @@ namespace libtorrent
if (!m_bitfield_received) incoming_have_none();
if (is_disconnecting()) return;
// slow-start
if (m_slow_start)
m_desired_queue_size += 1;
update_desired_queue_size();
#ifndef TORRENT_DISABLE_EXTENSIONS
@@ -4320,6 +4324,17 @@ namespace libtorrent
m_ignore_bandwidth_limits = m_ses.settings().ignore_limits_on_local_network
&& on_local_network();
// if our download rate isn't increasing significantly anymore, end slow
// start. The 10kB is to have some slack here.
if (m_slow_start && m_downloaded_last_second > 0
&& m_downloaded_last_second + 10000
>= m_statistics.last_payload_downloaded())
{
m_slow_start = false;
}
m_downloaded_last_second = m_statistics.last_payload_downloaded();
m_uploaded_last_second = m_statistics.last_payload_uploaded();
m_statistics.second_tick(tick_interval_ms);
if (m_statistics.upload_payload_rate() > m_upload_rate_peak)
View
@@ -1385,7 +1385,7 @@ namespace libtorrent
, connections_limit(200)
, connections_slack(10)
, utp_target_delay(100) // milliseconds
, utp_gain_factor(1500) // bytes per rtt
, utp_gain_factor(3000) // bytes per rtt
, utp_min_timeout(500) // milliseconds
, utp_syn_resends(2)
, utp_fin_resends(2)
View
@@ -623,7 +623,7 @@ struct utp_socket_impl
// this is done at startup of a socket in order to find its
// link capacity faster. This behaves similar to TCP slow start
bool m_slow_start:1;
// this is true as long as we have as many packets in
// flight as allowed by the congestion window (cwnd)
bool m_cwnd_full:1;
@@ -1602,7 +1602,9 @@ struct holder
// congestion window, false if there is no more space.
bool utp_socket_impl::send_pkt(int flags)
{
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;
#endif
bool force = (flags & pkt_ack) || (flags & pkt_fin);
@@ -2144,29 +2146,33 @@ void utp_socket_impl::experienced_loss(int seq_nr)
// less than or equal to. If we experience loss of the
// same packet again, ignore it.
if (compare_less_wrap(seq_nr, m_loss_seq_nr + 1, ACK_MASK)) return;
// cut window size in 2
m_cwnd = (std::max)(m_cwnd * m_sm->loss_multiplier() / 100, boost::int64_t(m_mtu << 16));
m_loss_seq_nr = m_seq_nr;
UTP_LOGV("%8p: Lost packet %d caused cwnd cut\n", this, seq_nr);
// if we happen to be in slow-start mode, we need to leave it
// note that we set ssthres to the window size _after_ reducing it. Next slow
// start should end before we over shoot.
if (m_slow_start)
{
m_ssthres = m_cwnd >> 16;
m_slow_start = false;
UTP_LOGV("%8p: experienced loss, slow_start -> 0\n", this);
}
// cut window size in 2
m_cwnd = (std::max)(m_cwnd * m_sm->loss_multiplier() / 100, boost::int64_t(m_mtu << 16));
m_loss_seq_nr = m_seq_nr;
UTP_LOGV("%8p: Lost packet %d caused cwnd cut\n", this, seq_nr);
// the window size could go below one MMS here, if it does,
// we'll get a timeout in about one second
m_sm->inc_stats_counter(utp_socket_manager::packet_loss);
}
void utp_socket_impl::maybe_inc_acked_seq_nr()
{
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;
#endif
bool incremented = false;
// don't pass m_seq_nr, since we move into sequence
@@ -2198,7 +2204,9 @@ void utp_socket_impl::maybe_inc_acked_seq_nr()
void utp_socket_impl::ack_packet(packet* p, ptime const& receive_time
, boost::uint32_t& min_rtt, boost::uint16_t seq_nr)
{
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;
#endif
TORRENT_ASSERT(p);
@@ -2244,7 +2252,9 @@ void utp_socket_impl::ack_packet(packet* p, ptime const& receive_time
void utp_socket_impl::incoming(boost::uint8_t const* buf, int size, packet* p, ptime now)
{
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;
#endif
while (!m_read_buffer.empty())
{
@@ -3213,7 +3223,7 @@ void utp_socket_impl::do_ledbat(int acked_bytes, int delay, int in_flight, ptime
boost::int64_t window_factor = (boost::int64_t(acked_bytes) << 16) / in_flight;
boost::int64_t delay_factor = (boost::int64_t(target_delay - delay) << 16) / target_delay;
boost::int64_t scaled_gain;
if (delay >= target_delay)
{
if (m_slow_start)
@@ -3502,15 +3512,15 @@ void utp_socket_impl::check_receive_buffers() const
void utp_socket_impl::check_invariant() const
{
for (int i = m_outbuf.cursor();
i != int((m_outbuf.cursor() + m_outbuf.span()) & ACK_MASK);
i != int((m_outbuf.cursor() + m_outbuf.span()) & ACK_MASK);
i = (i + 1) & ACK_MASK)
{
packet* p = (packet*)m_outbuf.at(i);
if (m_mtu_seq == i && m_mtu_seq != 0 && p)
if (!p) continue;
if (m_mtu_seq == i && m_mtu_seq != 0)
{
TORRENT_ASSERT(p->mtu_probe);
}
if (!p) continue;
TORRENT_ASSERT(((utp_header*)p->buf)->seq_nr == i);
}
View
@@ -53,9 +53,10 @@
delay_base = 'steps lw 2 lc rgb "purple"'
target_delay = 'steps lw 2 lc rgb "red"'
off_target = 'dots lc rgb "blue"'
cwnd = 'steps lc rgb "green"'
cwnd = 'steps lc rgb "green" lw 2'
window_size = 'steps lc rgb "sea-green"'
rtt = 'lines lc rgb "light-blue"'
send_buffer = 'lines lc rgb "light-red"'
metrics = {
'our_delay':['our delay (ms)', 'x1y2', delay_samples],
@@ -77,7 +78,7 @@
'their_delay_base':['their delay base (us)', 'x1y1', delay_base],
'their_actual_delay':['their actual delay (us)', 'x1y1', delay_samples],
'actual_delay':['actual_delay (us)', 'x1y1', delay_samples],
'send_buffer':['send buffer size (B)', 'x1y1', 'lines'],
'send_buffer':['send buffer size (B)', 'x1y1', send_buffer],
'recv_buffer':['receive buffer size (B)', 'x1y1', 'lines']
}
@@ -199,11 +200,17 @@
plot = [
{
'data': ['upload_rate', 'max_window', 'cur_window', 'wnduser', 'cur_window_packets', 'packet_size', 'rtt'],
'data': ['max_window', 'send_buffer', 'cur_window', 'rtt'],
'title': 'send-packet-size',
'y1': 'Bytes',
'y2': 'Time (ms)'
},
{
'data': ['upload_rate', 'max_window', 'cur_window', 'wnduser', 'cur_window_packets', 'packet_size', 'rtt'],
'title': 'slow-start',
'y1': 'Bytes',
'y2': 'Time (ms)'
},
{
'data': ['max_window', 'cur_window', 'our_delay', 'target_delay', 'ssthres'],
'title': 'cwnd',

0 comments on commit 578d353

Please sign in to comment.