ebb 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,152 @@
1
+ /*
2
+ * libevent compatibility header, only core events supported
3
+ *
4
+ * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modifica-
8
+ * tion, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ * Alternatively, the contents of this file may be used under the terms of
29
+ * the GNU General Public License ("GPL") version 2 or any later version,
30
+ * in which case the provisions of the GPL are applicable instead of
31
+ * the above. If you wish to allow the use of your version of this file
32
+ * only under the terms of the GPL and not to allow others to use your
33
+ * version of this file under the BSD license, indicate your decision
34
+ * by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL. If you do not delete the
36
+ * provisions above, a recipient may use your version of this file under
37
+ * either the BSD or the GPL.
38
+ */
39
+
40
+ #ifndef EVENT_H__
41
+ #define EVENT_H__
42
+
43
+ #ifdef EV_H
44
+ # include EV_H
45
+ #else
46
+ # include "ev.h"
47
+ #endif
48
+
49
+ #ifdef __cplusplus
50
+ extern "C" {
51
+ #endif
52
+
53
+ struct event_base;
54
+
55
+ #define EVLIST_TIMEOUT 0x01
56
+ #define EVLIST_INSERTED 0x02
57
+ #define EVLIST_SIGNAL 0x04
58
+ #define EVLIST_ACTIVE 0x08
59
+ #define EVLIST_INTERNAL 0x10
60
+ #define EVLIST_INIT 0x80
61
+
62
+ struct event
63
+ {
64
+ /* libev watchers we map onto */
65
+ union {
66
+ struct ev_io io;
67
+ struct ev_signal sig;
68
+ } iosig;
69
+ struct ev_timer to;
70
+
71
+ /* compatibility slots */
72
+ struct event_base *ev_base;
73
+ void (*ev_callback)(int, short, void *arg);
74
+ void *ev_arg;
75
+ int ev_fd;
76
+ int ev_pri;
77
+ int ev_res;
78
+ int ev_flags;
79
+ short ev_events;
80
+ };
81
+
82
+ #define EV_PERSIST 0x10
83
+
84
+ #define EVENT_SIGNAL(ev) ((int) (ev)->ev_fd)
85
+ #define EVENT_FD(ev) ((int) (ev)->ev_fd)
86
+
87
+ #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT)
88
+
89
+ #define evtimer_add(ev,tv) event_add (ev, tv)
90
+ #define evtimer_set(ev,cb,data) event_set (ev, -1, 0, cb, data)
91
+ #define evtimer_del(ev) event_del (ev)
92
+ #define evtimer_pending(ev,tv) event_pending (ev, EV_TIMEOUT, tv)
93
+ #define evtimer_initialized(ev) event_initialized (ev)
94
+
95
+ #define timeout_add(ev,tv) evtimer_add (ev, tv)
96
+ #define timeout_set(ev,cb,data) evtimer_set (ev, cb, data)
97
+ #define timeout_del(ev) evtimer_del (ev)
98
+ #define timeout_pending(ev,tv) evtimer_pending (ev, tv)
99
+ #define timeout_initialized(ev) evtimer_initialized (ev)
100
+
101
+ #define signal_add(ev,tv) event_add (ev, tv)
102
+ #define signal_set(ev,sig,cb,data) event_set (ev, sig, EV_SIGNAL | EV_PERSIST, cb, data)
103
+ #define signal_del(ev) event_del (ev)
104
+ #define signal_pending(ev,tv) event_pending (ev, EV_SIGNAL, tv)
105
+ #define signal_initialized(ev) event_initialized (ev)
106
+
107
+ const char *event_get_version (void);
108
+ const char *event_get_method (void);
109
+
110
+ void *event_init (void);
111
+ void event_base_free (struct event_base *base);
112
+
113
+ #define EVLOOP_ONCE EVLOOP_ONESHOT
114
+ int event_loop (int);
115
+ int event_loopexit (struct timeval *tv);
116
+ int event_dispatch (void);
117
+
118
+ #define _EVENT_LOG_DEBUG 0
119
+ #define _EVENT_LOG_MSG 1
120
+ #define _EVENT_LOG_WARN 2
121
+ #define _EVENT_LOG_ERR 3
122
+ typedef void (*event_log_cb)(int severity, const char *msg);
123
+ void event_set_log_callback(event_log_cb cb);
124
+
125
+ void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg);
126
+ int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv);
127
+
128
+ int event_add (struct event *ev, struct timeval *tv);
129
+ int event_del (struct event *ev);
130
+ void event_active (struct event *ev, int res, short ncalls); /* ncalls is being ignored */
131
+
132
+ int event_pending (struct event *ev, short, struct timeval *tv);
133
+
134
+ int event_priority_init (int npri);
135
+ int event_priority_set (struct event *ev, int pri);
136
+
137
+ int event_base_set (struct event_base *base, struct event *ev);
138
+ int event_base_loop (struct event_base *base, int);
139
+ int event_base_loopexit (struct event_base *base, struct timeval *tv);
140
+ int event_base_dispatch (struct event_base *base);
141
+ int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv);
142
+ int event_base_priority_init (struct event_base *base, int fd);
143
+
144
+ /* next line is different in the libevent+libev version */
145
+ /*libevent-include*/
146
+
147
+ #ifdef __cplusplus
148
+ }
149
+ #endif
150
+
151
+ #endif
152
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ry dahl
@@ -9,66 +9,52 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-08 00:00:00 +02:00
12
+ date: 2008-08-19 00:00:00 +02:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rack
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
23
- version:
14
+ dependencies: []
15
+
24
16
  description: ""
