Code Monkey home page Code Monkey logo

connpool's Introduction

Connection pool

Build Status

Lua connection pool for tarantool net.box with network zones support.

API

  • pool:init(cfg) - init connection pool with given config
  • pool:one(zone_id) - returns random active connection from given zone(can be nil)
  • pool:all(zone_id) - returns all active connections from given zone(can be nil)
  • pool:zone_list() - returns list of network zones ids
  • pool:get_heartbeat() - returns monitoring state

if zone_id is nil - return connections from all zones

Available callbacks

  • on_connected - all nodes connected
  • on_connected_one - one node connected
  • on_disconnect - lost all connations in pool
  • on_disconnect_one - one node disconnect
  • on_disconnect_zone - all nodes in zone disconnected
  • on_connfail - monitoring detected connection problem
  • on_init - init complete, monitoring fibers started

Configuration

global:

  • pool_name - connection pool id
  • monitor - enable connection monitoring(by default true)
  • servers - table with servers settings

servers:

  • uri - server uri with port
  • login
  • password
  • zone - network zone(can be nil)

Example

p = require('connpool')

-- create new pool
pool = p.new()
-- set callback
pool.on_connected = function(self)
    log.info('hello world')
end

-- config with 2 nodes in 2 zones and monitoring
local cfg = {
    pool_name = 'mypool';
    servers = {
        {
            uri = 'localhost:3313', login = 'tester',
            password = 'pass', zone = 'myzone1'
        };
        {
            uri = 'localhost:3314', login = 'tester',
            password = 'pass', zone = 'myzone2'
        };
    };
    monitor = true;
}

-- start
pool:init(cfg)

if there is no zone specified - all servers are in single zone

connpool's People

Contributors

amdrozdov avatar rtsisyk avatar bigbes avatar totktonada avatar opomuc avatar

Watchers

James Cloos 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.