【发布时间】:2021-09-30 15:59:50
【问题描述】:
我本地化了我的 Delphi 服务应用程序的问题。
现在我有一台装有 Windows Server 2019、RDP 的测试服务器。
简单的测试代码,连接本地TCP服务器并断开连接:
for i := 1 to 1000000 div 100 do
begin
sleep(100);
Caption := 'STRESS TEST: ' + inttostr(i * 100);
Application.ProcessMessages;
for j := 1 to 100 do
begin
thread := TThread.CreateAnonymousThread(
procedure
Var tcpClient : TIdTcpClient;
begin
try
tcpClient := TIdTCPClient.Create(nil);
tcpClient.Host := '127.0.0.1';
tcpClient.Port := RollControl_Svc.TCPServer.Bindings[0].Port
tcpClient.Connect;
tcpClient.IOHandler.ReadTimeout := 1000;
finally
FreeAndNil(tcpClient);
end;
end);
thread.FreeOnTerminate := (j > 1) and (j < 100);
if thread.FreeOnTerminate then thread.Start else
begin
thread.Start;
thread.WaitFor;
thread.Free;
end;
end;
在测试机上运行20K后,出现错误:
Thread creation error: Not enough memory resources are available to process this command.
在我使用机器时,一切都很好,已经完成了 100 万次操作。我有 Delphi XE3,最新的 Indy 版本,怎么了?也许在 RDP 中工作时有一些特殊性?
【问题讨论】:
-
"What's wrong?" - 错误信息很准确:对于您正在运行的进程,内存是有限的,并且您占用的内存太多,应该释放一些在要求更多之前再一次。想想你的“我的工作”机器有 16 GiB 的 RAM,而“测试服务器”只有 512 MiB 的 RAM。而服务在上面有更严格的限制。
-
内存中的进程没有增长,它的大小只有100M。没有内存泄漏,句柄和线程的数量没有增加。在一个机器上它工作正常,第二个崩溃了这个错误
-
你的代码中有很多奇怪的东西。让我只提其中一个:
tcpClient := TIdTCPClient.Create(nil);必须是try之前的行。 -
@Andreas Rejbrand 我同意,但这不会影响问题。我移动了 tcpClient := TIdTCPClient.Create(nil);退出尝试块,问题没有消失
-
@НиколайНевзоров:我知道。