1

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.

MarkusSchaber
  • 757
  • 1
  • 8
  • 16
  • Have you tried analysing network traffic using Wireshark or Micrsoft Network Monitor? It could well be that the server attempts to get additional user information and times out, or something similar. – Thomas Gerstendörfer Jul 13 '11 at 14:15
  • @Thomas: I don't think that the server does such attempts, as this would also affect the native svn.exe. And I just tried two small C# test programs using TcpClient and TcpListener - the same 1 second delay on each connection. – MarkusSchaber Jul 13 '11 at 14:45
  • Have you tried disabling your antivirus client during a test? – Lasse V. Karlsen Jul 14 '11 at 12:37
  • I did, and it did not solve the problem. – MarkusSchaber Jul 15 '11 at 12:47

1 Answers1

2

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
Sander Rijken
  • 21,376
  • 3
  • 61
  • 85
  • Thanks for the hints. I doubt that we can ask users of our software to mess in a windows internal hosts file (most of them are in corporate environment and don't necessarily have admin rights). But documenting the fact that the SVN server should prefer IPV6 in an IPV6 enabled environment is a good idea. Alghough I fear that there are networks where the hosts can resolve IPv6 addresses, but the routers don't pass IPv6 packets... – MarkusSchaber Jul 17 '11 at 18:09