AE Admin
AE Admin3y ago

Latency!

Hi everybody! How big is the synchronization delay? When I do some changes in one client app how much time it takes to deliver them to another client app? I wonder whether I can build my multiplayer game on top of Convex or not.
14 Replies
ballingt
ballingt3y ago
Hi @AE Admin, welcome! When I tested this last most of the latency was network.
ballingt
ballingt3y ago
Here's an unfinished game I made that doesn't have any "optimistic updates," so you can feel the latency when you click https://ball-shoot.vercel.app/
It's like ManyGolf
Multiplayer side-view golf game
ballingt
ballingt3y ago
(on mobile some if the latency is waiting for a touch to be classified as a click, so test on desktop) We have some metrics on this but I'm away from the computer
ian
ian3y ago
Also here's a little demo with some client-side throttling but otherwise round-tripping presence data between multiple users. https://spectacular-beijinho-ccf8ab.netlify.app/
Presence with Convex
Live presence feedback
nipunn
nipunn3y ago
Definitely check out our optimistic updates. They're really helpful for this sort of use case. https://docs.convex.dev/using/optimistic-updates Even if it takes some tens of milliseconds (even on say fiber internet) to make it to the other computer, on you can make your local browser state update immediately, without much of the difficulty of managing that temporary state until the data is saved for real.
Optimistic Updates | Convex Developer Hub
Even though Convex queries are completely reactive, sometimes you'll want to
sujayakar
sujayakar3y ago
for some concrete numbers, I ran a multiplayer cursors demo from our office in SF a few months ago, and I measured 117ms propagation time (from client update -> us-east server -> update received on client) at p50 and 133ms at p99. I can rerun the numbers if you like (we only currently have automated performance testing for within the datacenter), but that should be the rough order of magnitude. does that meet your requirements @AE Admin?
casado
casado3y ago
@AE Admin I built a hobby multiplayer game for fun in Convex (dungeon explorer) using Javascript and pixi.js, and for up to 8 players with roughly a dozen NPCs on screen with shared state, it worked just fine. I suspect it would have scaled even further, but I never tested that.
lee
lee3y ago
It's going to depend on where the clients are located in the world, for round trip time. And it may depend on what the queries and mutations are doing. From our load tests that are running simple queries and mutations close to the servers, the time to run a mutation and observe it from a query comes out to p99 of 25ms.
AE Admin
AE AdminOP3y ago
Perfect! Thank you for the answers.
Matt Luo
Matt Luo11mo ago
@ian - can you further explain how this demo works? I opened the URL in multiple tabs, and I also tried with multiple browsers, but I am not seeing any shared cursors in the sense of multiple cursors or cursor control
ian
ian11mo ago
Thanks for catching that - I hadn't re-deployed after making some changes last year. Just redeployed it. You can run it locally too: https://github.com/get-convex/convex-presence If you're interested in presence / cursors, we did a more optimized cursor pass (where it sends a buffer instead of just latest location) based on how we send player location data in AI Town. We didn't do anything with it, but I could share it with you if you want to check it out. We decided not to push the cursors story, since it's a lot of reads/writes of ephemeral data and we didn't want to eat up free tier bandwidth unnecessarily
GitHub
GitHub - get-convex/convex-presence: Implementing a presence hook i...
Implementing a presence hook in Convex. Contribute to get-convex/convex-presence development by creating an account on GitHub.
Matt Luo
Matt Luo11mo ago
Thanks @ian , the Presence demo with shared cursors looks great. I didn't realize that shared cursors would consume a lot of bandwidth. Which monthly resource do shared cursors use? Is it "Database bandwidth"? I think in general, more Convex billing examples of various customer archetypes would help
ian
ian11mo ago
The usage might not be too bad, but I’d expect reading & writing many cursors to use database bandwidth, maybe function calls. Likely still be cheaper than using another service, haven’t done the math I would also like at some point to make a more efficient implementation that doesn't do heartbeats (or does them much less frequently), and leverages sendBeacon & http to detect online status. https://discord.com/channels/1019350475847499849/1151212440789459045 But if we keep going on this, let's move this convo into a more discoverable thread on presence in support, so others can find it in the future
ampp
ampp7mo ago
I'm curious if there has been updates, i'm mixing a bit of this together, im building toward wide presence, then add specific rooms on to of that (like typing) so im modifying the implementations from convex-presence. a sendBeacon example would be helpful. :convex:

Did you find this page helpful?