Membrane API Gateway can balance requests across backend nodes that are added and removed dynamically at runtime.
Nodes can be organized in clusters. You can manage them either through the web-based administration console or via a simple URL-based API.
- One Membrane router as the load balancer
- Three sample web apps simulating backend nodes (ports 4000, 4001, 4002)
- A web-based admin console for cluster and node management
- An HTTP API for programmatic node control
-
Go to the
examples/loadbalancing/2-dynamicdirectory.cd examples/loadbalancing/2-dynamic -
Start Membrane:
- macOS/Linux:
./membrane.sh - Windows:
membrane.cmd
- macOS/Linux:
-
Open in a browser:
http://localhost:4000You will see a simple counter app. Identical apps are also available on ports
4001and4002. -
Open the Admin Console:
http://localhost:9000/admin -
Go to the Load Balancing tab.
- Click the entry
Default. - Enter
Defaultas the cluster name. - Click Add Cluster.
- Click the entry
-
Add the first node:
- Host:
localhost - Port:
4000 - Click Add Node.
- Host:
-
Open in a browser:
http://localhost:8080Refresh a few times. All requests go to node 4000.
-
Add a second node (
localhost:4001) using the same steps. -
Open:
http://localhost:8080Now requests are distributed between node 4000 and node 4001.
-
Add a third node (
localhost:4002) to see full load balancing across three backends.
Nodes can also be controlled programmatically using the Cluster Manager API. For example, to temporarily disable node localhost:4001:
curl "http://localhost:9010/clustermanager/down?balancer=default&host=localhost&port=4001"Re-enable the node with .../up?balancer=....
- The
adminConsoleandclusterNotificationinterceptors inproxies.xmlare optional. You can remove them if you only want programmatic control. - This example defaults to round-robin balancing.
See:
- proxies.xml
- balancer reference