Browse Source

Added unicorn tests to rails and rack

Patrick Falls 12 years ago
parent
commit
d7365e6150

+ 1 - 0
rack/Gemfile-ruby

@@ -3,3 +3,4 @@ source 'http://rubygems.org'
 gem 'rack', '1.5.1'
 gem 'json', '1.7.6'
 gem 'passenger', '3.9.5.rc3'
+gem "unicorn", "4.6.2"

+ 6 - 0
rack/benchmark_config

@@ -12,6 +12,12 @@
       "json_url": "/rack/json",
       "port": 8080,
       "sort": 15
+    },
+    "unicorn": {
+      "setup_file": "setup_unicorn",
+      "json_url": "/json",
+      "port": 8080,
+      "sort": 31
     }
   }]
 }

+ 1 - 1
rack/config.ru

@@ -4,7 +4,7 @@ app = lambda do |env|
   [
     200,
     { 'Content-Type' => 'application/json' },
-   {:message => "Hello World!"}.to_json
+    [{:message => "Hello World!"}.to_json]
   ]
 end 
 run app 

+ 52 - 0
rack/config/unicorn.rb

@@ -0,0 +1,52 @@
+worker_processes 8
+
+preload_app true
+GC.respond_to?(:copy_on_write_friendly=) and
+  GC.copy_on_write_friendly = true
+
+  before_fork do |server, worker|
+    # the following is highly recomended for Rails + "preload_app true"
+    # as there's no need for the master process to hold a connection
+    #defined?(ActiveRecord::Base) and
+    #  ActiveRecord::Base.connection.disconnect!
+
+    # The following is only recommended for memory/DB-constrained
+    # installations.  It is not needed if your system can house
+    # twice as many worker_processes as you have configured.
+    #
+    # # This allows a new master process to incrementally
+    # # phase out the old master process with SIGTTOU to avoid a
+    # # thundering herd (especially in the "preload_app false" case)
+    # # when doing a transparent upgrade.  The last worker spawned
+    # # will then kill off the old master process with a SIGQUIT.
+    # old_pid = "#{server.config[:pid]}.oldbin"
+    # if old_pid != server.pid
+    #   begin
+    #     sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
+    #     Process.kill(sig, File.read(old_pid).to_i)
+    #   rescue Errno::ENOENT, Errno::ESRCH
+    #   end
+    # end
+    #
+    # Throttle the master from forking too quickly by sleeping.  Due
+    # to the implementation of standard Unix signal handlers, this
+    # helps (but does not completely) prevent identical, repeated signals
+    # from being lost when the receiving process is busy.
+    # sleep 1
+  end
+
+  after_fork do |server, worker|
+    # per-process listener ports for debugging/admin/migrations
+    # addr = "127.0.0.1:#{9293 + worker.nr}"
+    # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
+
+    # the following is *required* for Rails + "preload_app true",
+    #defined?(ActiveRecord::Base) and
+    #  ActiveRecord::Base.establish_connection
+
+    # if preload_app is true, then you may also want to check and
+    # restart any other shared sockets/descriptors such as Memcached,
+    # and Redis.  TokyoCabinet file handles are safe to reuse
+    # between any number of forked children (assuming your kernel
+    # correctly implements pread()/pwrite() system calls)
+  end

+ 30 - 0
rack/setup_unicorn.py

@@ -0,0 +1,30 @@
+
+import subprocess
+import sys
+import re
+import osresults/i7/20130323205325
+
+def start(args):
+
+  try:
+    subprocess.check_call("rvm ruby-2.0.0-p0 do bundle install --gemfile=Gemfile-ruby", shell=True, cwd="rack")
+    subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="rack")
+    subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="rack")
+    subprocess.Popen("rvm ruby-2.0.0-p0 do bundle exec unicorn -E production -c config/unicorn.rb", shell=True, cwd="rack")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop():
+  try:
+    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+    out, err = p.communicate()
+    for line in out.splitlines():
+      if 'unicorn' in line and 'master' in line:
+        pid = int(line.split(None, 2)[1])
+        os.kill(pid, 9)
+    # subprocess.check_call("rvm ruby-2.0.0-p0 do bundle exec passenger stop --pid-file=$HOME/FrameworkBenchmarks/rack/rack.pid", shell=True, cwd='rack')
+    subprocess.check_call("rm Gemfile", shell=True, cwd="rack")
+    subprocess.check_call("rm Gemfile.lock", shell=True, cwd="rack")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1

+ 2 - 1
rails/Gemfile-ruby

