From 820c34d5be0b061f26db22c0db30e2353aa0cee4 Mon Sep 17 00:00:00 2001 From: Kenneth Ito Date: Tue, 16 Apr 2024 10:59:01 -0700 Subject: [PATCH] Set connection transport buffer for active socket (#363) Co-authored-by: Andrea Leopardi --- lib/xandra.ex | 4 +++- lib/xandra/connection.ex | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/xandra.ex b/lib/xandra.ex index 3b49474e..a4f0087e 100644 --- a/lib/xandra.ex +++ b/lib/xandra.ex @@ -448,7 +448,9 @@ defmodule Xandra do doc: """ Options to forward to the socket transport. If the `:encryption` option is `true`, then the transport is SSL (see the Erlang `:ssl` module) otherwise it's - TCP (see the `:gen_tcp` Erlang module). + TCP (see the `:gen_tcp` Erlang module). The `:buffer` option (`t:pos_integer/0`), + which controls the size of the user level buffer in use by the active mode + socket, defaults to `1_000_000` bytes. """ ], diff --git a/lib/xandra/connection.ex b/lib/xandra/connection.ex index 1c284f23..8e933833 100644 --- a/lib/xandra/connection.ex +++ b/lib/xandra/connection.ex @@ -19,6 +19,10 @@ defmodule Xandra.Connection do @forced_transport_options [packet: :raw, mode: :binary, active: false] + # The default size of the user-level buffer used by the driver + # We will receive at most this many bytes from the active mode socket + @default_transport_buffer_size 1_000_000 + # How old a timed-out stream ID can be before we flush it. @max_timed_out_stream_id_age_in_millisec :timer.minutes(5) @@ -410,6 +414,7 @@ defmodule Xandra.Connection do options: options |> Keyword.get(:transport_options, []) + |> Keyword.put_new(:buffer, @default_transport_buffer_size) |> Keyword.merge(@forced_transport_options) }