25
17
  email: ry at tiny clouds dot org
26
- executables:
27
- - ebb_rails
18
+ executables: []
19
+
28
20
  extensions:
29
- - src/extconf.rb
21
+ - ext/extconf.rb
30
22
  extra_rdoc_files: []
31
23
 
32
24
  files:
33
- - src/ebb.c
34
- - src/ebb.h
35
- - src/parser.c
36
- - src/parser.h
37
25
  - libev/ev_epoll.c
38
26
  - libev/ev_select.c
39
- - libev/ev.h
40
- - libev/ev_wrap.h
41
27
  - libev/ev_poll.c
42
28
  - libev/ev.c
29
+ - libev/event.c
43
30
  - libev/ev_port.c
44
31
  - libev/ev_kqueue.c
45
32
  - libev/ev_win32.c
33
+ - libev/ev++.h
34
+ - libev/event.h
35
+ - libev/ev.h
36
+ - libev/ev_wrap.h
46
37
  - libev/ev_vars.h
38
+ - lib/ebb/version.rb
39
+ - lib/ebb.rb
40
+ - ext/extconf.rb
41
+ - ext/ebb_ffi.c
47
42
  - README
48
- - src/ebb_ruby.c
49
- - src/extconf.rb
50
- - ruby_lib/ebb
51
- - ruby_lib/ebb/runner.rb
52
- - ruby_lib/ebb/runner
53
- - ruby_lib/ebb/runner/rails.rb
54
- - ruby_lib/rack
55
- - ruby_lib/rack/adapter
56
- - ruby_lib/rack/adapter/rails.rb
57
- - ruby_lib/ebb.rb
58
- - benchmark/server_test.rb
59
- - benchmark/application.rb
60
- - bin/ebb_rails
61
- - test/basic_test.rb
62
- - test/env_test.rb
63
- - test/helper.rb
64
- - test/ebb_rails_test.rb
43
+ - Rakefile
44
+ - ext/ebb.c
45
+ - ext/ebb.h
46
+ - ext/ebb_request_parser.rl
47
+ - ext/ebb_request_parser.c
48
+ - ext/ebb_request_parser.h
49
+ - ext/rbtree.c
50
+ - ext/rbtree.h
65
51
  has_rdoc: false
66
52
  homepage: http://ebb.rubyforge.org
67
53
  post_install_message:
68
54
  rdoc_options: []
69
55
 
70
56
  require_paths:
71
- - ruby_lib
57
+ - lib
72
58
  required_ruby_version: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - ">="
@@ -84,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
70
  requirements: []
85
71
 
86
72
  rubyforge_project: ebb
87
- rubygems_version: 1.1.1
73
+ rubygems_version: 1.2.0
88
74
  signing_key:
89
75
  specification_version: 2
90
76
  summary: A Web Server
