Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/branches/1-2-stable/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb

Revision 6144, 0.9 kB (checked in by bitsweat, 2 years ago)

Merge [6143] from trunk.

Line 
1 # CGI::Session#create_new_id requires 'digest/md5' on every call.  This makes
2 # sense when spawning processes per request, but is unnecessarily expensive
3 # when serving requests from a long-lived process.
4 #
5 # http://railsexpress.de/blog/articles/2005/11/22/speeding-up-the-creation-of-new-sessions
6 require 'cgi/session'
7 require 'digest/md5'
8
9 class CGI
10   class Session #:nodoc:
11     private
12       # Create a new session id.
13       #
14       # The session id is an MD5 hash based upon the time,
15       # a random number, and a constant string.  This routine
16       # is used internally for automatically generated
17       # session ids.
18       def create_new_id
19         md5 = Digest::MD5::new
20         now = Time::now
21         md5.update(now.to_s)
22         md5.update(String(now.usec))
23         md5.update(String(rand(0)))
24         md5.update(String($$))
25         md5.update('foobar')
26         @new_session = true
27         md5.hexdigest
28       end
29   end
30 end
Note: See TracBrowser for help on using the browser.