Some test text!
Web / FAQ / Manual Load Balancing
WebViewer Server comes with a load balancer known as HAProxy
located at our pdftron/wv-loadbalancer repository on DockerHub. This can be used in conjunction with WebViewer Server to load balance.
This guide details how to manage load balancing using the HAProxy image, in a way that is extensible to any environment.
HAProxy contains network entries called webA
webB
webC
... and so on. These entries indicate the location of a server that HAProxy can send requests to. The methods here will modify these entries to point at the correct server.
By default WebViewer Server does all load balancing using the leastconn method. This sends incoming requests to servers with the smallest number of active connections.
You can set the initial locations of these webX
entries by setting the environment variables INITIAL_NODE_A
INITIAL_NODE_B
... up to INITIAL_NODE_F
on the wv-loadbalancer
image. HAProxy will initially send requests to any healthy and responding servers set in these variables.
To set servers dynamically with HAProxy you can take advantage of something known as TCP Management - this can be used to change these webX
entries to the current location of a server.
There are several ways to send requests to the server with this method, but all commands to HAProxy will be sent with the same structure.
set server nodes/[webX] addr [WVS ip address] [WVS port]
socat /var/run/hapee.sock set server nodes/webA addr 192.168.1.1 8090
ENABLE_TCP_MANAGEMENT
to true on the Docker image and sending requests to the TCP Management port 4893
wherever the balancer is located. The following code does this using Node.js.const connectSocket = (balancer) => {
return new Promise((resolve, reject) => {
var socket = new net.createConnection(4893, balancer);
socket.on('connect', () => {
resolve(socket);
});
socket.on('error', () => {
reject(balancer + ": Balancer not online.");
});
});
};
const writeSocket = (command, socket, forceClose) => {
return new Promise((resolve, reject) => {
console.log(command);
socket.write(command, (error, data) => {
if (error) {
console.log(error);
reject();
}
});
socket.on('data', (data) => {
//console.log("balancer response:" + data);
socket.end();
resolve(data);
});
});
};
command = "set server nodes/webA addr 192.168.1.1 8090\n"
var socket = await connectSocket("insert balancer ip here");
await writeSocket(command, socket, false)
The above code sets webA
to be the Webviewer Server at 192.168.1.1:8090
. HAProxy will now send webA
requests to this server.
Whenever a change occurs, you can dynamically rewrite remotely using the above code. The changes will instantly occur. More commands can be found at the HAProxy Management documentation
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales