Skip to content

Commit 2ba5a21

Browse files
committed
Update send_file callback to save a system call
The callback is used in RabbitMQ to send the frame header. This commit changes the callback to expect a binary result and to send it along the chunk header. This saves a system call and improves performance with small chunks.
1 parent 0384060 commit 2ba5a21

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/osiris_log.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,10 +1649,10 @@ is_valid_chunk_on_disk(SegFile, Pos) ->
16491649
{error, term()} |
16501650
{end_of_stream, state()}.
16511651
send_file(Sock, State) ->
1652-
send_file(Sock, State, fun(_, _) -> ok end).
1652+
send_file(Sock, State, fun(_, _) -> <<>> end).
16531653

16541654
-spec send_file(gen_tcp:socket() | ssl:socket(), state(),
1655-
fun((header_map(), non_neg_integer()) -> term())) ->
1655+
fun((header_map(), non_neg_integer()) -> binary())) ->
16561656
{ok, state()} |
16571657
{error, term()} |
16581658
{end_of_stream, state()}.
@@ -1693,8 +1693,8 @@ send_file(Sock,
16931693
%% or the chunk is a user type (for offset readers)
16941694
case needs_handling(RType, Selector, ChType) of
16951695
true ->
1696-
_ = Callback(Header, ToSend + byte_size(HeaderData)),
1697-
case send(Transport, Sock, HeaderData) of
1696+
FrameHeader = Callback(Header, ToSend + byte_size(HeaderData)),
1697+
case send(Transport, Sock, [FrameHeader, HeaderData]) of
16981698
ok ->
16991699
case sendfile(Transport, Fd, Sock,
17001700
Pos + ?HEADER_SIZE_B + ToSkip, ToSend) of

0 commit comments

Comments
 (0)