Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add high accuracy sync ? #18

Open
darkterra opened this issue Dec 3, 2017 · 13 comments
Open

Add high accuracy sync ? #18

darkterra opened this issue Dec 3, 2017 · 13 comments

Comments

@darkterra
Copy link

Hi,
is it possible to add an option to have a synchronization with a high precision, kind real time ?

Somme time I have less than 100ms between my differents clients, and on the next sync I have more than 600ms.

I need to play different part of video on different glued screen. Same thing when I need to play a set of images

Thank in advance

@josdejong
Copy link
Contributor

The current implemented syncing algorithm is described here: https://github.com/enmasseio/timesync#algorithm

Do you know of a better algorithm? That would be interesting.

@darkterra
Copy link
Author

darkterra commented Dec 6, 2017

Maybe the PTP protocol ?
https://en.wikipedia.org/wiki/Precision_Time_Protocol

I think the main difficulty is "The accuracy of the two-way method depends on the validity of the assumption that the path delay is symmetric", see :
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4821719/

@josdejong
Copy link
Contributor

The PTP protocol looks the same as the protocol currently implemented (which is described here: http://www.mine-control.com/zack/timesync/timesync.html), but please correct me if I'm wrong. On top of that, that the current algorithm repeats calculating the offset and takes the median of it which should give more stable results. Could also be that I haven't implemented it correctly of course, please let me know if you see issues in the current implementation.

There is indeed an issue when the internet speed is not symmetric.

@darkterra
Copy link
Author

darkterra commented Dec 8, 2017

Indeed, it seemed to me that there was a strong similarity, however, I admit that the third point on the explanation of the algorithm (https://github.com/enmasseio/timesync#algorithm) lacked clarity ( certainly due to my lack of English).
That said, I wonder if there would be a gain of precision if we go through websocket (https://stackoverflow.com/questions/14703627/websockets-protocol-vs-http) and it is the server that initiates the synchronization phase.

About the algorithm used here, I think that we must find a more stable / precise way in terms of the asymmetric delay of a request, unfortunately I have no solution ready, but perhaps to be based on the operation described here: https://www.perle.com/supportfiles/precision-time-protocol.shtml

From what I understood, the idea is to refine the shift thanks to follow up and a repetition of queries to reduce the delay between the clocks.

Do you think that if we combine the use of WebSocket plus the use of FollowUp and a set of queries allowing a refinement of delay would be a good idea?

I would also add that for my need, it is not a problem if I have to wait x minutes (the first time) to have a sync within 100ms

Finally, at most the presision of the timestamp is fine at best it is.
In the case of Node.JS it is possible to use "process.hrtime" to have a precision at the nano second. From what I saw, in PHP too. So I guess it's feasible on most BackEnd languages.

By cons I have not yet found equivalent side FrontEnd. To see if there is no asctuce.
Maybe with the WebWorker?
Maybe by installing Node.JS client side?

For my need, it's not a problem to install a Node.JS instance to get precision down to nano

@josdejong
Copy link
Contributor

I don't know whether using websockets would improve the performance, but that could definitely help. Would be interesting to do some experimenting with it of course! Would you be able to give syncing time via websockets a try?

@canda
Copy link

canda commented Jan 25, 2018

I can give it a try if I find some spare time. I want to sync music with it. How do you recommend to verify accuracy? I mean, how can you check if it is really better and how much precision you really have?

@josdejong
Copy link
Contributor

I can give it a try if I find some spare time

that would be great

How do you recommend to verify accuracy? I mean, how can you check if it is really better and how much precision you really have?

That's an interesting question. You can't really check that by connecting two devices via internet, because the variable latencies would introduce measurement errors. If you're doing something with sound, maybe you can have two devices alternately make a ticking noise once per two seconds, and have a third device listen and compare the delay between the ticks from the different sources :D

@darkterra
Copy link
Author

Hello,
Having had very little time for me at the beginning of the year, I have not yet had the opportunity to propose a POC with WebSocket, but I think I can start in a few weeks :)

In the meantime here is an article which explains why I think to gain a better precision with the WebSocket (of course, I know that the nature of the Internet network makes that one will not be able to have a stable precision).

Watch the part: Why Websocket and Not HTTP?
and the part: How WebSockets Work
http://resources.infosecinstitute.com/websocket-security-issues/#gref

@josdejong
Copy link
Contributor

Thanks for sharing @darkterra

@darkterra
Copy link
Author

Hi !
One more very interesting article on WebSocket :)

https://blog.sessionstack.com/how-javascript-works-deep-dive-into-websockets-and-http-2-with-sse-how-to-pick-the-right-path-584e6b8e3bf7

I should be able to start working again on the project which asks me to have a great precision, so I would try to give a try with WebSocket and timesync :)

@josdejong
Copy link
Contributor

cool, I'm curious to hear the results!

@canda
Copy link

canda commented Jan 22, 2019

What I ended up doing to measure the sync precision is to display a clock on a browser in 2 different devices, film both screens, and compare frame by frame the difference between both clocks.

@josdejong
Copy link
Contributor

That makes sense @canda, thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants