Delphi + Indy causes high page fault and RAM usage
Asked Answered
E

1

8

I experience one weird problem.

I use Delphi and Indy to upload and backup some files. It runs just fine on many computers (Win7 64bit, WinXP) . CPU usage is less then 1% and max. 20MB in RAM.

But there is one computer (Win 2008 R2) where it is problematic and I can't find out why. CPU usage is 5-20%, it takes 100MB+ in RAM and it increases a lot. Furthemore "page fault" rises a lot, eg. 100 000 every second (not increasing on my computer)

Code is very simple

var
  IdHTTP: TIdHTTP;
  IdPostData: TIdMultiPartFormDataStream;
  sResponse: string;
begin
  IdHTTP := TIdHTTP.Create(nil);
  IdPostData:=TIdMultiPartFormDataStream.Create;

  try
    IdPostData.AddFile('file', 'C:\data.dat', '');

    sResponse:=IdHTTP.Post('http://web.com', IdPostData);

    ShowMessage(sResponse);
  finally
    IdHTTP.Free;
    IdPostData.Free;
  end;
end;

Does anybody have any idea why "page fault" increases that a lot? Is it possible that there is some hardware issue? How to find it?

Epiboly answered 5/2, 2014 at 17:54 Comment(10)
Maybe a silly suggestion but the first place I would start looking at with a problem like this is the antivirus and potentially any viruses on the PC.Authoritative
Page Faults generally mean that reserved but uncommitted memory is being accessed so the OS has to commit the memory for use. The OS uses that for dynamically growing a thread's available stack space, for instance. But that would only apply for large amounts of stack usage (the default min stack size is 1MB and the default max size is 4MB), but most things in Delphi use heap memory instead of stack memory. And there should definitely not be 100+ MB of memory being used. That suggests a leak/fragmentation is occurring, but nothing in the code you showed would cause that.Firearm
Is it possible that some specific hardware malfunction would cause that? Does OS report it anywhere?Epiboly
I would transmit the file with no file extension then do a rename when the transmission is complete. It might be some shadow-backup service or restore-point-creating shananigans!Cynthiacynthie
I tried a file without extension, no change. Furthemore, when I use larger upload buffer size, it goes crazy much faster. var FStack: TIdIOHandlerStack; FHTTP.IOHandler:=FStack; FStack.SendBufferSize:=512*1024; //512kB buffer Every second +10MB in RAMEpiboly
Perhaps this or something like it is your problem support.microsoft.com/kb/976658Authoritative
What version of Delphi and which memory manager are you using?Oops
Ensure that all updates are installed on your Windows 2008 Server.Bullet
How big is the file you are trying to transmit on that machine?Harkey
100MB-1GB ... bigger file means bigger usage. But I can't test it right now, I don't have a computer with Win2008 right now. Maybe it is really an issue with some Windows update.Epiboly
J
1

just put "IdHttp := nil; IdPostData:=nil; sResponse := 'Ok'; " before "try" clause and try again

--reviewed-- Changed your code a little bit

procedure SendFile;
var
  IdHTTP: TIdHTTP;
  IdPostData: TIdMultiPartFormDataStream;
  sResponse: string;
begin
  sResponse := 'OK';
  IdHTTP := TIdHTTP.Create(nil);
  IdPostData:=TIdMultiPartFormDataStream.Create;
  try
    IdPostData.AddFile('C:\data.dat', 'data.dat', '');

    IdHTTP.Post('http://www.yahoo.com', IdPostData);

    ShowMessage(sResponse);
  finally
    IdHTTP.Free;
    IdPostData.Free;
  end;
end;
Jethro answered 5/2, 2014 at 17:55 Comment(6)
I don't have to do that to see that it does not make any difference. Those variables are already nil at the beginning ;)Epiboly
delphi does not initialize local variables by default, you have to initialize them first, then variable can be ready for using. please check #133225Jethro
my experience approves "Local non reference-counted* variables are uninitialized so you have to assign a value before you can use them." lineJethro
@Jethro You are correct that the code in the question places the try in the wrong place. But that's a side issue from the point of the question.Doubloon
@Epiboly in debugging mode local variables are initialized in some versions of delphi but not in the compiled executable. (I don't have the latest DEPLPHI versions available for testing.)Niece
Stop talking about initialization. Objects are initialized when they are created, local reference-counted variables are also initialized automatically. The only problem was with "try" in the wrong place and that does not influence the problem with high CPU and memory usage.Epiboly

© 2022 - 2024 — McMap. All rights reserved.