English 中文(简体)
基准中的许多部队派遣国未能适当接近
原标题:Many TCPClients in benchmark do not close properly

I m currently programing a benchmark for my TCP-Socket Server. The basic concept is the following:

  • The Client creates 10000 connections
  • There are 2500 connections concurrent
  • They all send 10 seconds ping-pong messages to the server and receive the pong
  • After the 10 seconds they all disconnect

When I use smaller numbers of connections (100 concurrent and 1000 connections) everything works fine, but with the setup above, some of the connections remain connected at the server. This means that the close call never reaches the server at all.

以上解释守则:

    class Program {   
    static List<Thread> mConnectionThreads_ = new List<Thread>();                  //!< The list of the Threads for all textloaders
    static List<TCPConnection> mConnections_ = new List<TCPConnection>();         //!< The list of TextsXMLParser

    static void Main(string[] args) {
        int numConnections = 10000;
        int numConcurrentConnections = 2500;
        for( int k = 0; k < numConnections/numConcurrentConnections; ++k) {
            for( int i = 0; i < numConcurrentConnections; ++i ) {
                TCPConnection connection = new TCPConnection();
                connection.connect(((k+1)*numConcurrentConnections)+i);
                mConnections_.Add(connection);
                mConnectionThreads_.Add(new Thread(connection.pingLoop));
            }
            Console.WriteLine(((k+1)*numConcurrentConnections) + "/" + numConnections + " Threads connected");

            // start all threads
            foreach (Thread t in mConnectionThreads_)
                t.Start();

            foreach (Thread t in mConnectionThreads_)
                t.Join();
            foreach (TCPConnection c in mConnections_)
                c.disconnect();
            Console.WriteLine(((k+1)*numConcurrentConnections) + "/" + numConnections + " Threads disconnected " + cnt + " calls");
            mConnections_.Clear();
            mConnectionThreads_.Clear();
        }
    }
}

脱节的职能如下:

    public void disconnect() {
        if(  mClient_.Client != null ) {
            mClient_.Client.Disconnect(false);
            //mClient_.GetStream().Close();
            //mClient_.Close();
            Console.WriteLine("closed " + mConnectionId_);
        }
        else if( mClient_.Client == null )
            Console.WriteLine("closed invalid " + mConnectionId_);
    }

你可以看到,我已经尝试了许多不同的近距离方法,但 ne干。

在这种情况下,我怎么办? 是否有其他人有同样的问题?

问题回答

可是,我没有什么东西,但哪一类人有危险?

通常,如果你使用TCP客户(TCPClient阶层)的话,你就可以近距离联系。 同样,在直接使用Socket或网络Stream时,你也可以说近距离。

On the other hand you re detecting and debugging connection open/closed connections on the server, right? There can be the possibility that server code does not handle connection close properly and thus you get incorrect statistics.

同样在重负荷下,服务器可能没有足够的时间更新连接状态,以便你预计会出现一些延误。 贵服务器是否使用超常的I/O或按直线原则连接?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签