luke
lukeβ€’17mo ago

How to optimize database bandwidth?

Hey everyone! I'm working on a multiplayer emoji matching game, and while I've been having lots of friends help me test everything, I was surprised to see that I'm already very close to hitting the database bandwidth limit πŸ˜… The project is fully open sourced, and you can check my Convex-generated schema right now here: https://github.com/lucasheriques/emojinx/blob/main/convex/schema.ts. You can also play the game here: http://emojinx.lucasfaria.dev/ I've started as naively as possible and just storing it in the best way to make it work and worry about performance later, but given that I'm already hitting some limits on Starter plan I'm wondering there's a couple of ways to do it better. From what I researched in previous discussions here, database bandwidth is roughly measured by how many db.calls I'm making, which is a lot for a single multiplayer session. Here are the things I have to track multiple times during a game , and the related field on the schema: - The status of each emoji (emojiList) - The players' score (players) - The current player turn (currentPlayerIndex) - currentMultiplayerTimer (determines how many seconds the player has to make a play) And the things I have to track only a couple of times per game: - The status of the game (status) - The winners (winnerIds) - The room name (roomName) My first thought is to make different tables for the real-time-important stuff, and another one for these, but I would love to hear some of your thoughts as well. Also, on a side note, I absolutely loved using Convex, and together with the hackathon from WebDevCody it single-handedly brought back my joy to side projects again. I already have my next idea too. My motivation is to build fun and interactive games to play together with my friends or coworkers remotely πŸ˜‚ I always wanted to learn animations, but I was tired of just doing courses after courses, and this hackathon gave me the best opportunity to learn in practice
emojinx
A fun and interactive emoji matching game
6 Replies
lee
leeβ€’17mo ago
The github repo link returns a 404 for me. Is the repo private?
luke
lukeOPβ€’17mo ago
Just made it public sorry
jamwt
jamwtβ€’17mo ago
glad to hear you're enjoying convex. while we'll dig into this to figure out why db bandwidth has become a problem, I'm also gonna DM you in the mean time so you can get access to a pro account so this doesn't affect you during hackathon, @luke !
luke
lukeOPβ€’17mo ago
I may have found the culprit inside an useEffect hook. https://github.com/lucasheriques/emojinx/blob/main/components/game/hooks/use-countdown-effect.ts#L38 I forgot to add another check here to only run the force next turn if the game is in progress, so this was being run many times if anyone had a game room opened, even if they were not in the game i checked the Convex logs and saw that I was calling the forceNextTurn() function too many times
lee
leeβ€’17mo ago
Nice sleuthing! With the goal of improving debuggability, do you have any suggestions for how Convex could have helped you find this issue?
luke
lukeOPβ€’16mo ago
Im not sure on how possible is that, but I think if it’s possible to track which function was being responsible to refetch a query would be very helpful Like, in this case, the query that was being refetched was useGameQuery. I have many functions this might require a refetch, but for this case, one specific function would be the culprit, given that it was being ran many times more than needed So if Convex were able to give me this information, it would be a lot easier to track it into my code and see what was causing the mutation to trigger, since I would probably pinpoint the issue to specific parts of the code Hope that makes sense! Sorry formatting is not great, typing from my phone, but let me know if it’s not clear and I can probably link some code examples

Did you find this page helpful?