呵呵,我测试过啦,说实在的我倒是觉得很搞笑的,为了更好的测试你的 Server 的负载,我重新写过测试客户端和把服务器端改成你说的这种测试规则,其客户端核心代码如下,还有在你的这种测试模式之下,要达到每秒响应 1 万多次的请求本来就是很简单的,在这种测试方法实际上成啦测试 CPU 的速度以及网络 Send 和 Receive的速度罢了。
procedure TThreadConnections.Execute;
var
buf: Array[0..127] of char;
begin
try
while not Terminated do
begin
if not Assigned(FClientSocket) then
begin
FClientSocket := TTcpClient.Create(nil);
FClientSocket.RemotePort := FRemotePort;
FClientSocket.RemoteHost := FRemoteAddress;
FClientSocket.Open;
Inc(iCount);
end else
if FClientSocket.Connected then
begin
FillChar(Buf, SizeOf(Buf), #0);
FClientSocket.Sendln(IntToStr(ThreadID) + ' : Open:' + IntToStr(iCount));
Synchronize(AddResult);
FClientSocket.ReceiveBuf(buf, SizeOf(buf));
FRecvStr := Buf;
Synchronize(AddResult);
if FClientSocket.Handle = -1 then
begin
FClientSocket.Close;
FreeAndNil(FClientSocket);
end;
end
end;
except
raise ;
end;
end;