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干。
在这种情况下,我怎么办? 是否有其他人有同样的问题?