All pages
Powered by GitBook
1 of 1

Loading...

Galera Load Balancer (glbd)

The Galera Load Balancer (glbd) is no longer under active development. It is provided here for historical and reference purposes only. For new deployments, we recommend using a modern, fully supported proxy such as MariaDB MaxScale.

Galera Load Balancer (glbd) is a simple, multi-threaded TCP connection balancer, optimized for database workloads.

It was inspired by pen, but unlike it, GLB focuses only on balancing generic TCP connections.

Features

Feature
Description

Installation

GLB must be built from source. There are no pre-built packages.

This installs:

  • glbd (daemon) → /usr/sbin

  • libglb (shared library)

Running as a Service

To run as a service:

Manage with:

Configuration

GLB can be configured either via command-line options or via a configuration file.

Command-Line Options {#command-line-options}

Configuration File (glbd.cfg)

Parameter
Description

Example:

Destination Selection Policies

GLB supports five policies:

Policy
Description

-T | --top option: restricts balancing to servers with the highest weight.

Runtime Management

GLB can be managed at runtime via:

  • FIFO file

  • Control socket (-c <addr:port>)

Commands

Command
Example
Description

Performance Statistics

Example:

Field
Description

Watchdog

The watchdog module performs asynchronous health checks beyond simple TCP reachability.

Enable with:

  • Runs mysql.sh with host:port as first argument.

  • Exit code 0 = healthy, non-zero = failure.

  • Use -i to set check interval.

libglb (Shared Library)

libglb enables transparent load balancing by intercepting the connect() system call.

Basic Example

Environment Variables

Variable
Description

Operational Limits

  • Limited by system open files (ulimit -n)

  • With default 1024 → ~493 connections

  • With 4096 (typical unprivileged user) → ~2029 connections

See Also

  • – recommended modern proxy

This page is licensed: CC BY-SA / Gnu FDL

Get stats

echo "getstat" | nc 127.0.0.1 4444

Show raw performance counters

With Galera, -D|--discover enables auto-discovery of nodes.

Adjust in /etc/security/limits.conf if needed

Server Draining

Remove servers smoothly without interrupting active connections.

High Performance

Uses Linux epoll API (2.6+).

Multithreading

Leverages multi-core CPUs for better performance.

Optional Watchdog Module

Monitors server health.

Seamless Client Integration

Uses libglb for load balancing without changing applications, by intercepting connect() calls.

LISTEN_ADDR

Address/port GLB listens on for client connections

DEFAULT_TARGETS

Space-separated list of backend servers

OTHER_OPTIONS

Extra GLB options (e.g. balancing policy)

Least Connected(default)

Routes new connections to the server with the fewest active connections (adjusted for weight).

Round Robin

Sequentially cycles through available servers.

Single

Routes all connections to the highest-weight server until it fails or a higher-weight server is available.

Random

Distributes connections randomly among servers.

Source Tracking

Routes all connections from the same client IP to the same server (best-effort).

Add/Modify server

echo "192.168.0.1:3307:5" | nc 127.0.0.1 4444

Add backend with weight 5

Drain server

echo "192.168.0.1:3307:0" | nc 127.0.0.1 4444

Stop new connections, keep existing

Delete server

echo "192.168.0.1:3307:-1" | nc 127.0.0.1 4444

Remove backend and close active connections

Get routing table

echo "getinfo" | nc 127.0.0.1 4444

Show backends, weight, usage, connections

in / out

Bytes received/sent via client interface

recv / send

Bytes passed and number of recv()/send() calls

conns

Created / concurrent connections

poll

Read-ready / write-ready / total poll calls

elapsed

Time since last report (seconds)

GLB_WATCHDOG

Same as --watchdog option

GLB_TARGETS

Comma-separated list of backends (H:P:W)

GLB_BIND

Local bind address for intercepted connections

GLB_POLICY

Balancing policy (single, random, source)

GLB_CONTROL

Control socket for runtime commands

MariaDB MaxScale
Codership GLB on GitHub
git clone https://github.com/codership/glb
cd glb/
./bootstrap.sh
./configure
make
sudo make install
# cp files/glbd.sh /etc/init.d/glb
# cp files/glbd.cfg /etc/sysconfig/glbd.cfg   # Red Hat / CentOS
# cp files/glbd.cfg /etc/default/glbd.cfg     # Debian / Ubuntu
service glb start|stop|restart|getinfo|getstats|add|remove|drain
glbd --help
# Galera Load Balancer Configuration
LISTEN_ADDR="8010"
DEFAULT_TARGETS="192.168.1.1 192.168.1.2 192.168.1.3"
OTHER_OPTIONS="--random --top 3"
echo "getstat" | nc -q 1 127.0.0.1 4444
in: 6930 out: 102728 recv: 109658 / 45 send: 109658 / 45 conns: 0 / 4 poll: 45 / 0 / 45 elapsed: 1.03428
glbd -w exec:"mysql.sh -utest -ptestpass" -t 2 3306 192.168.0.1 192.168.0.2
export LD_PRELOAD=/path/to/libglb.so
export GLB_OPTIONS="--random 3306 192.168.0.1 192.168.0.2 192.168.0.3"

mysql -uroot -p -h127.0.0.1 -P3306