Capstone: Benchmark against real Redis

Ruby is the slowest sibling on this benchmark. The GIL serialises bytecode. For network IO that is mostly fine, but per-op overhead is higher than Go or Rust.

10-capstone/bench.rb
ruby
n.times do |i|
  cmd = encode_array_strings(['SET', "k:#{i}", "v:#{i}"])
  t = Time.now
  sock.write(cmd)
  buf = read_reply(sock, buf)
  sets << ((Time.now - t) * 1_000_000).to_i
end

Sequential RESP load. One TCPSocket, N SETs followed by N GETs.

Ruby's place on the throughput chart

Architecture is identical. Constant factors place Ruby above Python, comparable to Node, below Go/Rust/Elixir.

How to close the gap without changing architecture: pipelined client, hiredis-rb (C-extension RESP parser), Concurrent::Map for lock-free reads, multi-process with TCPServer.fork.

Quiz: Quiz

Loading practice…