Module: LoadBalancer

Extended by:
ActiveSupport::Concern
Defined in:
lib/multi_dbs_load_balancer/load_balancer.rb,
lib/multi_dbs_load_balancer/load_balancer/algo.rb,
lib/multi_dbs_load_balancer/load_balancer/hash.rb,
lib/multi_dbs_load_balancer/load_balancer/errors.rb,
lib/multi_dbs_load_balancer/load_balancer/randomized.rb,
lib/multi_dbs_load_balancer/load_balancer/round_robin.rb,
lib/multi_dbs_load_balancer/load_balancer/least_connection.rb,
lib/multi_dbs_load_balancer/load_balancer/weight_round_robin.rb,
lib/multi_dbs_load_balancer/load_balancer/least_response_time.rb

Defined Under Namespace

Modules: ClassMethods Classes: Algo, AllDatabasesHaveDown, Hash, LeastConnection, LeastResponseTime, Randomized, RoundRobin, WeightRoundRobin

Class Method Summary collapse

Class Method Details

.init(name, db_configs, algorithm: :round_robin, redis: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/multi_dbs_load_balancer/load_balancer.rb', line 21

def init(name, db_configs, algorithm: :round_robin, redis: nil)
    lb_algo_clazz = "LoadBalancer::#{algorithm.to_s.classify}".constantize
    LoadBalancer.lb[name] = {
        clazz: lb_algo_clazz,
        db_configs: db_configs,
        redis: redis,
        key: name
    }

    DistributeLock.new(redis).synchronize(name) do
        lb = lb_algo_clazz.new(db_configs, redis: redis, key: name)
        lb.warm_up
    end
end