Repository Server Load Balancing and Synchronization with SVN
In our support work of the recent past we saw that the topic of SVN repository synchronization seems to be a current issue. Therefore we want to show you how you can implement a main/worker (formerly known as master/slave) server structure for load balancing. Worker servers are used for read operations and the main for write operations.
Fundamentals
The reason why it is necessary to divide read and write operations to different servers is the behavior of users. Normally it is more likely that users are performing read operations such as checkouts, updates, etc. than write operations such as commits or revision property changes. Therefore the server performance can be increased by dividing those two tasks onto two different kinds of servers, lets call them main and worker. Multiple worker servers are used for read operations and the main server is used for all write operations. To ensure that the users are reading the latest versions from the worker servers it is necessary to synchronize the worker servers with the main. A setup of main and worker servers could look like this:
Since version 1.5 SVN supports the feature “Write-through proxy”. It enables the setup of one main/worker server system, where the main is associated with a repository for read and write operations, and several worker servers that are handling only read operations. The worker servers are passing through (proxying) write operations to the main server. A system like this requires “Apache HTTP Server” on the main and worker servers with at least version 2.2.x and the worker servers need “mod_proxy” enabled.
Implementation
The implementation requires the modification of the httpd.conf files of the main and worker servers. You need to perform the following few steps to implement the system:
-
Configure the main server to expose the repository by adding a new block to the httpd.conf file:
<lt;Location /svn/project> DAV svn SVNPath /opt/svn/project (path to the repository on the worker server) </Location>
-
Configure the worker server by adding a new block to the httpd.conf file:
<Location /svn/project> DAV svn SVNPath /opt/svn/project (path to the repository on the worker server) SVNMainURI http://*IP-ADDR-OF-MAIN*/svn/project/ </Location>
- Configure worker server to enable svnsync by adding another block to the workers httpd.conf file:
<Location /svn/project-proxy-sync> DAV svn SVNPath /opt/svn/project (path to the repository on the worker server) Order deny,allow Deny from all Allow from *IP-ADDR-OF-MAIN* <Location /svn/project>
- Enable the constant synchronization of the worker repository by using the main repositories hook for svnsync:
-
#!/bin/sh
REVISION=${2}
# Launch (backgrounded) sync jobs for each worker server.
svnsync copy-revprops http://*IP-ADDR-OF-WORKER*/svn/project-proxy-sync ${REVISION} &
-
#!/bin/sh
# Launch (backgrounded) sync jobs for each worker server
svnsync sync http://*IP-ADDR-OF-WORKER1*/svn/project-proxy-sync &
-
Now the basic configuration is finished. Depending on your needs and system you can extend the configuration with authentication and authorization, handling of lock/unlock requests and the handling of connection problems during the synchronization or a write operation. In any case it is necessary to realize at least read access at the worker servers and read/write access at the main server for all users. The authentication needs to match across all servers and also needs to be synced. The implementation of the authentication and authorization needs to be performed corresponding to your authentication system.