Browse Source

Add sinatra-sequel-puma-rbx benchmark

Mike Pastore 9 years ago
parent
commit
03876d2809

+ 1 - 1
frameworks/Ruby/sinatra-sequel/Gemfile

@@ -4,6 +4,6 @@ gem 'jdbc-mysql', '~> 5.1.37', :platform => 'jruby', :require => 'jdbc/mysql'
 gem 'json', '~> 1.8.3', :require => 'json/ext'
 gem 'mysql2', '~> 0.4.0', :platform => 'ruby'
 gem 'puma', '~> 2.15.3'
-gem 'sequel', '~> 4.28.0'
+gem 'sequel', '~> 4.28'
 gem 'sinatra', '~> 1.4.6', :require => 'sinatra/base'
 gem 'slim', '~> 3.0.6'

+ 5 - 2
frameworks/Ruby/sinatra-sequel/Gemfile.lock

@@ -10,7 +10,7 @@ GEM
     rack (1.6.4)
     rack-protection (1.5.3)
       rack
-    sequel (4.28.0)
+    sequel (4.29.0)
     sinatra (1.4.6)
       rack (~> 1.4)
       rack-protection (~> 1.4)
@@ -30,6 +30,9 @@ DEPENDENCIES
   json (~> 1.8.3)
   mysql2 (~> 0.4.0)
   puma (~> 2.15.3)
-  sequel (~> 4.28.0)
+  sequel (~> 4.28)
   sinatra (~> 1.4.6)
   slim (~> 3.0.6)
+
+BUNDLED WITH
+   1.10.6

+ 23 - 0
frameworks/Ruby/sinatra-sequel/benchmark_config.json

@@ -46,6 +46,29 @@
       "display_name": "sinatra-sequel-puma-jruby",
       "notes": "",
       "versus": "rack-puma-jruby"
+    },
+    "puma-rbx": {
+      "setup_file": "run_rbx_puma",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortunes",
+      "update_url": "/updates?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "MySQL",
+      "framework": "sinatra-sequel",
+      "language": "Ruby",
+      "orm": "Full",
+      "platform": "Rubinius",
+      "webserver": "Puma",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "sinatra-sequel-puma-rbx",
+      "notes": "",
+      "versus": "rack-puma-rbx"
     }
   }]
 }

+ 16 - 25
frameworks/Ruby/sinatra-sequel/hello_world.rb

@@ -58,16 +58,16 @@ class HelloWorld < Sinatra::Base
 
   after do
     # Add mandatory HTTP headers to every response
-    response['Server'] ||= 'Puma'
+    response['Server'] ||= 'Puma'.freeze
     response['Date'] ||= Time.now.to_s
   end
 
   get '/json', :provides => :json do
-    JSON.fast_generate :message => 'Hello, World!'
+    JSON.fast_generate :message => 'Hello, World!'.freeze
   end
 
   get '/plaintext', :provides => :text do
-    'Hello, World!'
+    'Hello, World!'.freeze
   end
 
   get '/db', :provides => :json do
@@ -79,16 +79,17 @@ class HelloWorld < Sinatra::Base
     queries = 1 if queries < 1
     queries = 500 if queries > 500
 
-    World
-      .where(:id => randn(queries))
-      .to_json
+    # Benchmark requirements explicitly forbid a WHERE..IN here, so be good...
+    worlds = randn(queries).map! { |id| World[id] }
+
+    World.to_json :array => worlds
   end
 
   get '/fortunes' do
     @fortunes = Fortune.all
     @fortunes << Fortune.new(
       :id => 0,
-      :message => 'Additional fortune added at request time.'
+      :message => 'Additional fortune added at request time.'.freeze
     )
     @fortunes.sort_by!(&:message)
 
@@ -100,26 +101,16 @@ class HelloWorld < Sinatra::Base
     queries = 1 if queries < 1
     queries = 500 if queries > 500
 
