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?

smooty86
  • 1,112
  • 7
  • 13
  • 2
    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. – Graymatter Feb 05 '14 at 19:08
  • 3
    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. – Remy Lebeau Feb 05 '14 at 19:18
  • Is it possible that some specific hardware malfunction would cause that? Does OS report it anywhere? – smooty86 Feb 05 '14 at 20:12
  • 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! – Sam Feb 06 '14 at 09:27
  • 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 RAM – smooty86 Feb 06 '14 at 15:17
  • Perhaps this or something like it is your problem http://support.microsoft.com/kb/976658 – Graymatter Feb 06 '14 at 23:48
  • What version of Delphi and which memory manager are you using? – oɔɯǝɹ Feb 22 '14 at 21:27
  • Ensure that all updates are installed on your Windows 2008 Server. – Steve F Mar 12 '14 at 18:23
  • How big is the file you are trying to transmit on that machine? – nobody May 13 '14 at 20:51
  • 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. – smooty86 May 25 '14 at 14:02

1 Answers1

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;
Onur
  • 852
  • 9
  • 18
  • I don't have to do that to see that it does not make any difference. Those variables are already nil at the beginning ;) – smooty86 Aug 31 '14 at 13:55
  • delphi does not initialize local variables by default, you have to initialize them first, then variable can be ready for using. please check http://stackoverflow.com/questions/132725/are-delphi-variables-initialized-with-a-value-by-default – Onur Nov 28 '14 at 07:52
  • my experience approves "Local non reference-counted* variables are uninitialized so you have to assign a value before you can use them." line – Onur Nov 28 '14 at 07:57
  • @Onur 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. – David Heffernan Nov 28 '14 at 08:06
  • @smooty86 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.) – hy-soft Mar 14 '15 at 19:58
  • 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. – smooty86 Mar 14 '15 at 22:33