aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-02-10 02:44:32 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-02-10 02:44:32 +0000
commit916f9e5143a07092afe1efdf22b8928241c6781c (patch)
tree8afed839351b18068af43109b3a809c6f194bfa3 /actionpack/lib/action_controller
parentc9108f3e399ad2b81d7001489a4036d69333add5 (diff)
downloadrails-916f9e5143a07092afe1efdf22b8928241c6781c.tar.gz
rails-916f9e5143a07092afe1efdf22b8928241c6781c.tar.bz2
rails-916f9e5143a07092afe1efdf22b8928241c6781c.zip
Performance: patch cgi/session to require digest/md5 once rather than per #create_new_id.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6143 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb30
-rw-r--r--actionpack/lib/action_controller/cgi_process.rb1
2 files changed, 31 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb b/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb
new file mode 100644
index 0000000000..7305167860
--- /dev/null
+++ b/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb
@@ -0,0 +1,30 @@
+# CGI::Session#create_new_id requires 'digest/md5' on every call. This makes
+# sense when spawning processes per request, but is unnecessarily expensive
+# when serving requests from a long-lived process.
+#
+# http://railsexpress.de/blog/articles/2005/11/22/speeding-up-the-creation-of-new-sessions
+require 'cgi/session'
+require 'digest/md5'
+
+class CGI
+ class Session #:nodoc:
+ private
+ # Create a new session id.
+ #
+ # The session id is an MD5 hash based upon the time,
+ # a random number, and a constant string. This routine
+ # is used internally for automatically generated
+ # session ids.
+ def create_new_id
+ md5 = Digest::MD5::new
+ now = Time::now
+ md5.update(now.to_s)
+ md5.update(String(now.usec))
+ md5.update(String(rand(0)))
+ md5.update(String($$))
+ md5.update('foobar')
+ @new_session = true
+ md5.hexdigest
+ end
+ end
+end
diff --git a/actionpack/lib/action_controller/cgi_process.rb b/actionpack/lib/action_controller/cgi_process.rb
index 8d24f8dd94..2af1654eec 100644
--- a/actionpack/lib/action_controller/cgi_process.rb
+++ b/actionpack/lib/action_controller/cgi_process.rb
@@ -1,6 +1,7 @@
require 'action_controller/cgi_ext/cgi_ext'
require 'action_controller/cgi_ext/cookie_performance_fix'
require 'action_controller/cgi_ext/raw_post_data_fix'
+require 'action_controller/cgi_ext/session_performance_fix'
module ActionController #:nodoc:
class Base