Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
122 changed files
with
4,717 additions
and
593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,15 +1,19 @@ | |||
Makefile | Gemfile.lock | ||
mkmf.log |
|
||
*.o | .bundle/ | ||
*.bundle | |||
doc/ | doc/ | ||
pkg/ | pkg/ | ||
examples/log | _site | ||
*.swp |
|
||
Gemfile.lock | |||
.yardoc | .yardoc | ||
.livereload | .livereload | ||
.rvmrc | |||
|
|||
*.swp | |||
*.watchr | *.watchr | ||
*.rbc | *.rbc | ||
.rvmrc |
|
||
_site | examples/log | ||
examples/goliath.log* | |||
examples/goliath.pid | |||
examples/rasterize/thumb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,3 @@ | |||
source "http://rubygems.org" | source "http://rubygems.org" | ||
|
|
||
gem 'em-websocket', :git => 'http://github.com/dj2/em-websocket', :branch => 'factory_change' | |||
gem 'http_parser.rb', :git => 'http://github.com/dj2/http_parser.rb', :branch => 'upgrade_data' | |||
|
|||
gemspec | gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,64 @@ | |||
# HISTORY | |||
|
|||
## v0.9.3 (Oct 16, 2011) | |||
|
|||
- new router DSL - much improved, see examples | |||
- refactored async_aroundware | |||
- make jruby friendlier (removed 1.9 req in gemspec) | |||
- enable epoll | |||
- SSL support | |||
- unix socket support | |||
- reload config on HUP | |||
- and a number of small bugfixes + other improvements.. | |||
- See full list @ https://github.com/postrank-labs/goliath/compare/v0.9.2...v0.9.3 | |||
|
|||
## v0.9.2 (July 21, 2011) | |||
|
|||
- See full list @ https://github.com/postrank-labs/goliath/compare/v0.9.1...v0.9.2 | |||
|
|||
## v0.9.1 (Apr 12, 2011) | |||
|
|||
- Added extra messaging around the class not matching the file name (Carlos Brando) | |||
|
|||
- Fix issue with POST parameters not being parsed by Goliath::Rack::Params | |||
- Added support for multipart encoded POST bodies | |||
- Added support for parsing nested query string parameters (Nolan Evans) | |||
- Added support for parsing application/json POST bodies | |||
- Content-Types outside of multipart, urlencoded and application/json will not be parsed automatically. | |||
|
|||
- added 'run as user' option | |||
- SERVER_NAME and SERVER_PORT are set to values in HOST header | |||
|
|||
- Cleaned up spec examples (Justin Ko) | |||
|
|||
- moved logger into 'rack.logger' key to be more Rack compliant (Env#logger added to | |||
keep original API consistent) | |||
- add command line option for specifying config file | |||
- HTTP_CONTENT_LENGTH and HTTP_CONTENT_TYPE were changed to CONTENT_TYPE and CONTENT_LENGTH | |||
to be more Rack compliant | |||
- fix issue with loading config file in development mode | |||
|
|||
- Rack::Reloader will be loaded automatically by the framework in development mode. | |||
|
|||
|
|||
## v0.9.0 (Mar 9, 2011) | |||
|
|||
(Initial Public Release) | |||
|
|||
Goliath is an open source version of the non-blocking (asynchronous) Ruby web server framework | |||
powering PostRank. It is a lightweight framework designed to meet the following goals: bare | |||
metal performance, Rack API and middleware support, simple configuration, fully asynchronous | |||
processing, and readable and maintainable code (read: no callbacks). | |||
|
|||
The framework is powered by an EventMachine reactor, a high-performance HTTP parser and Ruby 1.9 | |||
runtime. One major advantage Goliath has over other asynchronous frameworks is the fact that by | |||
leveraging Ruby fibers, it can untangle the complicated callback-based code into a format we are | |||
all familiar and comfortable with: linear execution, which leads to more maintainable and readable code. | |||
|
|||
While MRI is the recommend platform, Goliath has been tested to run on JRuby and Rubinius. | |||
|
|||
Goliath has been in production at PostRank for over a year, serving a sustained 500 requests/s for | |||
internal and external applications. Many of the Goliath processes have been running for months at | |||
a time (read: no memory leaks) and have served hundreds of gigabytes of data without restarts. To | |||
scale up and provide failover and redundancy, our individual Goliath servers at PostRank are usually | |||
deployed behind a reverse proxy (such as HAProxy). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
#!/usr/bin/env ruby | |||
|
|||
# Rewrites and proxies requests to a third-party API, with HTTP basic authentication. | |||
|
|||
require 'goliath' | |||
require 'em-synchrony/em-http' | |||
|
|||
class TwilioResponse < Goliath::API | |||
use Goliath::Rack::Params | |||
use Goliath::Rack::JSONP | |||
|
|||
HEADERS = { authorization: ENV.values_at("TWILIO_SID","TWILIO_AUTH_TOKEN") } | |||
BASE_URL = "https://api.twilio.com/2010-04-01/Accounts/#{ENV['TWILIO_SID']}/AvailablePhoneNumbers/US" | |||
|
|||
def response(env) | |||
url = "#{BASE_URL}#{env['REQUEST_PATH']}?#{env['QUERY_STRING']}" | |||
logger.debug "Proxying #{url}" | |||
|
|||
http = EM::HttpRequest.new(url).get head: HEADERS | |||
logger.debug "Received #{http.response_header.status} from Twilio" | |||
|
|||
[200, {'X-Goliath' => 'Proxy','Content-Type' => 'application/javascript'}, http.response] | |||
end | |||
end | |||
|
|||
class Twilio < Goliath::API | |||
get %r{^/(Local|TollFree)}, TwilioResponse | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,85 @@ | |||
#!/usr/bin/env ruby | |||
$: << File.dirname(__FILE__)+'/../lib' | |||
|
|||
require 'goliath' | |||
require 'em-synchrony/em-http' | |||
require 'yajl/json_gem' | |||
|
|||
# | |||
# Here's a way to make an asynchronous request in the middleware, and only | |||
# proceed with the response when both the endpoint and our middleware's | |||
# responses have completed. | |||
# | |||
# To run this, start the 'test_rig.rb' server on port 9002: | |||
# | |||
# bundle exec ./examples/test_rig.rb -sv -p 9002 | |||
# | |||
# And then start this server on port 9000: | |||
# | |||
# bundle exec ./examples/barrier_aroundware_demo.rb -sv -p 9000 | |||
# | |||
# Now curl the async_aroundware_demo_multi: | |||
# | |||
# $ time curl 'http://127.0.0.1:9000/?delay_1=1.0&delay_2=1.5' | |||
# { "results": { | |||
# "sleep_2": { "delay": 1.5, "actual": 1.5085558891296387 }, | |||
# "sleep_1": { "delay": 1.0, "actual": 1.0098700523376465 } | |||
# } } | |||
# | |||
# The requests are run concurrently: | |||
# | |||
# $ ./examples/async_aroundware_demo.rb -sv -p 9000 -e prod & | |||
# [68463:INFO] 2011-05-03 23:13:03 :: Starting server on 0.0.0.0:9000 in production mode. Watch out for stones. | |||
# $ ab -n10 -c10 'http://127.0.0.1:9000/?delay_1=1.5&delay_2=2.0' | |||
# Connection Times (ms) | |||
# min mean[+/-sd] median max | |||
# Connect: 0 0 0.1 0 0 | |||
# Processing: 2027 2111 61.6 2112 2204 | |||
# Waiting: 2027 2111 61.5 2112 2204 | |||
# Total: 2027 2112 61.5 2113 2204 | |||
# | |||
# | |||
|
|||
BASE_URL = 'http://localhost:9002/' | |||
|
|||
class RemoteRequestBarrier | |||
include Goliath::Rack::BarrierAroundware | |||
attr_accessor :sleep_1 | |||
|
|||
def pre_process | |||
# Request with delay_1 and drop_1 -- note: 'aget', because we want execution to continue | |||
req = EM::HttpRequest.new(BASE_URL).aget(:query => { :delay => env.params['delay_1'], :drop => env.params['drop_1'] }) | |||
enqueue :sleep_1, req | |||
return Goliath::Connection::AsyncResponse | |||
end | |||
|
|||
def post_process | |||
# unify the results with the results of the API call | |||
if successes.include?(:sleep_1) then body[:results][:sleep_1] = JSON.parse(sleep_1.response) | |||
else body[:errors][:sleep_1] = sleep_1.error ; end | |||
[status, headers, JSON.pretty_generate(body)] | |||
end | |||
end | |||
|
|||
class BarrierAroundwareDemo < Goliath::API | |||
use Goliath::Rack::Params | |||
use Goliath::Rack::Validation::NumericRange, {:key => 'delay_1', :default => 1.0, :max => 5.0, :min => 0.0, :as => Float} | |||
use Goliath::Rack::Validation::NumericRange, {:key => 'delay_2', :default => 0.5, :max => 5.0, :min => 0.0, :as => Float} | |||
# | |||
use Goliath::Rack::BarrierAroundwareFactory, RemoteRequestBarrier | |||
|
|||
def response(env) | |||
# Request with delay_2 and drop_2 -- note: 'get', because we want execution to proceed linearly | |||
resp = EM::HttpRequest.new(BASE_URL).get(:query => { :delay => env.params['delay_2'], :drop => env.params['drop_2'] }) | |||
|
|||
body = { :results => {}, :errors => {} } | |||
|
|||
if resp.response_header.status.to_i != 0 | |||
body[:results][:sleep_2] = JSON.parse(resp.response) rescue 'parsing failed' | |||
else | |||
body[:errors ][:sleep_2] = resp.error | |||
end | |||
|
|||
[200, { }, body] | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.