Broker as a load-balancing router

You can configure the broker to act as a load-balancing router among Edge Servers. When you configure a broker to act as a router, the broker creates a db.routing file. This file provides a mapping of client workspaces and users to specific servers. In effect, this file routes a given incoming command to the appropriate server, such as the Commit Server or a specific Edge Server.

Tip

Depending on your use case, using a different approach might be preferable. See Multi-server architectures.

Configure the broker as a router

To configure the broker as a router:

  1. Add the router statement to the top level of the broker configuration. The target server of the broker-router should be a commit or master server. For example:

  2. target      = commitserv.example.com:1666;
    listen      = 1667;
    directory   = /p4/broker;
    logfile     = broker.log;
    debug-level = server=1;
    admin-name  = "Perforce Admins";
    admin-phone = 999/911;
    admin-email = perforce-admins@example.com;
    router;
  3. Include altserver statements to specify the Edge Servers of the Commit Server that is the target server of the broker-router. For example:

altserver: edgeserv1
{
    target = edgeserve1.example.com:1669;
}
altserver: edgeserv2
{
    target = edgeserve2.example.com:1668;
}
Note
  • altserver names must match the server IDs

  • If you are using the broker to route messages for a commit-edge architecture, you must list the altserver names of all existing Edge Servers

Routing policy and behavior

When a command arrives at the broker, the broker uses the mapping to determine where the command should be routed. The routing logic attempts to bind a user to a server where that user already has client workspaces. You can modify the routing choice on the p4 command line by using the following argument to override routing for that command.

-Zroute=serverID

If a client and user have no binding to an existing Edge Server, an existing altserver is chosen at random.

To route requests to the Commit Server

Use a destination form similar to this:

target      = commitserv.example.com:1666;
listen      = 1667;
directory   = /p4/broker;
logfile     = broker.log;
debug-level = server=1;
admin-name  = "Perforce Admins";
admin-phone = 999/911;
admin-email = perforce-admins@example.com;
router;
destination target;

To cause new users to be bound to a new Edge Server

Use a destination form similar to this:

target      = commitserv.example.com:1666;
listen      = 1667;
directory   = /p4/broker;
logfile     = broker.log;
debug-level = server=1;
admin-name  = "Perforce Admins";
admin-phone = 999/911;
admin-email = perforce-admins@example.com;
router;
destination "myNewEdge";

where "myNewEdge" has already been defined as an altserver.

To force a command to be routed to the Commit Server

Use an action=redirect rule with a destination target statement:

command: regex pattern
{
    action=redirect;
    destination target;
}

where target is the Commit Server.

To reset the mapping

To reset the mapping, remove the db.routing file. For example, when you move clients to a different workspace or Edge Server, you need to remove the db.routing file from the home directory of the broker (see the directory setting of the broker config file).

To remove the file, you might first need to shut down the p4broker process.