Load Balancer HTTP & WebSocket Protocols

The component TsgcWebSocketLoadBalancerServer has been improved for sgcWebSockets 2024.3.0 version. Now supports the HTTP Protocol, previously only supported WebSockets, and has a couple of new events to fine-tune the HTTP Requests. The Load Balancer server now descends from the TsgcWebSocketHTTPServer, so inherits all the methods and properties of this.


Load Server Configuration

The Load Balancer server it's a descendant of TsgcWebSocketHTTPServer, so read the documentation about the TsgcWebSocketHTTPServer to know how to configure it.

Additionally, the Load Balancer has the property LoadBalancer, which has the following properties:

  • LoadBalancing: configure here how distribute the connections
    • lbRandom: (default) every time a new client request a new connection, it will return a random server.
    • lbConnections: every time a new client request a new connection, it will return server with fewer clients connected.
  • Protocols: configure which protocols are enabled
    • WebSocket: if true, the websocket connections will be handled by the Load Balancer Server.
    • HTTP: if true, the http connections will be handled by the Load Balancer Server.

Backup Server Configuration

The Backup Servers (the servers behind the load balancer) can be a TsgcWebSocketServer, TsgcWebSocketHTTPServer or a DataSnap Server.

Those servers have a property called LoadBalancer where you can configure the connection between the LoadBalancer Server and the Backup Servers.

  • Enabled: set to true if you want to use as a backup server.
  • Host: the host were is the LoadBalancer.
  • Port: the listening port of the LoadBalancer.
  • Guid: unique id that identifies this server.
  • Bindings: the public addresses accessible were the connections will be forwarded. Example: if the Backup WebSocket server is listening on port 8000 and the ip address is 1.1.1.1, use the following: ws://1.1.1.1:8000;
  • AutoRegisterBindings: if enabled, the LoadBalancer Server will use the Bindings property of the backup server to configure the public bindings.
  • AutoRestart: in seconds, if greater than zero, the load balancer client of the backup server will enable an internal watchdog that every x seconds, will check if the connection is alive, if it's closed, it will try to reconnect.

Sample

Find below a link to download a compiled demo for Windows which shows how put a Load Balancing Server which forward the HTTP requests randomly to 3 servers. 

sgcLoadBalancerServer
6.1 mb
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

sgcWebSockets 2024.3.0
Updated Telegram Libraries for Delphi, CBuilder & ...

Related Posts