Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time syncing vs high latency

I'm doing an auction script and time syncing between visitors and the server is necessary (when will the auction end). Every time a user bids, auction end time is extended for a few seconds. My problem is that several users are complaining about their timers skipping (some seconds) and figured out that it is because of a high latency connection.

My current algorithm has a javascript function that runs every second, getting time left for the auction through ajax requests. Is there a better way to approach this, especially for high latency users, to prevent the timer skipping problem?

like image 801
yowmamasita Avatar asked Oct 09 '12 18:10

yowmamasita


People also ask

What is time syncing?

Time synchronization refers to the distribution of time across clocks in a network. Time synchronization is one way of achieving phase synchronization.

What is more accurate than NTP?

GPS is more accurate than NTP and has less latency compared to NTP. clear sky, and after satellites are locked, the GPS master clock will send a signal every second to the slave clocks.

What is difference between NTP and PTP?

The older and more well-known protocol is the Network Time Protocol (NTP). In its fourth version, NTP is defined by IETF in RFC 5905. The newer protocol is the Precision Time Protocol (PTP), which is defined in the IEEE 1588-2008 standard. The reference implementation of NTP is provided in the ntp package.

Why time synchronization is important in a network?

In modern computer networks, time synchronization is critical because every aspect of managing, securing, planning, and debugging a network involves determining when events happen. Time also provides the only frame of reference between all devices on the network.


2 Answers

Adaptive intervals

First of all, I would suggest that you decrease the amount of polling. I don't know about your server implementation, but the current setup will create a lot of requests once you have a couple of users.

I would suggest that you adjust the polling interval depending on how much time is left. If there are two hours left until the end of an auction, we might not really care if the additional seconds are only fetched from the server every minute, right? You could do it like this

pollingInterval = secondsLeft / 100

The interval is shorter and the result is more accurate towards the end of the auction.

Server Sent Events

For the last minute or so, when you want a high accuracy, regular polling at short intervals is not the best solution, as discussed in the comments. Long polling is an option, but you should also look into HTML5 Server Sent Events, which is like a native browser implementation of long polling. There's a good introduction and comparison to Websockets. Browser support is already pretty good, there's a polyfill for unsupported browsers which falls back to...polling.

like image 81
pixelistik Avatar answered Oct 01 '22 15:10

pixelistik


Have you looked into long polling? Use you could use a jquery/javascript countdown clock and then just change the countdown time whenever a new bid is placed. Should cut your ajax calls drastically.

like image 20
Pitchinnate Avatar answered Oct 01 '22 15:10

Pitchinnate