Git Product home page Git Product logo

load_balancer_adapter's Introduction

load_balancer_adapter

[NOTE: Compatible with ActiveRecord 3.1.x only.]

Load balances connections across multiple database hosts.

The adapter cycles through hosts, creating a connection to a new host each time.

The gem also patches ActiveRecord's ConnectionPool to return a random connection from it's available connections instead of the first one, since in a single-threaded server the same connection would get checked out and checked-in repeatedly.

Usage

    ActiveRecord::Base.configurations[:development] = {
        :adapter => 'load_balancer',        # <-- change the adapter to 'load_balancer'
        :actual_adapter => 'mysql',         # <--- actual_adapter is the underlying adapter you want to use to connect to the database
        :hosts => ['127.0.0.1','localhost'] # <--- array of database host names
        :encoding => 'utf8',
        :reconnect => true,
        :database => 'information_schema',
        :pool => 2,
        :username => 'root',
        :password => '',
    }

    pool = ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[:development])

    first_conn = pool.checkout
    puts first_conn.instance_eval("@config")[:host]  # <--- prints "127.0.0.1"

    second_conn = pool.checkout
    puts second_conn.instance_eval("@config")[:host]  # <--- prints "localhost"

load_balancer_adapter's People

Contributors

dhiraj2kumar avatar

Stargazers

Chirag Aggarwal avatar

Watchers

Janmejay Singh avatar Vinay Y S avatar  avatar Phaneesh avatar srikara avatar Nikhil Bafna avatar Regunath B avatar James Cloos avatar  avatar Smit Shah avatar  avatar  avatar  avatar Poornima avatar  avatar  Anand Immannavar avatar Tarun Mangal avatar Rahul Madhavan K avatar Deepti Agrawal avatar  avatar Mohit Ranjan avatar Anshul Gupta avatar  avatar  avatar Abhishek Sharan avatar  avatar  avatar Shoury avatar Kartik Ukhalkar avatar kaustubh avatar Bhavdeep Sethi avatar Puneet avatar Arya Ketan avatar  avatar Ravindra Yadav avatar Sudeep Kumar Moharana avatar  avatar Yogesh Dahiya avatar Rohit Kalhans avatar Himanshu Virmani avatar  avatar  avatar Amit Kumar Goldy avatar  avatar  avatar  avatar Sourav Mitra avatar Charu Jain avatar  avatar Arun Ray avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.