-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send small blobs inline. #8318
base: master
Are you sure you want to change the base?
Send small blobs inline. #8318
Conversation
Why a new packet instead of sending them in the response message itself? IIRC response packets contain its own format so inline BLOBs can be described individually as strings and then transformed to cached BLOBs on client. |
Vlad, I suppose that content of op_inline_blob is cached by remote provider in order to serve requests for data in that blobs w/o network access. If yes - how long is data in that cache kept? |
Yes, sure. Cached blob is bound to the transaction object and will be released (what happens first):
Note, in the case when user opens the blob with non-empty BPB, cached blob is discarded. |
Imagine RO-RC transaction which leasts VERY long (nothing prevents from keeping it open for client application lifetime). Would not such long life of cache be an overhead? |
It is supposed that cached blobs will be read by application. |
Telling true my first thought was that cache is very tiny - just blobs from last fetched row, but this appears inefficient when we try to support various grids. First of all let's think about binding cache not to transaction but to request/statement. It's hardly typical to close statement and read blobs from it after close. Moreover, in the worst case that will anyway work - in old way over the wire. With limiting cache size arrives one more tunable parameter and I'm afraid there are already too much of them: blob size limit per-attachment or per-statement, may be on per-field basis (at least on/off), default BPB, may be on per-field basis too. (Hmm - are there too many cases when >1 blob per row is returned ?) Last but not least - is blob's inlining enabled by default? On my mind yes, but very reasonable (ie not too big) defaults should be used. |
There should be cache size limits in any case. If you loaded 1000000 records (1 blob per record) at 16K, that's already 16G. But if I understand correctly, this will be provided that the user does not read these cached blobs as the records are fetched. Maybe it's worth limiting the blob cache to some amount, for example 1000 (configurable) and when the number of blobs becomes greater than this value, the oldest of them are removed from the cache. And of course, this should be disabled/enabled at the statement level. And perhaps some |
Yes, it was my thoughts too. Also, consider batch fetching, when whole batch of rows should be read from the wire - it will cache all corresponding blobs anyway.
It was in my very first version of code. Until I started to handle It is possible to mark blobs by
If there will be too many parameters, we can put them into separate dedicated interface, say IClientBlobCache, that will be implemented by Remote provider only. And I'm sure there is applications that have many blobs in its resultsets. Look at monitoring tables, for example: MON$STATEMENTS have two blobs, there are other.
Currently it is enabled - else nobody could be able to test the feature ;) One of the goals of this PR is to discuss and then implement necessary numbers of parameters and corresponding API to customize the blobs cache. So far, I see two really required parameters: 'maximum blob size for inline sending' (per-statement or per-attachment- to be decided, it should be known to the server) and 'size of blob cache' (per-attachment, client-only). Others is 'good to have' but not highly required : BPB, per-field inlining. |
The builds for testing could be found here: |
I tried to conduct experiments on a local network. There are no problems with latency there, however, I will provide some results of the experiment. Run the query in different variants
It contains 66794 small BLOBs. Run IBExpert with this query and do FetchAll Results Firebird-5.0.2.1567-0-9fbd574-windows-x64 (server + client): Results Firebird-6.0.0.526-0-Initial-windows-x64 (server + client): Probably there will be a gain in networks with high latency. I will try to see in the near future. In the meantime, the experiment shows that default blob prefetching is not always useful and at least consumes more memory. PS
Overhead seems quite large to save 6 MB. Am I right in understanding that 16K of memory is always allocated for each BLOB? I also don't know how exactly BLOBs are handled in IBExpert, perhaps it doesn't close a fully read BLOB until the end of the query/transaction. What about the limitation of storing the last N BLOBs in the cache? |
On 11/18/24 16:44, Simonov Denis wrote:
Results Firebird-5.0.2.1567-0-9fbd574-windows-x64 (server + client):
640ms Memory consumption 38 MB (IBExpert)
Results Firebird-6.0.0.526-0-Initial-windows-x64 (server + client):
1s 187ms Memory consumption 385 MB (IBExpert)
Probably you should compare not 6-inline_blobs vs 5 but 6-inline_blobs
vs6-std? FB6 is in pre-alpha state, performance & memory comsumption may
be affected by a lot of other things.
Next, are you sure that in IBE 'FetchAll' loads blobs data from server?
|
Yes, and it was not introduced by this PR. BTW, 66794 blobs should consume near 1GB, while you see about 350MB - what memory counter you look at ?
I doubt IBE reads any blob contents when shows data in grid - until user explicitly ask for it by moving mouse cursor over grid cell or by pressing '...' button in the cell. And debugger confirms it.
It was proposed but we still have not defined what settings and API to manage them we need. Thanks for testing ! |
@AlexPeshkoff : I think the time overhead is related with memory allocations. |
I just looked at the task manager. It is clear that it does not display memory quite correctly, but here the difference is visible to the naked eye. And I have no claims to performance, I understand that slightly different conditions need to be tested (primarily in networks with high latency). Nevertheless, I consider this test useful to understand that without proper settings we can get excessive memory consumption at least. |
As there is no better ideas, I offer following API changes
|
On 11/19/24 18:47, Vlad Khorsun wrote:
As there is no better ideas, I offer following API changes
|interface Statement : ReferenceCounted { ... version: // 6.0 //
Inline blob transfer uint getMaxInlineBlobSize(Status status); void
setMaxInlineBlobSize(Status status, uint size); } |
|interface Attachment : ReferenceCounted { ... version: // 6.0 // Blob
caching by client uint getBlobCacheSize(Status status); void
setBlobCacheSize(Status status, uint size); // Inline blob transfer
uint getMaxInlineBlobSize(Status status); void
setMaxInlineBlobSize(Status status, uint size); } |
ok for me
|
I see no need for new methods in IAttachment, it can be handled by backward-compatible way using DPB and info items unless someone want to make such adjustments dynamically during attachment lifetime. |
The presence of methods in |
…imum size of blob to transfer inline.
New methods was added:
New DPB and info items will be added later, after interface changes above stabilized finally. Common behaviour All methods above is implemented by both
Inline blob size
Also, this value is assigned to the new Default value for inline blob size value is 16KB. To disable inline blob transfer, set inline blob size to zero. Currently, maximum value of inline blob size is not limited. It is open for discussion if some limit should be introduced or not and what value to choose. Obvious value of maximum possible segment size (64KB-2, or 65534 bytes) could be recommended for cursors (many blobs to cache). But in case of single row resultset it is not so obvious. Protocol is not limited by 2-bytes length, if I'm not mistaken. The value of inline blob size is transferred within Client blobs caching The content of inline blobs is cached on the The size of client cache of blobs is limited. Default size is 10MB and can be changed using Note, currently per-blob buffer is pre-allocated and its size is 16KB. It means that smaller blobs requires no additional memory re-allocations but occupy 16KB in memory (and in blobs cache) despite of its real size. I considering changes in this regards. |
The updated builds for testing could be found here: |
I have compiled a small application and tested Firebird 5.0 and 6.0 with different fbclient (parameters were not changed). The following query was tested:
where Record count: 66794 Each test executed the query twice, in the first case the blob itself was not read (only its identifier), in the second case the BLOB was read entirely and closed and the total length of all BLOBs was calculated. In order for the compiler not to optimize the empty loop in the first case, I calculated the code_horse sum. Here are the results I got:
It is clear that inline BLOBs (Firebird 6.0, fbclient 6.0) significantly reduce the time of their full reading, but it also becomes clear that if the blobs themselves are not read, but only their id is read, the reading slows down. This is not surprising given that network packets for sending inline blobs are sent idle. That is why the ability to disable this optimization via parameters is important (BLOBs can be read deferred and it is not known when). fbclient 5.0.2 (BLOB sending optimization) is faster than 5.0.1 by about 30%. |
last test with optimization (
|
@sim1984, many thanks for testing ! At the last test, with setMaxInlineBlobSize(0), there is confusion for 2nd pass (with reading blobs) result: what was the MaxInlineBlobSize value ? |
There is a default value. I just output it. std::cout << std::format("MaxInlineBlobSize = {}", stmt->getMaxInlineBlobSize(status)) << std::endl; |
Yes, I going to change this.
Is it measured fact or just a guess ? Note, blobs cache size is limited by 10MB by default. |
The feature allows to send small blob contents in the same data stream as main resultset.
This lowers number of roundtrips required to get blob data and significantly improves performance on high latency networks.
The blob metadata and data is send using new type of packet
op_inline_blob
and new structureP_INLINE_BLOB
.The
op_inline_blob
packet is send before correspondingop_sql_response
(in case of answer onop_execute2
orop_exec_immediate2
), orop_fetch_response
(answer onop_fetch
).There could be as much
op_inline_blob
packets as number of blob fields in output format.NULL blobs and too big blobs are not sent.
The blob send as a whole, i.e. current implementation doesn't support sending of part of blob. The reasons - attempt to not over-complicate the code and the fact that
seek
is not implemented for segmented blobs.Current, initial, implementation send all blobs that total size is not greater than 16KB.
The open questions is what API changes is required to allow user to customize this process:
Also, will good to have but not required:
This PR currently in draft state and published for the early testers and commenters.