Skip to content

Instantly share code, notes, and snippets.

@grosser
Last active June 4, 2019 22:00
Show Gist options
  • Save grosser/db29a5d4bb268d097b6154ef85ff7478 to your computer and use it in GitHub Desktop.
Save grosser/db29a5d4bb268d097b6154ef85ff7478 to your computer and use it in GitHub Desktop.
ruby test.rb internaltools.k8s.local
Warming up --------------------------------------
kubeclient os 1.000 i/100ms
kubeclient json 1.000 i/100ms
faraday json 1.000 i/100ms
faraday persistent 1.000 i/100ms
Calculating -------------------------------------
kubeclient os 1.896 (± 0.0%) i/s - 10.000 in 5.275373s
kubeclient json 1.907 (± 0.0%) i/s - 10.000 in 5.248037s
faraday json 1.933 (± 0.0%) i/s - 10.000 in 5.175768s
faraday persistent 7.135 (±14.0%) i/s - 33.000 in 5.047875s
ruby test.rb docker-desktop
Warming up --------------------------------------
kubeclient os 8.000 i/100ms
kubeclient json 9.000 i/100ms
faraday json 9.000 i/100ms
faraday persistent 35.000 i/100ms
Calculating -------------------------------------
kubeclient os 91.147 (± 6.6%) i/s - 456.000 in 5.029854s
kubeclient json 91.485 (± 7.7%) i/s - 459.000 in 5.046048s
faraday json 97.198 (± 8.2%) i/s - 486.000 in 5.037273s
faraday persistent 340.279 (± 9.7%) i/s - 1.715k in 5.093199s
require "bundler/inline"
context = ARGV[0] || abort("Context as first argument")
gemfile do
source "https://rubygems.org"
gem "faraday"
# gem "patron"
gem "kubeclient"
gem "benchmark-ips"
gem "net-http-persistent-retry"
gem "byebug"
end
require "kubeclient"
config = Kubeclient::Config.read(File.expand_path("~/.kube/config"))
context = config.context(context)
# kkubeclient
kubeclient = Kubeclient::Client.new(
"#{context.api_endpoint}/api",
"v1",
ssl_options: context.ssl_options
)
# faraday
require "faraday"
faraday = [:net_http, :net_http_persistent].map do |adapter|
Faraday.new(url: context.api_endpoint) do |builder|
builder.adapter adapter
builder.ssl.merge!(
client_cert: context.ssl_options[:client_cert], # OpenSSL::X509::Certificate.new(),
client_key: context.ssl_options[:client_key], # OpenSSL::PKey.read,
verify: false
)
end
end
# patron TODO https://github.com/toland/patron/issues/173
# require "patron"
# patron = Patron::Session.new
# patron.timeout = 10
# patron.base_url = context.api_endpoint
# patron.headers['User-Agent'] = 'myapp/1.0'
# patron.ssl_client_cert = context.ssl_options[:client_cert] # OpenSSL::X509::Certificate.new(),
# patron.ssl_client_key = context.ssl_options[:client_key] # OpenSSL::PKey.read,
# patron.ssl_verify = false
require "benchmark/ips"
Benchmark.ips do |x|
x.config time: 5, warmup: 2
x.report("kubeclient os") { kubeclient.get_namespaces }
x.report("kubeclient json") { kubeclient.get_namespaces as: :parsed_symbolized }
x.report("faraday json") { JSON.parse(faraday[0].get("/api/v1/namespaces").body, symbolize_names: true) }
x.report("faraday persistent") { JSON.parse(faraday[1].get("/api/v1/namespaces").body, symbolize_names: true) }
# x.report("patron persistent") { JSON.parse(patron.get("/api/v1/namespaces").body, symbolize_names: true) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment