You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何优化Firebird ADO.NET Provider性能?最优FetchSize是多少?

Firebird查询FetchSize最优配置探讨

测试场景与初始性能对比

同一电脑通过LAN访问同一Firebird数据库,分别使用两种技术栈执行相同查询,性能差异明显:

.NET实现(VS2022 + .NET8 + FirebirdSql.Data.FirebirdClient 10.0.0)

测试代码:

using FirebirdSql.Data.FirebirdClient;
using System.Diagnostics;
using System.Text;

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

var csb = new FbConnectionStringBuilder();
csb.Database = ...;
csb.DataSource = ...;
csb.Dialect = 1;
csb.Charset = "WIN1250";
csb.Pooling = true;
csb.Port = 3050;
csb.IsolationLevel = System.Data.IsolationLevel.ReadCommitted;
csb.UserID = ...;
csb.Password = ...;

using(var connection = new FbConnection(csb.ConnectionString))
{
    connection.Open();
    var cmd = new FbCommand("SELECT ID FROM SOMETABLE", connection);
    using(var r = cmd.ExecuteReader())
    {
        int cnt = 0;
        var s = new Stopwatch();
        s.Start();
        while(r.Read())
        {
            cnt++;
        }
        s.Stop();
        Console.WriteLine($"{cnt} in {s.ElapsedMilliseconds}ms");
    }
}

测试结果:

69790 in 365ms
69790 in 380ms
69790 in 355ms
...

Delphi实现(Delphi5 + IBX 5.0.4)

测试代码:

procedure TForm1.Button1Click(Sender: TObject);
var cnt : Integer;
    c : DWord;
begin
  IBDatabase1.Open;
  IBTransaction1.StartTransaction;
  IBSQL1.ExecQuery;
  cnt := 0;
  c := timeGetTime;
  While not IBSQL1.Eof do
    Begin
      cnt := cnt + 1;
      IBSQL1.Next;
    End;
  ShowMessage(IntToStr(cnt) + ' in ' + IntToStr(timeGetTime - c) + 'ms');
  IBSQL1.Close;
  IBTransaction1.Commit;
  IBDatabase1.Close;
end;

测试结果:

69790 in 168ms
69790 in 183ms
69790 in 169ms

多次测试显示,.NET版本的查询速度仅为Delphi版本的一半左右。

参数调整后的性能变化

针对连接参数调整后,得到以下性能数据:

csb.PacketSize: 默认值 8192
- 调小至1024:耗时 >60000ms
- 调至最大值32767:耗时 ~390ms

csb.FetchSize: 默认值200
- 调小至100:耗时 ~600ms
- 调至1000-1500:耗时 ~200ms!
- 调至2000及以上:耗时 ~250ms+

问题

是否存在最优的FetchSize配置值?


内容的提问来源于stack exchange,提问作者b0bik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 19:20:05