@@ -2,4 +2,5 @@ source 'https://rubygems.org'
 
 gem 'rails', '3.2.11'
 gem 'mysql2', '0.3.11'
-gem 'passenger', '3.9.5.rc3'
+gem 'passenger', '3.9.5.rc3'
+gem "unicorn", "4.6.2"

+ 8 - 0
rails/benchmark_config

@@ -16,6 +16,14 @@
       "query_url": "/rails/hello_world/db?queries=",
       "port": 8080,
       "sort": 17
+    },
+    "unicorn": {
+      "setup_file": "setup_unicorn",
+      "json_url": "/hello_world/json",
+      "db_url": "/hello_world/db",
+      "query_url": "/hello_world/db?queries=",
+      "port": 8080,
+      "sort": 32
     }
   }]
 }

+ 1 - 1
rails/config/database-ruby.yml

@@ -18,5 +18,5 @@ production:
   username: benchmarkdbuser
   password: benchmarkdbpass
   host: localhost
-  pool: 200
+  pool: 256
   timeout: 5000

+ 52 - 0
rails/config/unicorn.rb

@@ -0,0 +1,52 @@
+worker_processes 8
+
+preload_app true
+GC.respond_to?(:copy_on_write_friendly=) and
+  GC.copy_on_write_friendly = true
+
+  before_fork do |server, worker|
+    # the following is highly recomended for Rails + "preload_app true"
+    # as there's no need for the master process to hold a connection
+    defined?(ActiveRecord::Base) and
+      ActiveRecord::Base.connection.disconnect!
+
+    # The following is only recommended for memory/DB-constrained
+    # installations.  It is not needed if your system can house
+    # twice as many worker_processes as you have configured.
+    #
+    # # This allows a new master process to incrementally
+    # # phase out the old master process with SIGTTOU to avoid a
+    # # thundering herd (especially in the "preload_app false" case)
+    # # when doing a transparent upgrade.  The last worker spawned
+    # # will then kill off the old master process with a SIGQUIT.
+    # old_pid = "#{server.config[:pid]}.oldbin"
+    # if old_pid != server.pid
+    #   begin
+    #     sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
+    #     Process.kill(sig, File.read(old_pid).to_i)
+    #   rescue Errno::ENOENT, Errno::ESRCH
+    #   end
+    # end
+    #
+    # Throttle the master from forking too quickly by sleeping.  Due
+    # to the implementation of standard Unix signal handlers, this
+    # helps (but does not completely) prevent identical, repeated signals
+    # from being lost when the receiving process is busy.
+    # sleep 1
+  end
+
+  after_fork do |server, worker|
+    # per-process listener ports for debugging/admin/migrations
+    # addr = "127.0.0.1:#{9293 + worker.nr}"
+    # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
+
+    # the following is *required* for Rails + "preload_app true",
+    defined?(ActiveRecord::Base) and
+      ActiveRecord::Base.establish_connection
+
+    # if preload_app is true, then you may also want to check and
+    # restart any other shared sockets/descriptors such as Memcached,
+    # and Redis.  TokyoCabinet file handles are safe to reuse
+    # between any number of forked children (assuming your kernel
+    # correctly implements pread()/pwrite() system calls)
+  end

+ 32 - 0
rails/setup_unicorn.py

@@ -0,0 +1,32 @@
+
+import subprocess
+import sys
+import re
+import os
+import setup_util
+
+def start(args):
+  setup_util.replace_text("rails/config/database-ruby.yml", "host: .*", "host: " + args.database_host)
+  try:
+    subprocess.check_call("rvm ruby-2.0.0-p0 do bundle install --gemfile=Gemfile-ruby", shell=True, cwd="rails")
+    subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="rails")
+    subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="rails")
+    subprocess.check_call("cp config/database-ruby.yml config/database.yml", shell=True, cwd="rails")
+    subprocess.Popen("rvm ruby-2.0.0-p0 do bundle exec unicorn_rails -E production -c config/unicorn.rb", shell=True, cwd="rails")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop():
+  try:
+    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+    out, err = p.communicate()
+    for line in out.splitlines():
+      if 'unicorn' in line and 'master' in line:
+        pid = int(line.split(None, 2)[1])
+        os.kill(pid, 9)
+    # subprocess.check_call("rvm ruby-2.0.0-p0 do bundle exec passenger stop --pid-file=$HOME/FrameworkBenchmarks/rack/rack.pid", shell=True, cwd='rack')
+    subprocess.check_call("rm Gemfile", shell=True, cwd="rails")
+    subprocess.check_call("rm Gemfile.lock", shell=True, cwd="rails")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1