@@ -1,93 +0,0 @@
1
- DIR = File.dirname(__FILE__)
2
-
3
- def fib(n)
4
- return 1 if n <= 1
5
- fib(n-1) + fib(n-2)
6
- end
7
-
8
- def wait(seconds)
9
- n = (seconds / 0.01).to_i
10
- n.times do
11
- sleep(0.01)
12
- #File.read(DIR + '/yahoo.html')
13
- end
14
- end
15
-
16
- class SimpleApp
17
- @@responses = {}
18
-
19
- def initialize
20
- @count = 0
21
- end
22
-
23
- def deferred?(env)
24
- false
25
- end
26
-
27
- def call(env)
28
- path = env['PATH_INFO'] || env['REQUEST_URI']
29
- commands = path.split('/')
30
-
31
- @count += 1
32
- if commands.include?('periodical_activity') and @count % 10 != 1
33
- return [200, {'Content-Type'=>'text/plain'}, "quick response!\r\n"]
34
- end
35
-
36
- if commands.include?('fibonacci')
37
- n = commands.last.to_i
38
- raise "fibonacci called with n <= 0" if n <= 0
39
- body = (1..n).to_a.map { |i| fib(i).to_s }.join(' ')
40
- status = 200
41
-
42
- elsif commands.include?('wait')
43
- n = commands.last.to_f
44
- raise "wait called with n <= 0" if n <= 0
45
- wait(n)
46
- body = "waited about #{n} seconds"
47
- status = 200
48
-
49
- elsif commands.include?('bytes')
50
- n = commands.last.to_i
51
- raise "bytes called with n <= 0" if n <= 0
52
- body = @@responses[n] || "C"*n
53
- status = 200
54
-
55
- elsif commands.include?('test_post_length')
56
- input_body = ""
57
- while chunk = env['rack.input'].read(512)
58
- input_body << chunk
59
- end
60
- if env['CONTENT_LENGTH'].to_i == input_body.length
61
- body = "Content-Length matches input length"
62
- status = 200
63
- else
64
- body = "Content-Length doesn't matches input length!
65
- content_length = #{env['CONTENT_LENGTH'].to_i}
66
- input_body.length = #{input_body.length}"
67
- status = 500
68
- end
69
- else
70
- status = 404
71
- body = "Undefined url"
72
- end
73
-
74
- body += "\r\n"
75
- headers = {'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }
76
- [status, headers, body]
77
- end
78
- end
79
-
80
-
81
- if $0 == __FILE__
82
- # Thread.new do
83
- # i = 0
84
- # loop {
85
- # puts i += 1
86
- # sleep 1
87
- # }
88
- # end
89
-
90
- require DIR + '/../ruby_lib/ebb'
91
- #server = Ebb::start_server(SimpleApp.new, :unix_socket => '/tmp/ebb.sock')
92
- server = Ebb::start_server(SimpleApp.new, :port => 4001)
93
- end
@@ -1,193 +0,0 @@
1
- $: << File.expand_path(File.dirname(__FILE__))
2
-
3
- require 'rubygems'
4
- require 'rack'
5
- require 'application'
6
-
7
-
8
- class Array
9
- def mean
10
- @mean ||= sum / length
11
- end
12
-
13
- def variance
14
- @variance ||= map { |x| (mean - x)**2 }.sum / length
15
- end
16
-
17
- def stdd
18
- @stdd ||= Math.sqrt(variance)
19
- end
20
-
21
- def errors
22
- map { |x| (mean - x).abs }
23
- end
24
-
25
- def center_avg
26
- return mean if stdd < 10
27
- acceptable_error = 0
28
- good_points = []
29
- while good_points.empty?
30
- acceptable_error += stdd
31
- good_points = select { |x| (mean - x).abs < acceptable_error }
32
- end
33
- good_points.mean
34
- end
35
-
36
- def sum
37
- inject(0.to_f) { |i, s| s += i }
38
- end
39
-
40
- def rand_each(&block)
41
- sort_by{ rand }.each &block
42
- end
43
- end
44
-
45
- class ServerTestResults
46
- def self.open(filename)
47
- if File.readable?(filename)
48
- new(Marshal.load(File.read(filename)))
49
- else
50
- new
51
- end
52
- end
53
- attr_reader :results
54
- def initialize(results = [])
55
- @results = results
56
- end
57
-
58
- def benchmark
59
- @results.first[:benchmark]
60
- end
61
-
62
- def write(filename='results.dump')
63
- puts "writing dump file to #{filename}"
64
- File.open(filename, 'w+') do |f|
65
- f.write Marshal.dump(@results)
66
- end
67
- end
68
-
69
- def <<(r)
70
- @results << r
71
- end
72
-
73
- def length
74
- @results.length
75
- end
76
-
77
- def servers
78
- @results.map {|r| r[:server] }.uniq.sort
79
- end
80
-
81
- def data(server)
82
- server_data = @results.find_all { |r| r[:server] == server }
83
- ticks = server_data.map { |d| d[:input] }.uniq
84
- datas = []
85
- ticks.each do |c|
86
- measurements = server_data.find_all { |d| d[:input] == c }.map { |d| d[:rps] }
87
- datas << [c, measurements.mean] unless measurements.empty?
88
- end
89
- datas
90
- end
91
-
92
- end
93
-
94
- class ServerTest
95
- attr_reader :name, :port, :app, :pid
96
- def initialize(name, port, &start_block)
97
- @name = name
98
- @port = port.to_i
99
- end
100
-
101
- def <=>(a)
102
- @name <=> a.name
103
- end
104
-
105
- def kill
106
- Process.kill('KILL', @pid) if @pid
107
- end
108
-
109
- def running?
110
- !@pid.nil?
111
- end
112
-
113
- def start
114
- puts "Starting #{name}"
115
- case name
116
- when 'emongrel'
117
- @pid = fork { start_emongrel }
118
- when 'ebb'
119
- @pid = fork { start_ebb }
120
- when 'mongrel'
121
- @pid = fork { start_mongrel }
122
- when 'thin'
123
- @pid = fork { start_thin }
124
- when 'fcgi'
125
- @pid = fork { start_fcgi }
126
- end
127
- end
128
-
129
- def app
130
- SimpleApp.new
131
- end
132
-
133
- def start_emongrel
134
- require 'mongrel'
135
- require 'swiftcore/evented_mongrel'
136
- ENV['EVENT'] = "1"
137
- Rack::Handler::Mongrel.run(app, :Host => '0.0.0.0', :Port => @port.to_i)
138
- end
139
-
140
- def start_ebb
141
- require File.dirname(__FILE__) + '/../ruby_lib/ebb'
142
- server = Ebb::start_server(app, :port => @port)
143
- end
144
-
145
-
146
- def start_mongrel
147
- require 'mongrel'
148
- ENV.delete('EVENT')
149
- Rack::Handler::Mongrel.run(app, :Port => @port)
150
- end
151
-
152
- def start_thin
153
- require 'thin'
154
- Rack::Handler::Thin.run(app, :Port => @port)
155
- end
156
-
157
- def start_fcgi
158
- Rack::Handler::FastCGI.run(app, :Port => @port)
159
- end
160
-
161
- def trial(ab_cmd)
162
- cmd = ab_cmd.sub('PORT', @port.to_s)
163
-
164
- puts "#{@name} (#{cmd})"
165
-
166
- r = %x{#{cmd}}
167
-
168
- return nil unless r =~ /Requests per second:\s*(\d+\.\d\d)/
169
- rps = $1.to_f
170
- if r =~ /Time taken for tests:\s*(\d+\.\d+) seconds/
171
- time_taken = $1.to_f
172
- end
173
- if r =~ /Complete requests:\s*(\d+)/
174
- requests_completed = $1.to_i
175
- end
176
- if r =~ /Failed requests:\s*(\d+)/
177
- failed_requests = $1.to_i
178
- else
179
- raise "didn't get how many failed requests from ab"
180
- end
181
- successful_requests = requests_completed - failed_requests
182
- puts " #{rps} req/sec (#{requests_completed} total, #{failed_requests} failed in #{"%.2f" % time_taken} seconds)"
183
-
184
- {
185
- :server => @name,
186
- :rps => rps,
187
- :time_taken => time_taken,
188
- :requests_completed => requests_completed,
189
- :requests_failed => failed_requests,
190
- :ab_cmd => cmd
191
- }
192
- end
193
- end