At Gcore, we have 140 points of presence (PoPs) around the world, and we needed to find a solution to transfer the configurations of a CDN edge server to all PoPs. As we need to upload and update a lot of files, some over 100 MB in size, we were looking for a tool that offers partial synchronization. So we did not have to update whole files each time we make a change. Our two options were the torrent protocol Resilio and the file sync tool rsync, and we ended up choosing Resilio.
In this article, we will compare the capabilities and configuration complexities of Resilio and rsync. Weâll explain why we chose Resilio to speed up our configuration management process and highlight its advantages over traditional syncing tools like rsync. Weâll also touch on the drawbacks of the torrent protocol and how we counterbalanced them.
Comparing features of rsync and Resilio
Resilio and rsync both offer syncing capabilities for config files. However, their handling of file transfers is very different. The following sections compare some of the features of these two tools to help you understand what benefits one provides over the other.
Resilio
Resilio is a P2P file synchronization tool that uses the BitTorrent protocol for handling distributed file transfers. It offers many useful features, such as partial updating of files, limiting bandwidth usage, selective syncing, and secure file sharing.
On-demand access to files
Resilio provides on-demand access to files through its Selective Sync feature. You can use it to create placeholder files that can be accessed locally but will download only when you need them. This feature not only gives on-demand access to files but also eliminates unnecessary replication.
Secure links for sharing
Resilioâs secure link sharing method allows users to set an expiration when sharing file links with peers. This ensures nobody can access the files once the link expires. You can also set up notification alerts so that youâll get an approval request when someone tries to access the files.
Folder-level access controls
Resilio allows you to change folder-wise access levels for your peers via the Advanced Folders feature. You can change permissions on the go, revoke access, or set ownership of an advanced folder to another user so they can manage it themselves.
Advanced folders also use public key infrastructure (PKI) instead of the randomly generated keys used by standard folders. PKI allows you to verify the identities of different users and introduce additional security measures.
Intelligent sync
Intelligent syncing allows Resilio to update only the changed parts of a file. So, if you change one of your configuration parameters, peers wonât have to download the entire config file. It increases performance by minimizing storage overhead and latency.
Plus, the P2P nature of Resilio speeds up the transfer rate as you add additional peers. You can also pause syncing for a specific directory or everything at once if the network connection is unstable.
Cross-platform
Resilio is cross-platform, so itâs suitable for enterprise-level file transfers. It provides readily available binaries for Windows, macOS, and Linux, as well as for Android and iOS devices. You can also use Resilio for syncing files with a NAS as it supports all major NAS vendors.
No failed transfers
Resilioâs BitTorrent technology safeguards against failed transfer operations when synchronizing data. Its P2P architecture ensures that active peers will take over and complete the task when other peers are offline or canât transfer data.
Rsync
Rsync is a popular tool for transferring and synchronizing files. It offers a readily available command line interface (CLI) that can be used for backing up data or syncing files between devices.
No special privileges required
You donât need special privileges to install rsync, and you donât need admin permissions on the systems where you use it. You only need read access to the source and write access to the target systems. Rsync can also preserve file ownership and attributes without superuser access at the destination.
Internal pipelining reduces latency for multiple files
Rsyncâs architecture is heavily pipelined and consists of processes that communicate unidirectionally. Once initiated, a sender process will create the file list and relay it to a receiver. After this step, the receiver process becomes the generator, and a pipeline is established as follows:
generator -> sender -> receiver
The processes run independently, and the pipeline is only delayed when one process is waiting for I/O or CPU resources. This pipeline-based approach reduces latency when transferring a large set of files.
Anonymous rsync
Rsync can be a valuable tool for mirroring as anyone with access to an rsync server can pull contents anonymously. This feature makes rsync a suitable choice for mirroring public-facing data.
Works out of the box
Rsync comes preinstalled on most Linux, BSD, and macOS systems. Plus, all of its features are readily available on the command line. Thereâs no need to tweak any configuration parameters for normal file transfers. You can simply fire up a terminal and use the ârsyncâ command to transfer data.
Feature comparison brief summary
A torrent tracker is the best option for distributing configs worldwide as it provides real-time synchronization, multi-way file transfers, and much faster transfer speeds. A peer-to-peer (P2P) system like Resilio distributes the work across all PoPs. It can sync files in real time and offers multidirectional sync, centralized management, and automation abilities.
Conversely, rsync is a remote file transfer tool that uses the client-server model for synchronization. Remote and local file sync tools such as rsync may be helpful in some cases, but they are not viable for syncing real-time config changes on a large scale.
Comparing configuration complexity for Resilio and rsync
In addition to capabilities, the effort needed to configure an application is crucial when selecting a synchronization solution. The following sections illustrate how to use Resilio and rsync to sync a simple config file.
How to configure Resilio to synchronize a config file
Syncing a config file for your daily builds between several systems is very straightforward with Resilio.
There are several ways to configure Resilio depending on your operating system, but the configuration file is the most consistent method and also offers the most advanced configurations.
Your first step would be downloading a sample configuration file from Resilio. You can then open the file in any text editor and make the desired modifications. The important sections that you would need to change are:
{ "device_name": "My Sync Device", // "listening_port" : 0, // 0 - randomize port /* storage_path dir contains auxiliary app files if no storage_path field: .sync dir created in current working directory */ // "storage_path" : "/home/user/.sync",
âdevice_nameâ is how your device is identified and âstorage_pathâ is where you would like your configuration files to be stored.
/* !!! if you set shared folders in config file WebUI will be DISABLED !!! shared directories specified in config file override the folders previously added from WebUI. */ /*, "shared_folders" : [ { "secret" : "MY_SECRET_1", // required field - use --generate-secret in command line to create new secret "dir" : "/home/user/resilio/sync_test", // * required field "use_relay_server" : true, // use relay server when direct connection fails "use_tracker" : true, "search_lan" : true, "use_sync_trash" : true, // enable SyncArchive to store files deleted on remote devices "overwrite_changes" : false, // restore modified files to original version, ONLY for Read-Only folders "selective_sync" : false, // add folder in selective sync mode "known_hosts" : // specify hosts to attempt connection without additional search [ "192.168.1.2:44444" ] } ] */
Youâll need to uncomment the section around âshared_foldersâ and make sure to update the values as it best fits your environment. You can share the code âsecretâ with others to allow them to download the files that you share, and âdirâ is the folder that you are sharing.
You can learn more about the different values in the configuration file on the Resilio website.
After youâre done with the configuration file, you need to just run sync with the âconfig sync.confâ parameter to load your configuration file, for example:
./rslsync âconfig /confpath/sync.conf
Resilio has three sync modes: Disconnected, Selective Sync, and Synced. Youâll need to turn on the Synced mode to enable real-time updates to your config file.
How to configure rsync to synchronize a config file
To configure rsync for syncing a config file, first set up the â/etc/hostsâ file of your primary server to contain all of the agent serverâs hostnames and IP addresses. This step will make server administration easier in the future.
Next, create SSH key pairs for your primary server using âssh-keygenâ and copy the generated public key to each of your agent servers using âssh-copy-idâ. You should now be able to SSH into the agent servers from the primary server. Test and check if it works.
Now, youâll create the rsync script that syncs your config file. The rsync script will push changes from the primary server to each agent server, one at a time. Create a file named ârsync-push.shâ and populate it with the following code:
#!/bin/bash # list of agent servers servers=(server01 server02 server03) # sample config file status="/var/www/html/config.status" # if lock exists then exit if [ -d /tmp/.rsync.lock ]; then echo "FAILURE : lock exists" > $status exit 1 fi # creates a new lock /bin/mkdir /tmp/.rsync.lock if [ $? = "1" ]; then echo "FAILURE : can not obtain lock" > $status exit 1 else echo "SUCCESS : lock created" > $status fi # iterate over the agent servers and transfer files for i in ${servers[@]}; do echo "===== Starting rsync $i =====" nice -n 20 /usr/bin/rsync -avzx --delete -e ssh /var/www/vhosts/ root@$i:/var/www/vhosts/ # prompt if unsuccessful if [ $? = "1" ]; then echo "FAILURE : rsync failed" > $status exit 1 fi echo "===== Finished rsync $i ====="; done # release rsync lock /bin/rm -rf /tmp/.rsync.lock echo "SUCCESS : script completed successfully" > $status
This script assumes that the document roots are in â/var/www/vhostsâ. Tweak it as necessary. Make ârsync-push.shâ executable using âchmodâ and add the line below to your crontab to execute it every five minutes:
*/5 * * * * /opt/scripts/rsync-push.sh
Configuration complexity summary
As you can see, using rsync for syncing config files between multiple devices requires significant user intervention. Notably, you need to create custom shell scripts to deal with the servers and transfer data to them. Moreover, youâll also need to set up custom cron jobs to automate the entire syncing process.
Resilio offers a much more seamless experience in this regard. You donât need to create custom scripts or configure any parameters to sync files. Just share the files with your peers and enable the Synced mode to sync files instantly.
Why did we choose Resilio to distribute configs?
We chose Resilio to update our config files since it offers real-time synchronization and effective multi-way transfers. The BitTorrent protocol of Resilio also ensures faster transfers because it downloads the config files from the nearest server.
Rsync needs to download the changed parts from the central server, which might be located far away from some nodes. This, coupled with rsyncâs client-server architecture and the lack of N-way transfers, introduces latency. Plus, rsync also lacks the real-time syncing capability of Resilio.
In addition, Resilio is much easier to configure and offers valuable features that rsync lacks. Rsync also requires manual configuration that can quickly become inconvenient for large-scale applications.
How did we handle blocked countries?
One major drawback of the torrent protocol we had to overcome is that not all countries allow it. Some countries block it to crack down on piracy. So, nodes in these countries wonât benefit from Resilioâs distributed file transfers.
To counter this problem, our synchronization solution downloads the config files directly from the central server in countries where BitTorrent is blocked. It may get minor performance hits in such cases, but it typically retains an excellent transfer rate.
Conclusion
Effective syncing of config files is crucial for modern CI/CD methodologies. Real-time file synchronization tools like Resilio enable instant updates to config files across numerous points of presence, something traditional tools like rsync canât achieve.
At Gcore, Resilio lets us deliver new configuration files and update old ones almost instantly across all of our CDNâs 140 points of presence so that we can offer convenient and fast services for our customers around the globe. Itâs part of our carefully designed syncing solution that helps us minimize latency and drive data faster to the destination.
Written by Rubaiat Hossain