【问题标题】:why is datasnap http much slower than tcp/ip为什么datasnap http比tcp/ip慢得多
【发布时间】:2015-02-09 08:01:03
【问题描述】:

您好,我已经编写了一个客户端服务器应用程序来将文件从服务器流式传输到客户端。该代码在我的测试中非常基本:

服务器代码(它是作为服务或应用程序运行的可执行文件)

function TServerMethods1.DownloadFile(sFile:String; out iOut:Int64): TStream;
begin
  iOut := -1;
  result := TFileStream.Create(sFile, fmOpenRead or fmShareDenyNone);
  iOut := result.Size;
  TFileStream(Result).Seek(0, TSeekOrigin.soBeginning);
end;

客户端代码

procedure TForm1.DownloadFileStabiel(sSourceFile,sTargetFile:String);
var
    RetStream: TStream;
    fs:TFileStream;
    oServerMethodsClient:TServerMethods1Client;
    iOut:Int64;
begin
  ClientModule1.SQLConnection1.Connected:=True;
  oServerMethodsClient := nil;

  try
    try
      oServerMethodsClient := TServerMethods1Client.Create(ClientModule1.SQLConnection1.DBXConnection, True);
      RetStream := oServerMethodsClient.DownloadFile(sSourceFile,iOut);

      fs := TFileStream.Create(sTargetFile, fmCreate);

      fs.CopyFrom(retstream,iOut);

      showmessage('Klaar');

    except
      on E: Exception do
      begin
        showmessage('Oeps download: ' + E.Message);
      end;
    end;

  finally

    ClientModule1.SQLConnection1.Connected:=False;

    FreeAndNIl(fs);
    FreeAndNil(oServerMethodsClient);
  end;
end;

在实际应用程序中,我做的事情有点不同,我实现了文件块和进度条等。对于速度问题,它没有区别。

在客户端我使用 TSQLConnection,在服务器上使用 TDSTCPServerTransport 和 TDSHTTPService

当我使用 http 流式传输文件时,它永远不会超过 1Mb/s,而当我使用 tcp/ip 流式传输时,它的速度与服务器可以处理它的 i/o 一样快,大约 30a50 Mb/s

我尝试了不同的服务器,但总是看到相同的速度差异因素。我尝试了不同的操作系统,windows server 2003、2008、2012、windows 7。在同一台机器或不同机器上运行客户端和服务器也没有什么区别。

你能帮帮我吗?我原本打算使用 https,但现在我卡在 tcp/ip

【问题讨论】:

    标签: client-server performance-testing delphi-xe5 datasnap


    【解决方案1】:

    虽然 datasnap 的速度并不出名,但我认为在这种情况下,将 TCP/IP 传输与 HTTP 传输进行比较是不公平的。 HTTP 开销很大,必须进行文件编码/解码。

    要检查瓶颈是否是 DataSnap,请尝试使用普通 HTTP 服务器 (Indy) 进行传输,并将该速度与使用 Datasnap 获得的速度进行比较。

    【讨论】:

      【解决方案2】:

      我刚刚尝试使用普通的 indy 服务器可执行文件和客户端可执行文件,使用 indy 它非常快....现在我对 Datasnap 感到沮丧。差别这么大!!

      服务器:

      procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
        ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
      begin
        aResponseInfo.ContentStream := TFileStream.Create('D:\Software\NKDataSnap\voerexpert.zip', fmOpenRead or fmShareDenyNone);
      end;
      

      客户:

      procedure TForm1.Button1Click(Sender: TObject);
      var strm:TFileStream;
      begin
        strm := TFileStream.Create('c:\temp\temp.zip',fmCreate);
        IdHTTP1.Get('http://myserver',strm);
        strm.Free;
      end;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-26
        • 2011-01-25
        • 2012-12-20
        • 1970-01-01
        • 1970-01-01
        • 2017-05-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多