Skip to content

Commit

Permalink
Implemented tests for Rack behavior and async requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
matadon committed Feb 13, 2011
1 parent 324e2ed commit 3434ff7
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 198 deletions.
9 changes: 4 additions & 5 deletions README.markdown
Expand Up @@ -17,7 +17,8 @@ Mizuno is the fastest option for Rack applications on JRuby:
Jetty (via jruby-rack): 2011.67 req/s (mean)
Mongrel: 1479.15 req/sec (mean)

Mizuno also supports asynchronous request handling.
Mizuno also supports asynchronous request handling, via the Java Servlet
3.0 asynchronous processing mechanism

All the speed comes from Jetty 7; Mizuno just ties it to Rack through
JRuby's Ruby/Java integration layer.
Expand All @@ -28,10 +29,8 @@ Rack application for installation in a Java web container.

There's also a few features that I have yet to implement:

1. Integrate the cometd servlet to provide Comet/Bayeux.
2. Route Jetty's logs into Rack::Logger.
3. Add hooks for realtime monitoring of server performance.
4. Add the ability to run multiple Rack apps in a single JVM.
1. Route Jetty's logs into Rack::Logger.
2. Add hooks for realtime monitoring of server performance.

Mizuno is licensed under the Apache Public License, version 2.0; see
the LICENSE file for details, and was developed on behalf of
Expand Down
5 changes: 5 additions & 0 deletions Rakefile
@@ -0,0 +1,5 @@
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
Binary file removed lib/java/bayeux-api-2.1.0.jar
Binary file not shown.
Binary file removed lib/java/cometd-java-server-2.1.0.jar
Binary file not shown.
13 changes: 0 additions & 13 deletions lib/java/jars

This file was deleted.

60 changes: 47 additions & 13 deletions lib/mizuno/http_server.rb
Expand Up @@ -9,45 +9,79 @@ class HttpServer
include_class 'org.eclipse.jetty.servlet.ServletHolder'
include_class 'org.eclipse.jetty.server.nio.SelectChannelConnector'
include_class 'org.eclipse.jetty.util.thread.QueuedThreadPool'
include_class 'org.eclipse.jetty.servlet.DefaultServlet'

#
# Provide accessors so we can set a custom logger and a location
# for static assets.
#
class << self
attr_accessor :logger
end

#
# Start up an instance of Jetty, running a Rack application.
# Options can be any of the follwing, and are not
# case-sensitive:
#
# :host::
# String specifying the IP address to bind to; defaults
# to 0.0.0.0.
#
# :port::
# String or integer with the port to bind to; defaults
# to 9292.
#
# FIXME: Clean up options hash (all downcase, all symbols)
#
def self.run(app, options = {})
# The Jetty server
server = Server.new
@server = Server.new

options = Hash[options.map { |o|
[ o[0].to_s.downcase.to_sym, o[1] ] }]

# Thread pool
thread_pool = QueuedThreadPool.new
thread_pool.min_threads = 5
thread_pool.max_threads = 50
server.set_thread_pool(thread_pool)
@server.set_thread_pool(thread_pool)

# Connector
connector = SelectChannelConnector.new
connector.setPort(options[:Port].to_i)
connector.setHost(options[:Host])
server.addConnector(connector)
connector.setPort(options[:port].to_i)
connector.setHost(options[:host])
@server.addConnector(connector)

# Servlet context.
context = ServletContextHandler.new(nil, "/",
ServletContextHandler::NO_SESSIONS)

# The servlet itself.
servlet = RackServlet.new
servlet.rackup(app)
holder = ServletHolder.new(servlet)
rack_servlet = RackServlet.new
rack_servlet.rackup(app)
holder = ServletHolder.new(rack_servlet)
context.addServlet(holder, "/")

# Add the context to the server and start.
server.set_handler(context)
puts "Started Jetty on #{connector.getHost}:#{connector.getPort}"
server.start
@server.set_handler(context)
puts "Listening on #{connector.getHost}:#{connector.getPort}"
@server.start

# Stop the server when we get The Signal.
trap("SIGINT") { server.stop and exit }
trap("SIGINT") { @server.stop and exit }

# Join with the server thread, so that currently open file
# descriptors don't get closed by accident.
# http://www.ruby-forum.com/topic/209252
server.join
@server.join unless options[:embedded]
end

#
# Shuts down an embedded Jetty instance.
#
def self.stop
@server.stop
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/mizuno/rack_servlet.rb
Expand Up @@ -3,8 +3,9 @@
#
# Relevant documentation:
#
# http://rack.rubyforge.org/doc/SPEC.html
# http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServlet.html
# http://rack.rubyforge.org/doc/SPEC.html
# http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax
# /servlet/http/HttpServlet.html
#
module Mizuno
include_class javax.servlet.http.HttpServlet
Expand Down
73 changes: 0 additions & 73 deletions lib/testrequest.rb

This file was deleted.

11 changes: 5 additions & 6 deletions mizuno.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "mizuno"
spec.version = "0.3.7"
spec.version = "0.4.0"
spec.required_rubygems_version = Gem::Requirement.new(">= 1.2") \
if spec.respond_to?(:required_rubygems_version=)
spec.authors = [ "Don Werve" ]
Expand All @@ -12,8 +12,6 @@ Gem::Specification.new do |spec|
README.markdown
LICENSE
mizuno.gemspec
lib/java/bayeux-api-2.1.0.jar
lib/java/cometd-java-server-2.1.0.jar
lib/java/jetty-continuation-7.3.0.v20110203.jar
lib/java/jetty-http-7.3.0.v20110203.jar
lib/java/jetty-io-7.3.0.v20110203.jar
Expand All @@ -24,12 +22,13 @@ Gem::Specification.new do |spec|
lib/java/jetty-servlets-7.3.0.v20110203.jar
lib/java/jetty-util-7.3.0.v20110203.jar
lib/java/servlet-api-2.5.jar
lib/rack/handler/mizuno/http_server.rb
lib/rack/handler/mizuno/rack_servlet.rb
lib/rack/handler/mizuno.rb
lib/mizuno/http_server.rb
lib/mizuno/rack_servlet.rb
lib/mizuno.rb
bin/mizuno )
spec.homepage = 'http://github.com/matadon/mizuno'
spec.has_rdoc = false
spec.require_paths = [ "lib" ]
spec.rubygems_version = '1.3.6'
spec.add_dependency('rack', '>= 1.0.0')
end
1 change: 1 addition & 0 deletions spec/data/hello.txt
@@ -0,0 +1 @@
Hello, world!
Binary file added spec/data/reddit-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3434ff7

Please sign in to comment.