i've 2 servers.

  1. Server A : contains
    • mysql
    • apache
    • nginx
  2. Server B : contains
    • apache
    • memcached
    • rsync cron ( each 3 mins ) that pulls the /var/www/ content and update its own

I'm using:

  • nginx of Server A to load balance the http requests. (And it work just fine).
  • memcached from server B to maintain php sessions

Nginx currently load balances asking Server B to handle 75% of the requests.

In order to sync the application code ( which is written in php ) i use rsync ( as explained above ).

The problem of rsync is that I can't handle 2 way sync so I was starting looking at Unison.

At this point I've 2 questions:

  1. Would it be a good idea to ask nginx to route all the "send file" requests to Server A so that Server B only needs to pull?
  2. Should I use Unison or some other software for this kind of sync? Can I get a realtime sync?
  3. Should I use some network file system that shares the content of /var/www/ from Server A to Server B? If yes. What do you suggest?
  • Can you explain why you need a 2-way sync of anything? Do you really mean application code, or do you mean user uploaded data? – carpii Sep 5 '12 at 23:27

You can use tools rsync or unison, but you will not get a realtime sync. There should be some delay until new/updated files get synced even if you run such a tool every minute. You can implement it if you think it is acceptable to have a small delay.

If you want to get changes synced in realtime, you need to use a tool like NFS/glusterfs, or DRBD. The main drawback of such tools is the increased I/O overhead as a result of network delay. This becomes clearer when the shared folder becomes huge and network delay becomes larger.

  • Arent such tools ( nfs, drdb... ) caching the content? – Andrea Baccega Sep 5 '12 at 11:29
  • There IS caching, but you can not cache everything and frequent changes (if any) make things more complicated. – Khaled Sep 5 '12 at 11:32

This asymmetric architectures doubles your chance of the service failing - and it's not very good for performance.

i use rsync ( as explained above ).

I didn't see an explanation of how you use rsync.

In order to sync the application code

Deployment of application code should be a managed process. How you manage replication of content uploaded via the webserver / generated by the webserver is a very different story. If you need to do bi-directional replication of application code then you are doing it wrong.

Your issue centres around deployment. If the nodes were functionally symmetrical with replication occurring for memcache and mysql, then it's a no-brainer to take one node offline (even if that just means swapping in an nginx config to proxy/redirect all requests to the other node) for deployment. As a result, you have zero downtime for code deployments, zero downtime for database backups, zero downtime for database maintenance, zero downtime for schema changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.