public
Description: CGIAlt is a re-implementation of cgi.rb
Homepage: http://cgialt.rubyforge.org/
Clone URL: git://github.com/kwatch/cgialt.git
cgialt / README.txt
100644 174 lines (116 sloc) 6.025 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
= README.txt
 
Release: $Release$
 
$Copyright$
 
http://cgialt.rubyforge.org/
http://rubyforge.org/projects/cgialt/
http://github.com/kwatch/cgialt/
 
 
== About
 
'CGIAlt' is an alternative library of standard 'cgi.rb'.
It is written in pure Ruby but works faster than 'cgi.rb'.
 
 
== Features
 
* Compatible with 'cgi.rb'.
* Faster and more lightweight than 'cgi.rb'.
* Available to install with CGIExt (which is a re-implementation of 'cgi.rb'
  in C extension).
* FastCGI support
 
 
== Install
 
Download cgialt-$Release$.tar.gz and install it according to the following:
 
    $ tar xzf cgialt-$Release$.tar.gz
    $ cd cgialt-$Release$/
    $ sudo ruby setup.rb
 
Or if you have installed RubyGems, you can install CGIAlt by 'gem' command.
 
    $ sudo gem install cgialt
 
It is recommended not to use RubyGems if you have to develop CGI program
because loading RubyGems is very heavy-weight for CGI program.
 
 
== Usage
 
All you have to do is to require 'cgialt' instead of 'cgi', and you can use
CGI class which is compatible with 'cgi.rb'.
 
   require 'rubygems' # if you have installed with RubyGems
   require 'cgialt'
 
If you want to use CGIAlt with FastCGI (fcgi.rb), require 'cgialt/fcgi'
instead of 'fcgi'.
 
   require 'cgialt'
   require 'cgialt/fcgi'
 
If you want require 'cgi' when CGIAlt is not installed, try the following.
 
   begin
     require 'cgialt'
   rescue LoadError
     require 'cgi'
   end
   begin
     reqiure 'cgialt/fcgi'
   rescue LoadError
     require 'fcgi'
   end
 
If you want to replace original 'cgi.rb' entirely by 'cgialt',
create 'cgi.rb' which requires 'cgialt' under proper directory such as
'/usr/local/lib/ruby/site_ruby/1.8'.
 
   $ sudo echo 'require "cgialt"' > /usr/local/lib/ruby/site_ruby/1.8/cgi.rb
   $ sudo echo 'require "cgialt/fcgi"' > /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb
 
When $DEBUG is true or ENV['DEBUG'] is set, CGIAlt prints release number
to $stderr when loaded.
 
   $ DEBUG=1 ruby -e 'require "cgi"'
   *** CGIAlt: release $Release$
 
 
== Benchmark
 
Try 'bench.rb' included in CGIAlt archive.
The following is an example of benchmark.
 
    ## cgi.rb
    $ ruby -s bench.rb -N=1000
    *** 1000 times user system total real
    ruby -e 'nil' 0.0900 0.8300 11.5400 ( 11.9631)
    ruby -e 'require "cgi"' 0.1000 1.2400 24.7000 ( 25.2709)
    
    *** 100000 times user system total real
    CGI#new (simple) 20.3100 0.0300 20.3400 ( 20.3770)
    CGI#new (complex) 26.5800 0.0400 26.6200 ( 26.6604)
    
    *** 1000000 times user system total real
    CGI#header (simple) 12.6700 0.0100 12.6800 ( 12.7137)
    CGI#header (complex) 43.4600 0.0600 43.5200 ( 43.5749)
 
    ## CGIAlt
    $ ruby -s bench.rb -N=1000 -cgialt
    *** CGIAlt: release 0.0.0
    *** 1000 times user system total real
    ruby -e 'nil' 0.0900 0.8000 11.5900 ( 12.0581)
    ruby -e 'require "cgi"' 0.1000 1.2300 19.4800 ( 20.0621)
    
    *** 100000 times user system total real
    CGI#new (simple) 14.5000 0.0300 14.5300 ( 14.5594)
    CGI#new (complex) 20.0700 0.0300 20.1000 ( 20.1356)
    
    *** 1000000 times user system total real
    CGI#header (simple) 6.0400 0.0100 6.0500 ( 6.0553)
    CGI#header (complex) 36.2200 0.0400 36.2600 ( 36.3138)
 
 
It is good thing for performance to install CGIExt as well as CGIAlt.
The following is a benchmark example of using both CGIAlt and CGIExt.
 
    ## CGIAlt and CGIExt
    $ ruby -s bench.rb -N=1000 -cgialt -cgiext
    *** CGIAlt: release 0.0.0
    *** 1000 times user system total real
    ruby -e 'nil' 0.0900 0.8100 11.6600 ( 12.1769)
    ruby -e 'require "cgi","cgiext"' 0.1000 1.2100 20.8400 ( 21.5575)
    
    *** 100000 times user system total real
    CGI#new (simple) 12.4200 0.0400 12.4600 ( 12.5207)
    CGI#new (complex) 13.1600 0.0300 13.1900 ( 13.2443)
    
    *** 1000000 times user system total real
    CGI#header (simple) 6.0300 0.0100 6.0400 ( 6.0651)
    CGI#header (complex) 36.5400 0.0800 36.6200 ( 37.0642)
 
 
The following is a summary of above benchmark results.
 
    Table 1. summary of benchmark
                                       cgi.rb CGIAlt CGIAlt+CGIExt
    ---------------------------------------------------------------------------
    require "cgi" (x1000) 13.16 7.89 ( 67%) 9.18 ( 43%)
    CGI#new (simple) (x100000) 20.34 14.53 ( 40%) 12.46 ( 63%)
    CGI#new (comple) (x100000) 26.62 20.10 ( 32%) 13.19 (102%)
    CGI#header (simple) (x1000000) 12.68 6.05 (110%) 6.04 (110%)
    CGI#header (complex) (x1000000) 43.52 36.26 ( 20%) 36.62 ( 19%)
 
 
Another benchmark script 'bench.fcgi' is provided. It is for FastCGI.
The following is an example result of benchmark.
 
    Table 2. result of bench.fcgi
                                   Time taken for tests Request per second
    --------------------------------------------------------------------------
    cgi + fcgi 16.686 [sec] 1198.61 [#/sec]
    cgialt + cgialt/fcgi 15.562 [sec] 1285.18 [#/sec]
    cgialt + cgialt/fcgi + cgiext 15.310 [sec] 1306.34 [#/sec]
 
 
== License
 
Ruby's license
 
 
== Author
 
makoto kuwata <kwa(at)kuwata-lab.com>
 
 
== Bug reports
 
If you have bugs or questions, report them to kwa(at)kuwata-lab.com.