diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-04 19:16:28 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-04 19:16:28 +0000 |
commit | 9e4f5f33974b018fe4b6eba2766af263f8b06951 (patch) | |
tree | e42300627db01be56744ff6732e64ea7356b2ed3 /railties/dispatches | |
parent | 00739dee173a675a9da94ec4c9c9e2866715fb41 (diff) | |
download | rails-9e4f5f33974b018fe4b6eba2766af263f8b06951.tar.gz rails-9e4f5f33974b018fe4b6eba2766af263f8b06951.tar.bz2 rails-9e4f5f33974b018fe4b6eba2766af263f8b06951.zip |
Added an EXPERIMENTAL gateway.cgi for getting high-speed performance through vanilla CGI using a long-running, DRb-backed server in the background (using script/listener and script/tracker) #1603 [Nicholas Seckar]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1676 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/dispatches')
-rw-r--r-- | railties/dispatches/gateway.cgi | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/railties/dispatches/gateway.cgi b/railties/dispatches/gateway.cgi new file mode 100644 index 0000000000..b8d44acef2 --- /dev/null +++ b/railties/dispatches/gateway.cgi @@ -0,0 +1,57 @@ +#!/usr/bin/ruby + +# This is an experimental feature for getting high-speed CGI by using a long-running, DRb-backed server in the background + +require File.join(File.dirname(__FILE__), 'drb') +require 'cgi' + +VERBOSE = false + +AppName = File.split(File.expand_path(File.join(__FILE__, '..'))).last +SocketPath = File.expand_path(File.join(File.dirname(__FILE__), '../log/drb_gateway.sock')) +ConnectionUri = "drbunix:#{SocketPath}" +attempted_start = false + +def start_tracker + tracker_path = File.join(File.dirname(__FILE__), '../script/tracker') + fork do + Process.setsid + STDIN.reopen "/dev/null" + STDOUT.reopen "/dev/null", "a" + + exec 'ruby', tracker_path, 'start', ConnectionUri + end + + $stderr.puts "dispatch: waiting for tracker to start..." if VERBOSE + 10.times do + sleep 0.5 + return if File.exists? SocketPath + end + + $stderr.puts "Can't start tracker!!! Dropping request!" + Kernel.exit 1 +end + +unless File.exists?(SocketPath) + $stderr.puts "tracker not running: starting it..." if VERBOSE + start_tracker +end + +$stderr.puts "dispatch: attempting to contact tracker..." if VERBOSE +tracker = DRbObject.new_with_uri(ConnectionUri) +tracker.ping # Test connection + +$stdout.extend DRbUndumped +$stdin.extend DRbUndumped + +DRb.start_service "drbunix:", $stdin +$stderr.puts "dispatch: publishing stdin..." if VERBOSE + +$stderr.puts "dispatch: sending request to tracker" if VERBOSE +puts tracker.process($stdin) + +$stdout.flush +[$stdin, $stdout].each {|io| io.close} +$stderr.puts "dispatch: finished..." if VERBOSE + + |