xlgjjff / libtorrent

Automatically exported from code.google.com/p/libtorrent
Other
0 stars 0 forks source link

Too slow exit (Win XP) #752

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
May be it https://code.google.com/p/libtorrent/issues/detail?id=705 duplicate.

What steps will reproduce the problem?
1. run session with torrents
2. wait 1-2 min
3. destroy session

What is the expected output? What do you see instead?
Shutdown took ~30sec. - ~10min. (more often 40-60 seconds)

What version of the product are you using? On what operating system?
Windows XP 32 SP3 (on Win 8.1 64 not reproduced)
libtorrent 1.04 / 1.05 / RC_1_0(11123) / trunk(11122)
boost 1.57
Visual studio 2010 sp1 / Visual studio 2013 update 4

Please provide any additional information below.
Tested on "client_test" example.
Time was measured in "libtorrent\src\session_impl.cpp"
   session_impl::~session_impl()
   {
     ...
     ... time = GetTickCount();
     if (m_thread) m_thread->join();
     ... << GetTickCount() - time;
   }

I found that a lot of time takes 
boost::win_iocp_io_service::shutdown_service(). Specifically 
GetQueuedCompletionStatus() - called many times and took ~500 milliseconds.

------------------
BOOST_ASIO_DISABLE_IOCP flag was solved problem, but then hangs appears on Win 
8.1 (hang time constant - ~39.5 seconds). Reproduced on 1.05 / RC_1_0.

On trunk with disabled IOCP works fine on XP and 8.1.
But I not sure that BOOST_ASIO_DISABLE_IOCP is a good solution. As I understood 
- IOCP disabling can reduce throughput.

---- Build configuration --------------------------
release 32

BOOST_ALL_NO_LIB
BOOST_ASIO_ENABLE_CANCELIO
BOOST_ASIO_HASH_MAP_BUCKETS=1021
BOOST_ASIO_SEPARATE_COMPILATION
BOOST_EXCEPTION_DISABLE
BOOST_SYSTEM_NO_DEPRECATED
BOOST_SYSTEM_STATIC_LINK

TORRENT_DISABLE_ENCRYPTION
TORRENT_DISABLE_FULL_STATS
TORRENT_DISABLE_GEO_IP
TORRENT_DISABLE_INVARIANT_CHECKS
TORRENT_DISABLE_LOGGING
TORRENT_NO_ASSERTS
TORRENT_NO_DEPRECATE

WINVER=0x0501
_WIN32_WINNT=0x0501

Original issue reported on code.google.com by rominmai...@gmail.com on 1 Jun 2015 at 10:16

GoogleCodeExporter commented 8 years ago
File \boost\asio\detail\win_iocp_io_service.hpp contains comment:
    // Timeout to use with GetQueuedCompletionStatus on older versions of
    // Windows. Some versions of windows have a "bug" where a call to
    // GetQueuedCompletionStatus can appear stuck even though there are events
    // waiting on the queue. Using a timeout helps to work around the issue.
    default_gqcs_timeout = 500,

Maybe it's related to the problem.

Original comment by rominmai...@gmail.com on 1 Jun 2015 at 10:18

GoogleCodeExporter commented 8 years ago
UPD: forgot about important clarification: if after session start wait more 
time - >5 min - client shutdown quickly.

Original comment by rominmai...@gmail.com on 1 Jun 2015 at 12:24

GoogleCodeExporter commented 8 years ago
UPD: about hang on Win 8.1 - it not depends of the BOOST_ASIO_DISABLE_IOCP.
In some cases reproduced consistently - session shutdown about ~39.5 seconds.
Conditions: several torrent with seeding or paused state. 

Sorry for the confusion )).

Original comment by rominmai...@gmail.com on 1 Jun 2015 at 2:39

GoogleCodeExporter commented 8 years ago
My first guess would be that there are DNS lookups that are stuck. 
Unfortunately there is no way (at least not easily in boost.asio) to cancel DNS 
lookups. If you have a DNS server that's slow or have a network connection 
that's unreliable and DNS lookups stall, you have to wait for them to time out 
before you can finish the shut down. I believe the default time-out is 2 
minutes.

Presumably one or more of the trackers of the torrents you start have hostnames 
that cause hangs, once they've timed out once, you may not contact them again, 
or much later. This would explain why only if you start and try to shut down 
quickly after do you get stuck.

Original comment by arvid.no...@gmail.com on 1 Jun 2015 at 10:03

GoogleCodeExporter commented 8 years ago
btw. in trunk (the next major release) I have made some effort to mitigate 
this. Partly to cache more aggressively for shutdown and to use my own queue to 
more reliably enforce the shutdown timeout.

Original comment by arvid.no...@gmail.com on 1 Jun 2015 at 10:04

GoogleCodeExporter commented 8 years ago
Hi,
Thanks for the reply.
Looks like you are right about trackers and DNS lookups.

Here are the results of my tests:
1) Hangs related to trackers:
  libtorrent: 1.0.x (but OK on trunk)
  OS: Win XP sp3 / 7 sp1 / 8.1

  Workaround: remove torrents from session before exit.
  Time reduced from ~27 to ~5 seconds (test_client example).

2) Hangs related to DNS lookups (?):
  libtorrent: any
  OS: Win XP

  Workaround: BOOST_ASIO_DISABLE_IOCP

Please, could you express your opinion about BOOST_ASIO_DISABLE_IOCP?
How much will this affect libtorrent work (download/upload) and whole network 
bandwidth?
Thanks.

Original comment by rominmai...@gmail.com on 2 Jun 2015 at 8:54

GoogleCodeExporter commented 8 years ago
I don't understand why disabling IOCP would make a difference. If anything, 
hostname lookups would be more likely to have to be synchronous.

The main advantage of IOCP compared to select is that it scales with the number 
of connections. If you don't intend to have a large number of connections, it 
may not matter much. windows' select() only supports 64 sockets iirc, and I 
don't know what or if boost.asio attempts to work around that or if that 
becomes a hard limit. It's possible that it actually uses poll() internally too.

instead of removing the torrents, you could also stop them.

Original comment by arvid.no...@gmail.com on 2 Jun 2015 at 11:23