Skip to content

Commit c358351

Browse files
committed
fix: improve command execution speed
Command execution speed gets a significant speed boost by avoiding multiple small writes to the socket connection. Using an IOBuffer to collect the command args and do a single socket write. Also turned off nagle and turned on quickack on sockets, suitable for the typically short and quick exchanges needed here.
1 parent cd48768 commit c358351

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/connection.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ function SubscriptionConnection(parent::SubscribableConnection)
101101
end
102102

103103
function on_connect(conn::RedisConnectionBase)
104+
# disable nagle and enable quickack to speed up the usually small exchanges
105+
Sockets.nagle(conn.socket, false)
106+
Sockets.quickack(conn.socket, true)
107+
104108
conn.password != "" && auth(conn, conn.password)
105109
conn.db != 0 && select(conn, conn.db)
106110
conn

src/parser.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ end
8888

8989
function execute_command_without_reply(conn::RedisConnectionBase, command)
9090
is_connected(conn) || throw(ConnectionException("Socket is disconnected"))
91-
lock(conn.socket.lock) do
92-
pack_command(conn.socket, command)
91+
iob = IOBuffer()
92+
pack_command(iob, command)
93+
lock(conn.socket.lock) do
94+
write(conn.socket, take!(iob))
9395
end
9496
end
9597

0 commit comments

Comments
 (0)