开发者

SharpSVN connection rate limit to localhost?

We use SharpSVN to programmatically access SVN repositories. Now we have the problem that the access to local repositories via svn:// or http:// urls is very slow - every access needs at least one second, and our app needs to fetch a bunch of properties and directory listings.

We could reproduce the problem on two different machines, both are Windows 7 32 bit and are in the same domain. The SVN servers are VisualSVN 2.1.9 for http:// urls and the CollabNet 1.6.17 for svn:// urls. It appears for connections via "localhost" and via the host name. It appears in our C# application, as well as a small testbed app using IronPython and when calling the SharpSvn svn.exe command.

This problem does not happen when accessing when accessing remote repositories (Both a linux and a windows XP server) - here, each access is between 0.01 and 0.08 secs, which is expected due to network latency. The Problem also does not happen when acessing the local repositories via file:// urls or when accessing the repositories via "native" svn command line tools from CollabNet.

Now my question is: Has Windows 7 or .NET or SharpSVN some built-in limit which only applies to localhost connections?

(Addition: I now found out that this limit also applies when connecting via a small C# test program using System.Net.Sockets.TcpClient:

Server:

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace TcpSpeedServer
{
    class Program
    {
        public static void Main()
        {
            Int32 port = 47011;
            IPAddress localAddr = IPAddress.Parse("127.0.0.1");

            var server = new TcpListener(localAddr, port);
            server.Start();

            Console.WriteLine("Listening on {0} : {1}", localAddr, port);

            ulong count = 0;
            // Enter the listening loop.
            while(true)
            {
                using (var client = server.AcceptTcpClient()) {
                    Console.WriteLine("Connected: {0} {1}!", count, client.Client.RemoteEndPoint);
                    count += 1;

                    using (var stream = client开发者_运维问答.GetStream()) {
                        using (StreamWriter writer = new StreamWriter(stream))
                            using (StreamReader reader = new StreamReader(stream))
                        {
                            string query = reader.ReadLine();
                            writer.WriteLine("GET / HTTP/1.0");
                            writer.WriteLine();
                            writer.Flush();
                        }
                    }
                }
            }
        }
    }
}

Client:

using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using System.Threading;

namespace TcpSpeedTest
{
    class Program
    {
        const bool ASYNC = false;
        static DateTime s_now;
        public static void Main(string[] args)
        {
            var liste = new List<object>();
            s_now = DateTime.Now;
            for (int i=0; i < 100; i += 1) {
                if (ASYNC)
                    ThreadPool.QueueUserWorkItem(connect, i);               
                else
                    connect(i);
            }

            Console.WriteLine("outer: " + (DateTime.Now - s_now));
            Console.ReadLine();
        }

        private static void connect(object i)
        {
            DateTime now = DateTime.Now;

            using (TcpClient client = new TcpClient("localhost", 47011))
            {
                var stream = client.GetStream();
                using (StreamWriter writer = new StreamWriter(stream))
                    using (StreamReader reader = new StreamReader(stream))
                {
                    writer.WriteLine("GET / HTTP/1.0");
                    writer.WriteLine();
                    writer.Flush();
                    string result = reader.ReadLine();
                }
            }
            Console.WriteLine(string.Format("inner: {0} - {1} - {2}", i, DateTime.Now - now, DateTime.Now - s_now));
        }
    }
}

So this problem seems not to be subversion specific.)

Addition2: When running the client under Mono 2.10 for windows, the problem does not appear. So it seems to be specific to .NET framework.

Addition3: It seems to be an IPv6 related problem. The server only listens on IPv4, but the hostname also resolves to IPv6. Now it seems that the OS code internally tries the IPv6 connection, and after getting the connection reset, waits 1 sec before falling back to IPv4. And this game is repeated for every single connection attempt. http://msdn.microsoft.com/en-us/library/115ytk56.aspx documents that for TcpClient (thanks to Andreas Johansson from the MSDN forums for the hint!), and it seems that the APR used by Apache internally uses a similar mechanism.


Addition 3 is also the solution to your problem. To fix this, either make DNS/hosts file only resolve to an IPv4 address, or make the IPv6 server(s) work.

You can enter in C:\Windows\System32\drivers\etc\hosts something like:

127.0.0.1 localhost-ipv4

And then use that name to connect.

You can also make svnserve listen to IPv6 addresses. A quick search for svnserve options [revealed][1] that it defaults to IPv6, so in its startup parameters is probably a --listen-host. Try removing that, or when it's not present forcing it to run at IPv6.

The same can be done for the Apache webserver:

Listen 0.0.0.0:80
Listen [::]:80
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