Skip to content

Support higher maximum blob segment size #1197

Description

@mrotteveel

Currently, the blob segment size is controlled by the connection property PacketSize, and this has a maximum value of 32767 (bytes). However, since Firebird 2.1, segment sizes of 64KiB - 1 are supported (though Firebird 2.1 and 2.5 have some issues because sometimes the value is cast to a SSHORT, as far as I know, Firebird 3.0 is the first where it really works).

There are some oddities with this maximum, because for op_get_segment the maximum is also the maximum size of the buffer used for transferring, so the largest value you can receive with op_get_segment when asking for 65535 is actually 65533 (and if the response is broken up in multiple segments, it can even be multiples of 2 shorter) because of the 2-byte length prefixes in the response buffer. When sending (op_put_segment), the maximum is 65535 bytes.

Support a larger maximum value, so blobs can be transferred more efficiently, at least for Firebird 3.0 and higher, and also consider deprecating PacketSize, and/or introduce an alternative property called BlobSegmentSize, as that seems to be the only thing controlled by PacketSize.

Activity

  1. self-assigned this
    on Nov 7, 2024
  2. vmzubov commented on Nov 22, 2026

    @vmzubov

    One thing that bears on this: PacketSize is not only the blob segment size. It is also the size of the socket buffers, and over a link with noticeable latency that makes it the main limit on fetch speed.

    GdsConnection.Connect and ConnectAsync (10.3.4, the same on master):

    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, PacketSize);
    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, PacketSize);

    A receive buffer set by hand switches off the system's receive window auto-tuning for that socket, so the TCP window stays at about PacketSize. The server cannot have more than that in flight, and throughput is capped at roughly PacketSize / round-trip time, whatever the bandwidth. With the default of 8192 and a 75 ms round trip that is about 100 KB/s. On a LAN it does not show, because the round trip is a fraction of a millisecond.

    What I measured against Firebird 5.0: Windows client, a VPN link with a 75 ms round trip (ping), one query returning 29,000 rows with two CHAR(63) UTF8 columns, no compression, the four runs one after another on an otherwise idle link. "Without the two lines" is 10.3.4 built from the FirebirdClient-10.3.4.0 tag with those SetSocketOption calls removed from Connect and ConnectAsync, nothing else changed.

    PacketSize 8192 (default) PacketSize 32767
    10.3.4 163 s 54 s
    10.3.4 without the two lines 20 s 23 s

    The output is byte for byte the same in all four. For comparison, the same query through fbclient (ServerType=Embedded + ClientLibrary) took 17-23 s on that link: fbclient sets only TCP_NODELAY and SO_KEEPALIVE on its socket and leaves the buffers to the system (src/remote/inet.cpp), so its window grows as far as the link allows.

    So if PacketSize is deprecated or gets another meaning here, the socket buffers need a decision of their own. The simplest would be not to set ReceiveBuffer and SendBuffer at all, as fbclient does. Raising the limit to 65535 would help a distant link too, but would still cap it.

    I can open a pull request with that change if it is the direction you want.

    The analysis was done with the help of an AI assistant (Claude).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions