From 6dcd34bfb5513d57ee772224a7d3731e142ec54c Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 19 Aug 2021 12:10:43 -0400 Subject: [PATCH] Add a memcached_ping tool --- tools/memcached_ping.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 tools/memcached_ping.rb diff --git a/tools/memcached_ping.rb b/tools/memcached_ping.rb new file mode 100755 index 00000000000..ae4d9973603 --- /dev/null +++ b/tools/memcached_ping.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +require 'dalli' +require 'benchmark' + +server_host = ENV.fetch("MEMCACHED_SERVICE_HOST", "localhost") +server_port = ENV.fetch("MEMCACHED_SERVICE_PORT", "11211") +server_address = "#{server_host}:#{server_port}" + +begin + client = Dalli::Client.new(server_address) + avg = 10.times.map { Benchmark.realtime { client.get("test") } }.inject(:+) / 10.0 + + puts "Average: #{avg.round(8)} seconds" +rescue => err + puts "Failed: #{err}" +end