As traffic of your project increases you need to improve your app performance to keep up with it. A solution to this is to migrate your application on multiple web servers. But it is often difficult to run such applications as WordPress, Drupal, Joomla, Liferay, Redmine and others that are similar, across multiple web servers. The main problem is that these applications by default save all uploaded files only to one server and do not synchronize these files between server nodes in the cluster. In other words, only the server which was processing the file upload request will contain newly added content. The rest of the servers will fall out-of-sync.
Therefore, here is an instruction solving the issue of keeping uploaded files in sync or, in other words, providing solution for the file synchronization problem.
|For now this is just a workaround which helps to automate content synchronization on multiple app servers. In the future, our team will integrate it into the core system.|
Lsyncd is a light-weight, live mirror solution used to synchronize app servers. Being wisely coupled with inotify, lsyncd initiates file sync only if it has detected any actual changes in the system. In such a way, the load on CPU is decreased and you do not burn up many resources on processing the synchronization.
With a help of our bookmarklet, lsyncd is automatically installed on each app server available in the environment. Before its installation, you will be asked to choose the folders you want to synchronize. As a result, when a change is made in the chosen folders on any of the app servers, those changes will be synced to each server node automatically.
So now let’s see how to turn this into reality, step-by-step.
In our example we will use the WordPress application deployed to the environment with two servers. This instruction is also fully appropriate for other PHP, Java or Ruby applications such as Drupal, Joomla, Liferay, Redmine and others.