You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 4, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 4, 2024. It is now read-only.
Hi, could you please explain how OT works within Firepad?
I'm running the user list demo locally. I've noticed the code has an OT implementation. But the code only talks to the Firebase server, which confuses me as i thought OT required a server component?
Good question. I've been meaning to write up a doc on this at some point, but haven't gotten around to it. I'm not going to go into too much detail unless you have specific questions, but the basics are:
Firepad uses OT, but it's implemented completely client-side. Firebase doesn't need to be OT-aware.
When you make an edit, the client turns that into an OT operation and tries to append it to a log of operations stored in Firebase, using a transaction.
If there's a conflict (i.e. some other client appended something new to the log before our transaction completed), the client will use OT to transform its operation against the newly added operation, and then it will attempt again to append the (now) transformed operation to the log. This can potentially happen multiple times if there's contention on the log.
Number 3 is where firepad differs from most implementations, which do rely on the server doing the transform, as you say.
I'm going to close this, but feel free to reply if you have further questions.
Great explanation thanks. Quite a clever design actually. I found it quite difficult to make sense of the code given the size of the code base. I'll have a go at reverse engineering your work so that i can better understand it.
Glad it was helpful. Yeah, sorry the code isn't more readable. It could use some cleanup and better documentation for sure.
If it's helpful, the operations and their transforms are defined in text-operation.js (and text-op.js). The higher-level OT mechanism (deciding when/how operations are transformed against each other and resent) lives in editor-client.js and especially its base class client.js. And the interaction with firebase (e.g. using transactions to append to the revision history log) lives in firebase-adapter.js.
If you have more specific questions, feel free to ping me (michael at firebase.com). Good luck.
@mikelehen as an aside, I'd really love the aforementioned doc. I've had to pass around a ham-handed description of the Firepad OT format to certain users who are interested in their per-edit data and having a resource to point them at would be pretty useful.
... This can potentially happen multiple times if there's contention on the log.
What happens if there is very high contention (many edits per round-trip time)?
At least one client always succeeds, so progress is being made, right?
I suppose users will simply see rarer bigger incoming changes.
But if one client has much higher latency (California vs satellite over Australia...), can it get consistently starved?
And would server-side OT avoid that?
(I don't expect such high usage, just curious to understand the tradeoffs of client-side OT...)
Progress will always be made (/somebody/ is able to append to the log), but there is the potential for starvation if somebody has very high latency. In practice, I've never heard of this actually happening though. It's rare to have more than a few collaborators at a time, and even if you do, people's typing tends to be very "bursty" (with long pauses of multiple seconds while they think about what to type next), and this gives "starved" clients a chance to catch up.
It's worth noting that a client will automatically merge all of its outstanding changes together each time it tries to append to the log, so even if a client gets starved for a while, it only needs to successfully write to the log once to catch up completely.
Activity
mikelehen commentedon Mar 6, 2015
Good question. I've been meaning to write up a doc on this at some point, but haven't gotten around to it. I'm not going to go into too much detail unless you have specific questions, but the basics are:
Number 3 is where firepad differs from most implementations, which do rely on the server doing the transform, as you say.
I'm going to close this, but feel free to reply if you have further questions.
dcworldwide commentedon Mar 10, 2015
Great explanation thanks. Quite a clever design actually. I found it quite difficult to make sense of the code given the size of the code base. I'll have a go at reverse engineering your work so that i can better understand it.
mikelehen commentedon Mar 10, 2015
Glad it was helpful. Yeah, sorry the code isn't more readable. It could use some cleanup and better documentation for sure.
If it's helpful, the operations and their transforms are defined in text-operation.js (and text-op.js). The higher-level OT mechanism (deciding when/how operations are transformed against each other and resent) lives in editor-client.js and especially its base class client.js. And the interaction with firebase (e.g. using transactions to append to the revision history log) lives in firebase-adapter.js.
If you have more specific questions, feel free to ping me (michael at firebase.com). Good luck.
vincentwoo commentedon Mar 10, 2015
@mikelehen as an aside, I'd really love the aforementioned doc. I've had to pass around a ham-handed description of the Firepad OT format to certain users who are interested in their per-edit data and having a resource to point them at would be pretty useful.
mikelehen commentedon Mar 11, 2015
@vincentwoo Cool, I'll keep that in mind.
cben commentedon Mar 19, 2015
What happens if there is very high contention (many edits per round-trip time)?
At least one client always succeeds, so progress is being made, right?
I suppose users will simply see rarer bigger incoming changes.
But if one client has much higher latency (California vs satellite over Australia...), can it get consistently starved?
And would server-side OT avoid that?
(I don't expect such high usage, just curious to understand the tradeoffs of client-side OT...)
mikelehen commentedon Mar 19, 2015
Yep, it's exactly as you say (nice work :-)).
Progress will always be made (/somebody/ is able to append to the log), but there is the potential for starvation if somebody has very high latency. In practice, I've never heard of this actually happening though. It's rare to have more than a few collaborators at a time, and even if you do, people's typing tends to be very "bursty" (with long pauses of multiple seconds while they think about what to type next), and this gives "starved" clients a chance to catch up.
It's worth noting that a client will automatically merge all of its outstanding changes together each time it tries to append to the log, so even if a client gets starved for a while, it only needs to successfully write to the log once to catch up completely.
mohdsanadzakirizvi commentedon Apr 25, 2018
Hey @mikelehen
I'm a student and I need to understand this for a project. I'd like to take up the challenge of documenting "how everything works?"
mikelehen commentedon Apr 25, 2018
Cool, good luck! If you have specific questions I can try to answer them. 😄