frostalf / libtorrent

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

half-open connection limit is not honored #338

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add some torrent file into libtorrent.
2. Set them in upload mode only

What is the expected output? What do you see instead?

In upload mode only, libtorrent should wait for income connection. I use 
Process Explorer and see that libtorrent make a lot of new connections.

What version of the product are you using? On what operating system?
Libtorrent 0.15.10, Windows XP SP3

Windows XP has a limited for half-open connection, every time I start 
libtorrent with about ten of torrents, It make my internet connection so lag.
I think in session_impl.second_tick()

for (;;)
            {
                torrent& t = *m_next_connect_torrent->second;
                if (t.want_more_peers())

...
It should care for torrent state before make new connection.

Thx.

Original issue reported on code.google.com by secm...@gmail.com on 22 Jun 2012 at 4:17

GoogleCodeExporter commented 9 years ago
I understand your problem. The solution is not to stop making outgoing 
connections for upload-only torrents. It is absolutely critical for bittorrent 
to work that you make outgoing connections for all active torrents, regardless 
of if they're upload only or not. If you're behind a NAT and can't receive 
incoming connections, you would never connect to anyone unless you initiate the 
connection.

You can lower the number of half-open connections allowed by libtorrent if 
you'd like. It's not obvious that it's the half-open connections that makes 
your internet lag. A few SYN packets will use a miniscule amount of bandwidth. 
Instead, you might want to disable the DHT if your NAT has problems with many 
pin-holes.

Original comment by arvid.no...@gmail.com on 22 Jun 2012 at 5:00

GoogleCodeExporter commented 9 years ago
Thanks for quick reply. The problem is not the bandwidth, problems is many 
Windows XP only allow about 10 half-open connections in concurrently, any more 
will be place in a queue, so any other application such as web browser have to 
wait to open a new connection while bit-torrent keep connecting.

I thought about limit number of half-open connection in libtorrent, but I only 
got connection_speed parameter in session_settings, which is opening new 
connection rate per-second, it's not number of half-open connection 
concurrently. I also disable DHT but number of half-open connections still 
enough make other applications have to wait.

Original comment by secm...@gmail.com on 22 Jun 2012 at 5:33

GoogleCodeExporter commented 9 years ago
Yeah, I'm talking about limiting half-open connections. You can do this 
manually with session::set_max_half_open_connections(), see

  http://www.rasterbar.com/products/libtorrent/manual.html

The build-in default value for windows is determined by this logic:

      // the least significant byte is the major version
      // and the most significant one is the minor version
      if (windows_version >= 0x060100)
      {
         // windows 7 and up doesn't have a half-open limit
         m_half_open.limit(0);
      }
      else if (windows_version >= 0x060002)
      {
         // on vista SP 2 and up, there's no limit
         m_half_open.limit(0);
      }
      else if (windows_version >= 0x060000)
      {
         // on vista the limit is 5 (in home edition)
         m_half_open.limit(4);
      }
      else if (windows_version >= 0x050102)
      {
         // on XP SP2 the limit is 10  
         m_half_open.limit(9);
      }
      else
      {
         // before XP SP2, there was no limit
         m_half_open.limit(0);
      }

The DHT doesn't use TCP btw, so it won't affect the number of half-open 
connections.

Original comment by ar...@rasterbar.com on 22 Jun 2012 at 7:26

GoogleCodeExporter commented 9 years ago
I use set_max_half_open_connections set value to 5 but it does not help. I 
attach an image of process explorer tcp/ip on my application. I have an other 
http client for testing, that receive one byte from server. When libtorrent 
keep connecting, http client take 5s to finish the request, turn off my 
libtorrent, it take < 50ms. That's puzzle me.

Original comment by secm...@gmail.com on 22 Jun 2012 at 9:09

GoogleCodeExporter commented 9 years ago
This is image of process explorer in case of attach image problem,  
http://i124.photobucket.com/albums/p35/secmask/WindowsXPProfessionalSP3-2012-06-
22-16-00-33.png

Original comment by secm...@gmail.com on 22 Jun 2012 at 9:11

GoogleCodeExporter commented 9 years ago
my understanding is that each process has a limit on the half-open connections 
it can have. only if this limit is exceeded by one process, the whole system 
(i.e. all processes) start to be serviced one connection attempt per second (or 
so).

Is that screenshot showing sockets for just libtorrent or all sockets on the 
system? If the latter, I'm not sure what you see indicates a problem with 
half-open connections. The syslog should have an entry telling you if the limit 
was exceeded. There are other reasons why you could be seeing delays of up to 5 
s. One would be if your uplink is saturated and your modem has a large buffer.

Original comment by arvid.no...@gmail.com on 22 Jun 2012 at 3:39

GoogleCodeExporter commented 9 years ago
Hello!
The screenshot is belong to libtorrent process, my http_test only open one 
connection.
But I think that's not per process limit, because right after I close 
libtorrent process, my http_test show a really better response.
System Log have some record such as "TCP/IP has reached the security limit 
imposed on the number of concurrent (incomplete) TCP connect attempts."
Microsoft has a article on this at 
http://www.microsoft.com/technet/support/ee/transform.aspx?ProdName=Windows+Oper
ating+System&ProdVer=5.2&EvtID=4226&EvtSrc=Tcpip&LCID=1033

There are some tools that hack windows tcpip.sys to get a higher upper bound 
limit of half-open connection, but I try to tunning libtorrent before suggest 
my user apply such that tools.

Original comment by secm...@gmail.com on 22 Jun 2012 at 4:04

GoogleCodeExporter commented 9 years ago
ok. renaming ticket. What do you do to trigger this behavior in libtorrent? Do 
you have a sample .torrent file that triggers it?

Original comment by arvid.no...@gmail.com on 22 Jun 2012 at 11:52

GoogleCodeExporter commented 9 years ago
Ok, You can get sample torrents at http://www.mediafire.com/?9b7tcyrmlylgf0g
These torrent have quite many of peers in swarm will easier to trigger the 
problem, I just add them in upload mode with Windows XP.

Thx!

Original comment by secm...@gmail.com on 23 Jun 2012 at 4:21