title: Delphi (DataSnap) Slow
body: <p>I have recently started using DataSnap in Delphi to produce what will be a RESTful web service. After following guides by the man himself Marco Cantu and several others on the internet I have successfully got the whole 'chain' working.</p>
  
  <p>But there is a small issue of speed; the client can now send a stream (along with it's size) to the server (which, because of the bug here <a href="https://stackoverflow.com/questions/12097470/datasnap-xe2-and-tstream-method-parameters/12099038#12099038">DataSnap XE2 and TStream method parameters</a>, is read upto the sent size), and the server will reassemble it into a file and save it on disk.</p>
  
  <p>But foir a 3.66MiB file, this takes over 50 seconds!</p>
  
  <p>Should this be the case? On the server I have:</p>
  
  <pre><code>try
     F := TFileStream.Create('written.dat', fmCreate);
     F.Position := 0;
     F.CopyFrom(Data, DataSize);
  finally 
     F.Free; 
  </code></pre>
  
  <p>And on the client end:</p>
  
  <pre><code>var
    Server: TServerMethods1Client;
    DBStream: TFileStream;
  begin
    Server := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
    try
      DBStream := TFileStream.Create('DataSnapServer.exe', fmOpenRead);
      DBStream.Position := 0;
      Showmessage(IntToStr(Server.SendData(DBStream, DBStream.Size)));
    finally
      Server.Free;
  </code></pre>
  
  <p>Any help appreciated!</p>
  
  <p>Cheers,
  Adrian</p>