Browse files

benchmark alpha

  • Loading branch information...
1 parent 2b43b25 commit c1e9930b51da8172b5bc223005079140fa950eda @hcatlin committed Jan 12, 2010
Showing with 146 additions and 5 deletions.
  1. +2 −2 app/helpers/global_helpers.rb
  2. +23 −0 benchmark/log.rb
  3. +47 −0 benchmark/run.rb
  4. +72 −0 benchmark/version.rb
  5. +1 −1 bin/cluster
  6. +1 −2 config/deploy.rb
View
4 app/helpers/global_helpers.rb
@@ -63,9 +63,9 @@ def action_url(path,action)
end
def stop_redirect_notice(path)
- %|<a href="#{temp_url(path)}">#{language_object["regular_wikipedia"]}</a>
+ %|<a href="#{temp_url(path)}">#{language_object["regular_wikipedia"].force_encoding("UTF-8")}</a>
<div id="perm">
- <a href="#{disable_url(path)}">#{language_object["perm_stop_redirect"]}</a>
+ <a href="#{disable_url(path)}">#{language_object["perm_stop_redirect"].force_encoding("UTF-8")}</a>
</div>|
end
View
23 benchmark/log.rb
@@ -0,0 +1,23 @@
+class Log
+ def self.log(*types)
+ @log_types = types
+ end
+
+ def self.method_missing(name, *args, &block)
+ data = args.first
+ if @log_types.include?(name.to_s)
+ if data.is_a?(String)
+ display = data
+ else
+ display = data.inspect
+ end
+
+ if $version
+ display = "#{$version}\t" + display
+ end
+
+ puts "#{name}~\t#{display}"
+ end
+ return data
+ end
+end
View
47 benchmark/run.rb
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+rubies = [#{}"ree-1.8.7-20090928",
+ "ruby-1.8.6-p383",
+ "ruby-1.8.7-p174",
+ "ruby-1.9.1-p129",
+ "ruby-1.9.1-p243",
+ "ruby-1.9.1-rc2",
+ "ruby-1.9.2-preview1"]
+
+require File.join(File.dirname(__FILE__), "version")
+require File.join(File.dirname(__FILE__), "log")
+
+Log.log("r", "error")
+
+def run(line)
+ Log.e(line)
+ result = `#{line}`
+ Log.o(result)
+ result
+end
+
+def time_to(thing, &block)
+ start_time = Time.now
+ result = block.call
+ Log.d("#{thing} took " + (Time.now - start_time).to_s + " seconds")
+ return result
+end
+
+#Dir["/Users/hcatlin/.rvm/*"].each do |path|
+rubies.each do |path|
+ $version = path
+
+ path = "/Users/hcatlin/.rvm/" + path
+ ruby = path + "/bin/ruby"
+
+ begin
+ v = Version.new(ruby)
+ v.install
+ if v.boot
+ else
+ Log.error("#{path} didn't launch!")
+ end
+ ensure
+ v.shutdown
+ end
+end
View
72 benchmark/version.rb
@@ -0,0 +1,72 @@
+class Version
+ def initialize(ruby)
+ @ruby = ruby
+ @path = ruby.split("/")[0..-2].join("/")
+ @gem = @path + "/gem"
+ @hit_counter = 0
+
+ @port = rand(2000) + 2000
+
+ Log.d @gem
+ if File.exists?(ruby)
+ @name = `#{ruby} --version`.split(" ")[1]
+ Log.d "Successfully loaded #{@name}"
+ else
+ throw "Can't find #{ruby}"
+ end
+ end
+
+ def is_running?
+ (`curl -s http://localhost:#{@port}/ | wc`).split(" ").first.to_i > 10
+ end
+
+ def install
+ # NOT USING BUNDLER FOR THE MOMENT
+ #Log.d "Installing gems"
+ #run "#{@gem} install bundler --no-ri --no-rdoc"
+ #run "#{@gem} bundle"
+ #run "#{@path}"
+ end
+
+ def boot
+ Log.d "Booting #{@name}"
+ #Log.d `memcached -d`
+
+ time_to "startup server" do
+ run "#{@path}/ruby /Users/hcatlin/.rvm/gems/ruby/1.8.6/bin/merb -a thin -e development -p #{@port} -d"
+
+ tries = 0
+
+ while(!is_running? && tries <= 50)
+ sleep(0.1)
+ tries += 1
+ end
+
+ if !is_running?
+ Log.error("Server failed to launch")
+ return false
+ end
+ end
+
+ Log.d "Successfully started merb server"
+
+ Log.r "Taking up #{memory_usage[:real_memory]}"
+ return true
+ end
+
+ def shutdown
+ Log.d "Shutting down Merb"
+ #Log.d `pkill memcached`
+ run "merb -K #{@port}"
+ #Log.d "Cleaning up Gem cache"
+ end
+
+ def memory_usage
+ result = run("ps -o rss -o vsize -o comm | grep ruby").split("\n")[0].split(" ")[0..1]
+ {:virtual_memory => result[1], :real_memory => result[0]}
+ end
+
+ def to_mb(number)
+ (number / 1000).to_i
+ end
+end
View
2 bin/cluster
@@ -31,7 +31,7 @@ case "$1" in
pkill -9 thin
;;
restart)
- ruby $DAEMON restart --all $CONFIG_PATH
+ ruby $DAEMON restart --onebyone --all $CONFIG_PATH
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
View
3 config/deploy.rb
@@ -17,8 +17,7 @@
end
task :restart do
- deploy.stop
- deploy.start
+ run "#{current_path}/bin/cluster restart"
end
task :start do

0 comments on commit c1e9930

Please sign in to comment.