diff options
author | Zach Koopmans <zkoopmans@google.com> | 2020-08-07 13:47:03 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-08-07 13:49:07 -0700 |
commit | 7b9bfc0ce094b0fd0cb3beec665a7b64c4ec552e (patch) | |
tree | ee9fcb5a7c0617b41c1d9096a36b9812bc5c4124 /images/benchmarks | |
parent | a7bd0a701289f8d808f93eaded266f6a1bab03ea (diff) |
Port Ruby benchmark.
PiperOrigin-RevId: 325500772
Diffstat (limited to 'images/benchmarks')
-rwxr-xr-x | images/benchmarks/ruby/Dockerfile | 27 | ||||
-rwxr-xr-x | images/benchmarks/ruby/Gemfile | 5 | ||||
-rw-r--r-- | images/benchmarks/ruby/Gemfile.lock | 26 | ||||
-rwxr-xr-x | images/benchmarks/ruby/config.ru | 2 | ||||
-rwxr-xr-x | images/benchmarks/ruby/index.erb | 8 | ||||
-rwxr-xr-x | images/benchmarks/ruby/main.rb | 27 |
6 files changed, 95 insertions, 0 deletions
diff --git a/images/benchmarks/ruby/Dockerfile b/images/benchmarks/ruby/Dockerfile new file mode 100755 index 000000000..13c4f6eed --- /dev/null +++ b/images/benchmarks/ruby/Dockerfile @@ -0,0 +1,27 @@ +# example based on https://github.com/errm/fib +FROM alpine:3.9 as build + +COPY Gemfile Gemfile.lock ./ + +RUN apk add --no-cache ruby ruby-dev ruby-bundler ruby-json build-base bash \ + && bundle install --frozen -j4 -r3 --no-cache --without development \ + && apk del --no-cache ruby-bundler \ + && rm -rf /usr/lib/ruby/gems/*/cache + +FROM alpine:3.9 as prod + +COPY --from=build /usr/lib/ruby/gems /usr/lib/ruby/gems +RUN apk add --no-cache ruby ruby-json ruby-etc redis apache2-utils \ + && ruby -e "Gem::Specification.map.each do |spec| \ + Gem::Installer.for_spec( \ + spec, \ + wrappers: true, \ + force: true, \ + install_dir: spec.base_dir, \ + build_args: spec.build_args, \ + ).generate_bin \ + end" + +COPY . /app/. + +STOPSIGNAL SIGINT diff --git a/images/benchmarks/ruby/Gemfile b/images/benchmarks/ruby/Gemfile new file mode 100755 index 000000000..ac521b32c --- /dev/null +++ b/images/benchmarks/ruby/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "sinatra" +gem "puma" +gem "redis"
\ No newline at end of file diff --git a/images/benchmarks/ruby/Gemfile.lock b/images/benchmarks/ruby/Gemfile.lock new file mode 100644 index 000000000..041778e02 --- /dev/null +++ b/images/benchmarks/ruby/Gemfile.lock @@ -0,0 +1,26 @@ +GEM + remote: https://rubygems.org/ + specs: + mustermann (1.0.3) + puma (3.4.0) + rack (2.0.6) + rack-protection (2.0.5) + rack + redis (4.1.0) + sinatra (2.0.5) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.5) + tilt (~> 2.0) + tilt (2.0.9) + +PLATFORMS + ruby + +DEPENDENCIES + puma + redis + sinatra + +BUNDLED WITH + 1.17.1
\ No newline at end of file diff --git a/images/benchmarks/ruby/config.ru b/images/benchmarks/ruby/config.ru new file mode 100755 index 000000000..b2d135cc0 --- /dev/null +++ b/images/benchmarks/ruby/config.ru @@ -0,0 +1,2 @@ +require './main' +run Sinatra::Application
\ No newline at end of file diff --git a/images/benchmarks/ruby/index.erb b/images/benchmarks/ruby/index.erb new file mode 100755 index 000000000..7f7300e80 --- /dev/null +++ b/images/benchmarks/ruby/index.erb @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<html> +<body> + <% text.each do |t| %> + <p><%= t %></p> + <% end %> +</body> +</html> diff --git a/images/benchmarks/ruby/main.rb b/images/benchmarks/ruby/main.rb new file mode 100755 index 000000000..b998f004e --- /dev/null +++ b/images/benchmarks/ruby/main.rb @@ -0,0 +1,27 @@ +require "sinatra" +require "securerandom" +require "redis" + +redis_host = ENV["HOST"] +$redis = Redis.new(host: redis_host) + +def generateText + for i in 0..99 + $redis.set(i, randomBody(1024)) + end +end + +def randomBody(length) + return SecureRandom.alphanumeric(length) +end + +generateText +template = ERB.new(File.read('./index.erb')) + +get "/" do + texts = Array.new + for i in 0..4 + texts.push($redis.get(rand(0..99))) + end + template.result_with_hash(text: texts) +end |