-    # Prepare our updates in advance so transaction retries are idempotent
-    updates = randn(queries).map! { |id| [id, rand1] }.to_h
-
-    worlds = nil
-
-    World.db.transaction do
-      worlds = World
-        .where(:id => updates.keys.sort!)
-        .for_update
-        .all
-
-      worlds
-        .each { |w| w.randomNumber = updates[w.id] }
-
-      World.dataset
-        .on_duplicate_key_update(:randomNumber)
-        .import([:id, :randomNumber], worlds.map { |w| [w.id, w.randomNumber] })
+    # Benchmark requirements explicitly forbid a WHERE..IN here, and specify
+    # that each transaction only read and write a single record, so be good...
+    worlds = randn(queries).map! do |id|
+      World.db.transaction do
+        World.for_update[id].tap do |world|
+          world.update :randomNumber => rand1
+        end
+      end
     end
 
-    # The models are dirty but OK to return if the batch update was successful
     World.to_json :array => worlds
   end
 end

+ 8 - 3
frameworks/Ruby/sinatra-sequel/run_mri_puma.sh

@@ -5,9 +5,14 @@ fw_depends rvm ruby-2.2
 rvm ruby-$MRI_VERSION do \
   bundle install --jobs=4 --gemfile=$TROOT/Gemfile --path=vendor/bundle
 
-WORKERS=8 # enable Puma's clustered mode
-MAX_THREADS=32 ; export MAX_THREADS
-MIN_THREADS=$(( MAX_THREADS / WORKERS * 2 ))
+# Enable Puma's clustered mode with about one process per hardware thread,
+# scaling up to a maximum of about 256 concurrent threads. NOTE: I was having
+# trouble keeping two cores saturated with only two workers, thus the "fuzzy"
+# math here.
+
+WORKERS=$(( $(nproc || echo 7) + 1 ))
+MAX_THREADS=$(( 256 / WORKERS + 1 )) ; export MAX_THREADS
+MIN_THREADS=$(( MAX_THREADS / 4 + 1 ))
 
 rvm ruby-$MRI_VERSION do \
   bundle exec puma -w $WORKERS -t $MIN_THREADS:$MAX_THREADS -b tcp://0.0.0.0:8080 -e production &

+ 12 - 0
frameworks/Ruby/sinatra-sequel/run_rbx_puma.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+fw_depends rvm rbx-2.5
+
+rvm rbx-$RBX_VERSION do \
+  bundle install --jobs=4 --gemfile=$TROOT/Gemfile --path=vendor/bundle
+
+MAX_THREADS=256 ; export MAX_THREADS
+MIN_THREADS=$(( MAX_THREADS / 8 * 2 ))
+
+rvm rbx-$RBX_VERSION do \
+  bundle exec puma -t $MIN_THREADS:$MAX_THREADS -b tcp://0.0.0.0:8080 -e production &

+ 1 - 1
frameworks/Ruby/sinatra-sequel/source_code

@@ -1 +1 @@
-./hello_world.rb
+./sinatra-sequel/hello_world.rb

+ 33 - 0
toolset/setup/linux/languages/rbx-2.5.sh

@@ -0,0 +1,33 @@
+#!/bin/bash
+
+fw_depends rvm
+
+# rvm stable [typically] only provides one version of rbx-2.5
+# update this when it changes
+RBX_VERSION=2.5.2
+
+RETCODE=$(fw_exists ${IROOT}/rbx-${RBX_VERSION}.installed)
+[ ! "$RETCODE" == 0 ] || { \
+  # Load environment variables
+  source $IROOT/rbx-${RBX_VERSION}.installed
+  return 0; }
+
+# We assume single-user installation as
+# done in our rvm.sh script and
+# in Travis-CI
+if [ "$TRAVIS" = "true" ]
+then
+  # Rubinus cannot find libc during configure unless
+  # you specify bash as the shell.
+  SHELL="/bin/bash" rvmsudo rvm install rbx-$RBX_VERSION
+  # Bundler is SOMETIMES missing... not sure why.
+  SHELL="/bin/bash" rvmsudo rvm rbx-$RBX_VERSION do gem install bundler
+else
+  SHELL="/bin/bash" rvm install rbx-$RBX_VERSION
+  # Bundler is SOMETIMES missing... not sure why.
+  SHELL="/bin/bash" rvm rbx-$RBX_VERSION do gem install bundler
+fi
+
+echo "" > $IROOT/rbx-$RBX_VERSION.installed
+
+source $IROOT/rbx-${RBX_VERSION}.installed