Multithreaded WinHttp downloads

I am creating a Delphi application to download files from the Internet, and if the server supports a range request, it will be multithreaded. Progress is also transferred back to the graphical interface.

The current software model uses components TThread. The GUI calls TDownloadThread, which then spawns TDownloadPartThreads- these are the threads that actually load through "WinHttp".

My problem . The CPU is used even for a single load, where only 4 threads are loaded.

My alleged reasons:

  • I write to the destination file every 8192 bytes and I wonder if I should buffer it before writing in one block?
  • The exchange of threads is done through Synchronize(MainForm.UpdateProgress(Downloaded, TotalSize))which, as I heard, AWFUL, maybe I need to share an object between threads so that I can access it using a timer in the main form, to update the progress?

My decisions

  • Mark up the file entry and write only every xbyte.

  • Update the components TThreadto use OmniThreadLibraryand submit the data back to the main form. Each thread TDownloadPartwould become IOmniWorkerand send back its progress, sharing the object with the main form. The main form will then use a timer to update its progress, for example:ProgressBar1.Position := sharedDataObject.Progress;

Hope someone can point me in the right direction!

+5
4

- , . 8- (4 !) , , 8-, , .

- TGp8AlignedInt64 GpStuff, OmniThreadLibrary- TThread .

TGp8AlignedInt64 = record
  function  Add(value: int64): int64; inline;
  function  Addr: PInt64; inline;
  function  CAS(oldValue, newValue: int64): boolean;
  function  Decrement: int64; overload; inline;
  function  Decrement(value: int64): int64; overload; inline;
  function  Increment: int64; overload; inline;
  function  Increment(value: int64): int64; overload; inline;
  function  Subtract(value: int64): int64; inline;
  property Value: int64 read GetValue write SetValue;
end; 

, .Add . .

+2

Yup - GUI. TThread.Synchronize - - , GUI , . - PostMessaging, - , , , , 10000 WMQ . , , , - -///- .

+1

- "" , , , . , .

WinHTTP CPU . , WinINet, ( , C API - COM-?). , - .

:

  • 8192 ( HTTP-), . Windows 4 . (, 65536), , .

  • Synchronize . , (, 5% 10%) . , , .

(DownloadedSize + TotalSize: Int64) , . TTimer - (WM_USER+...), PostMessage() - GUI, , , . .

+1

Synchronize() , , , CPU. , , , GUI.

, , . , .

, .

, , , , ? , ? ?

, , , - ? ?

, .

, - , , , .

+1

All Articles