I notice a timestamp mismatch between my webserver (Amazon EC2) & database (Amazon RDS running PostgreSQL). They are off by a few seconds.
There are some entries that are created in the database with a timestamp (using SQL current_timestamp
). The server reads these entries and compares the timestamp with its own clock (using Django timezone.now()
) to select entries newer than 'x' minutes.
This mismatch leads to inconsistenct data. What's a good approach to make my code fault tolerant to clock mismatch between different machines. Should I remove the timezone.now()
function on server side and instead read the timestamp from the database instead? This will add a slight overhead of database access, but the timestamp would be consistent across multiple web servers.
Or, is there a better way to keep the 2 machines synchronized?
Aucun commentaire:
Enregistrer un commentaire