3

I am using Rails 3.0.9. (With ruby 1.9.3) I have been looking into some replication gems (data_fabric, octopus, multi_db).

Been wondering what is the best solution. Production ready, fast, AR3 compatible...

I thought it was octopus till I saw this issue: https://github.com/tchandy/octopus/issues/60

I don't need sharding at this point, all I needs is the ability to send Reads to the slaves, and writes to the master.

What is the best solution for the above needs?

KensoDev
  • 3,285
  • 21
  • 38
  • Can you answer my question here http://stackoverflow.com/questions/29445495/rails-how-to-split-write-read-query-across-master-slave-database?noredirect=1#comment47064893_29445495 – Sanjay Salunkhe Apr 11 '15 at 06:04

1 Answers1

1

Octopus is still the one to pick, despite that issue. We use it at Square for the use case you describe.

Commits to relax the dependency went in directly after v0.4.0, so it's safe to lock to a git revision:

gem 'octopus',
  :git => 'https://github.com/tchandy/octopus.git',
  :ref => '7e585ecd35d3caf9b5d23a0265e709716740a3ce'

Other changes in master look mostly 3.1 and spec related, plus a single performance commit (my commit), so it's probably fine also.

For reference, we're running a fork of v0.4.0 amended to allow AR 2.3, plus a performance related commit which is now on master (not critical if you're not doing heaps of traffic, but nice.)

git diff v0.4.0..7e585ecd35d3caf9b5d23a0265e709716740a3ce

diff --git a/Gemfile b/Gemfile
index e82375d..c3bcf77 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,7 +1,7 @@
 source :rubygems

-gem 'activerecord', '3.0.6'
-gem 'actionpack', '3.0.6'
+gem 'activerecord', '~> 3.0'
+gem 'actionpack', '~> 3.0'

 group :test do
   gem "rake", ">= 0.8.7"
diff --git a/Gemfile.lock b/Gemfile.lock
index a80476c..a82c18f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -58,8 +58,8 @@ PLATFORMS
   ruby

 DEPENDENCIES
-  actionpack (= 3.0.6)
-  activerecord (= 3.0.6)
+  actionpack (~> 3.0)
+  activerecord (~> 3.0)
   jeweler (>= 1.4)
   mysql2
   pg (>= 0.9.0)
diff --git a/ar-octopus.gemspec b/ar-octopus.gemspec
index 9e5f73e..2b06df4 100644
--- a/ar-octopus.gemspec
+++ b/ar-octopus.gemspec
@@ -171,8 +171,8 @@ Gem::Specification.new do |s|
     s.specification_version = 3

     if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
-      s.add_runtime_dependency(%q<activerecord>, ["= 3.0.6"])
-      s.add_runtime_dependency(%q<actionpack>, ["= 3.0.6"])
+      s.add_runtime_dependency(%q<activerecord>, ["~> 3.0"])
+      s.add_runtime_dependency(%q<actionpack>, ["~> 3.0"])
       s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
       s.add_development_dependency(%q<mysql2>, [">= 0"])
       s.add_development_dependency(%q<pg>, [">= 0.9.0"])
@@ -181,8 +181,8 @@ Gem::Specification.new do |s|
       s.add_development_dependency(%q<actionpack>, [">= 2.3"])
       s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
     else
-      s.add_dependency(%q<activerecord>, ["= 3.0.6"])
-      s.add_dependency(%q<actionpack>, ["= 3.0.6"])
+      s.add_dependency(%q<activerecord>, ["~> 3.0"])
+      s.add_dependency(%q<actionpack>, ["~> 3.0"])
       s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
       s.add_dependency(%q<mysql2>, [">= 0"])
       s.add_dependency(%q<pg>, [">= 0.9.0"])
@@ -192,8 +192,8 @@ Gem::Specification.new do |s|
       s.add_dependency(%q<activerecord>, [">= 2.3"])
     end
   else
-    s.add_dependency(%q<activerecord>, ["= 3.0.6"])
-    s.add_dependency(%q<actionpack>, ["= 3.0.6"])
+    s.add_dependency(%q<activerecord>, ["~> 3.0"])
+    s.add_dependency(%q<actionpack>, ["~> 3.0"])
     s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
     s.add_dependency(%q<mysql2>, [">= 0"])
     s.add_dependency(%q<pg>, [">= 0.9.0"])
diff --git a/lib/octopus/association_collection.rb b/lib/octopus/association_collection.rb
index 2dbff87..44d0f7a 100644
--- a/lib/octopus/association_collection.rb
+++ b/lib/octopus/association_collection.rb
@@ -12,4 +12,8 @@ module Octopus::AssociationCollection
   end
 end

-ActiveRecord::Associations::AssociationCollection.send(:include, Octopus::AssociationCollection)
\ No newline at end of file
+if ActiveRecord::VERSION::MAJOR >= 3 && ActiveRecord::VERSION::MINOR >=1
+  ActiveRecord::Associations::CollectionAssociation.send(:include, Octopus::AssociationCollection)
+else
+  ActiveRecord::Associations::AssociationCollection.send(:include, Octopus::AssociationCollection)
+end
diff --git a/lib/octopus/migration.rb b/lib/octopus/migration.rb
index 70bd8bd..7d9fd90 100644
--- a/lib/octopus/migration.rb
+++ b/lib/octopus/migration.rb
@@ -70,4 +70,8 @@ module Octopus::Migration
   end
 end

-ActiveRecord::Migration.extend(Octopus::Migration)
+if ActiveRecord::VERSION::MAJOR >= 3 && ActiveRecord::VERSION::MINOR >=1
+  ActiveRecord::Migration.send :include, Octopus::Migration
+else
+  ActiveRecord::Migration.extend(Octopus::Migration)
+end
```
Xavier Shay
  • 4,067
  • 1
  • 30
  • 54
  • Thank you. Since posting this I actually went with data_fabric, though I think after your message, it's safe to say that octopus is better, it looked better from the get go, the only problem is that it had the dependency. – KensoDev Jan 03 '12 at 07:52
  • I would give you +10 if I could :-) – KensoDev Jan 03 '12 at 07:52