Skip to content

Commit

Permalink
improvements on bench and add multi to profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
danmayer committed Feb 3, 2025
1 parent 6fdc9b4 commit f529213
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
6 changes: 2 additions & 4 deletions bin/benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ bench_target = ENV['BENCH_TARGET'] || 'set'
bench_time = (ENV['BENCH_TIME'] || 10).to_i
bench_warmup = (ENV['BENCH_WARMUP'] || 3).to_i
bench_payload_size = (ENV['BENCH_PAYLOAD_SIZE'] || 700_000).to_i
payload = 'B' * bench_payload_size
TERMINATOR = "\r\n"
puts "yjit: #{RubyVM::YJIT.enabled?}"

client = Dalli::Client.new('localhost', serializer: StringSerializer, compress: false)
multi_client = Dalli::Client.new('localhost:112111,localhost:11222', serializer: StringSerializer, compress: false)
multi_client = Dalli::Client.new('localhost:11211,localhost:11222', serializer: StringSerializer, compress: false)
string_client = Dalli::Client.new('localhost', serializer: StringSerializer, compress: false)
# The raw socket implementation is used to benchmark the performance of dalli & the overhead of the various abstractions
# in the library.
Expand All @@ -58,9 +59,6 @@ sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
# Benchamrks did see an improvement in performance when increasing the SO_SNDBUF buffer size
sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, 1024 * 1024 * 8)

TERMINATOR = "\r\n"
payload = 'B' * bench_payload_size

# ensure the clients are all connected and working
client.set('key', payload)
string_client.set('string_key', payload)
Expand Down
44 changes: 42 additions & 2 deletions bin/profile
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,30 @@ def sock_get_multi(sock, pairs)
next unless line.start_with?('VA ') || last_result

_, value_length, _flags, key = line.split
value = sock.read(value_length.to_i + TERMINATOR.length)
results[key[1..]] = value.chomp!(0..-TERMINATOR.length)
results[key[1..]] = sock.read(value_length.to_i)
sock.read(TERMINATOR.length)
break if results.size == pairs.size
break if last_result
end
results
end

def sock_set_multi(sock, pairs)
count = pairs.length
tail = ''
ttl = 3600

pairs.each do |key, value|
count -= 1
tail = count.zero? ? '' : 'q'
sock.write(String.new("ms #{key} #{value.bytesize} c F0 T#{ttl} MS #{tail}\r\n", capacity: key.size + value.bytesize + 40))
sock.write(value)
sock.write(TERMINATOR)
end
sock.flush
sock.gets(TERMINATOR) # clear the buffer
end

if %w[all get].include?(bench_target)
Vernier.profile(out: 'client_get_profile.json') do
start_time = Time.now
Expand Down Expand Up @@ -135,3 +151,27 @@ if %w[all set].include?(bench_target)
end
end
end

if %w[all get_multi].include?(bench_target)
Vernier.profile(out: 'client_get_multi_profile.json') do
start_time = Time.now
client.get_multi(pairs.keys) while Time.now - start_time < bench_time
end

Vernier.profile(out: 'socket_get_multi_profile.json') do
start_time = Time.now
sock_get_multi(sock, pairs) while Time.now - start_time < bench_time
end
end

if %w[all set_multi].include?(bench_target)
Vernier.profile(out: 'client_set_multi_profile.json') do
start_time = Time.now
client.set_multi(pairs, 3600, raw: true) while Time.now - start_time < bench_time
end

Vernier.profile(out: 'socket_set_multi_profile.json') do
start_time = Time.now
sock_set_multi(sock, pairs) while Time.now - start_time < bench_time
end
end

0 comments on commit f529213

Please sign in to comment.