Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 19, 2011
Ruben Nine Updating async-rails demo to work with em_postgresql 0.3 8650aa8
Ruben Nine Using em_postgresql on heroku e9e85c8
Commits on Jan 03, 2013
@cluesque cluesque Slow action produces results incrementally dc1722c
@cluesque cluesque Adapt database.yml for my setup
(also, use em_postgresql, fixing a bug in the heroku commit?)
9cafc0a
View
9 Gemfile
@@ -13,12 +13,17 @@ gem 'jquery-rails'
# async wrappers
gem 'eventmachine'
gem 'rack-fiber_pool', :require => 'rack/fiber_pool'
-gem 'em-synchrony', :require => ['em-synchrony',
+
+gem 'em-synchrony', :git => 'git://github.com/leftbee/em-synchrony.git',
+ :require => ['em-synchrony',
'em-synchrony/em-http',
'em-synchrony/activerecord']
# async activerecord requires
-gem 'mysql2'
+gem 'pg'
+
+gem 'em-postgresql-adapter', :git => 'git://github.com/leftbee/em-postgresql-adapter.git'
+ #:path => '/Users/ruben/src/work/em-postgresql-adapter'
# async http requires
gem 'em-http-request', :require => 'em-http'
View
32 Gemfile.lock
@@ -1,3 +1,19 @@
+GIT
+ remote: git://github.com/leftbee/em-postgresql-adapter.git
+ revision: 6313a6c5c48fd9d141f60c22ae9c12c2eca1b329
+ specs:
+ em-postgresql-adapter (0.3)
+ activerecord (>= 3.1.0)
+ eventmachine
+ pg (>= 0.8.0)
+
+GIT
+ remote: git://github.com/leftbee/em-synchrony.git
+ revision: 6a414e0fefe1c3e7f3f76db2b607080f422516cf
+ specs:
+ em-synchrony (1.0.0)
+ eventmachine (>= 1.0.0.beta.1)
+
GEM
remote: http://rubygems.org/
specs:
@@ -46,8 +62,6 @@ GEM
http_parser.rb (>= 0.5.2)
em-socksify (0.1.0)
eventmachine
- em-synchrony (1.0.0)
- eventmachine (>= 1.0.0.beta.1)
erubis (2.7.0)
eventmachine (1.0.0.beta.3)
execjs (1.2.4)
@@ -64,7 +78,8 @@ GEM
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.3)
- mysql2 (0.3.7)
+ pg (0.12.0)
+ rake-compiler (~> 0.7)
polyglot (0.3.2)
rack (1.3.2)
rack-cache (1.0.3)
@@ -92,6 +107,8 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2)
+ rake-compiler (0.7.9)
+ rake
rdoc (3.9.4)
sass (3.1.7)
sass-rails (3.1.0)
@@ -100,11 +117,11 @@ GEM
sass (>= 3.1.4)
sinatra (1.2.6)
rack (~> 1.1)
- tilt (< 2.0, >= 1.2.2)
+ tilt (>= 1.2.2, < 2.0)
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
- tilt (!= 1.3.0, ~> 1.1)
+ tilt (~> 1.1, != 1.3.0)
thin (1.2.11)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
@@ -126,10 +143,11 @@ DEPENDENCIES
addressable
coffee-script
em-http-request
- em-synchrony
+ em-postgresql-adapter!
+ em-synchrony!
eventmachine
jquery-rails
- mysql2
+ pg
rack-fiber_pool
rails (= 3.1.0)
sass-rails
View
20 app/controllers/widgets_controller.rb
@@ -1,9 +1,27 @@
+class SlowResponder
+ def each(&blk)
+ Rails.logger.info("Slow request start")
+ (1..40).each do |i|
+ Widget.uncached { Widget.find_by_sql("select pg_sleep(1)") }
+ # sleep 1.0
+ puts "Yielding #{i}"
+ yield "Bueller #{i}\n"
+ end
+ Rails.logger.info("Slow request end")
+ end
+end
+
class WidgetsController < ApplicationController
def index
- Widget.find_by_sql("select sleep(1)")
+ Widget.find_by_sql("select pg_sleep(1)")
render :text => "Oh hai"
end
+ def slow
+ response.headers['Cache-Control'] = 'no-cache'
+ self.response_body = SlowResponder.new
+ end
+
def http
# going meta, query yourself, on the same thin server!
http = EM::HttpRequest.new("http://#{request.host}:#{request.port}/widgets").get
View
23 config/database.yml
@@ -1,25 +1,24 @@
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
- adapter: em_mysql2
- database: widgets
- username: root
- pool: 250
- timeout: 5000
+ adapter: em_postgresql
+ database: async-rails
+ username: www
+ host: /tmp
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: em_mysql2
- database: widgets_test
- username: root
+ adapter: em_postgresql
+ database: async-rails_test
+ # username: ruben
pool: 5
- timeout: 5000
+ host: /tmp
production:
- adapter: em_mysql2
+ adapter: em_postgresql
database: widgets
- username: root
+ username: ruben
pool: 200
- timeout: 5000
+ host: /tmp
View
3  config/environment.rb
@@ -1,5 +1,8 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
+# Uncomment if you are running this app on Heroku
+#require 'em_postgresql_on_heroku'
+
# Initialize the rails application
AsyncRails3::Application.initialize!
View
1  config/routes.rb
@@ -57,6 +57,7 @@
# mount async sinatra app (in metal folder)
match '/twitter', :to => Twitter
+ get '/slow' => 'widgets#slow'
match ':controller(/:action(/:id(.:format)))'
end
View
8 lib/em_postgresql_on_heroku.rb
@@ -0,0 +1,8 @@
+# Heroku hack to replace the original PostgreSQL adapter with EMPostgreSQL in a hackerish way
+
+puts 'Using EMPostgreSQL instead of PostgreSQL!'
+class ActiveRecord::Base
+ class << self
+ alias :postgresql_connection :em_postgresql_connection
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.