Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BogdanVasc · Aug 20, 2017 at 02:43 PM · multiplayernetworkserverdatabaseturn-based

Best practice for a turn-based game

This is mostly a non-Unity question, but I have been thinking of using Databases instead of classic server-style way of communicating with a server, and I want to know if this method is practical or not. Here's what I've come up with:

  1. In Unity, a certain player creates a room, generating a key for another player to be able to join it. Data about the room is sent to the database.

  2. Another player inserts the key somewhere, calling the server for a potential room. If a room exists, both players are connected.

  3. One new row is created in the database, containing information about each player (<1KB in total).

  4. Whenever a player ends his move or does something that should affect the other player, this row is updated.

  5. Each x seconds (with an upper limit, obviously affected by the delay) the information from this row is downloaded and managed in Unity and the game continues based on that information.

If for the sake of argument we consider the delay/limit value to be 1 second, then in a game of 5 minutes this means that there would be 300 download calls for each player, thus 600 in total, with up to 100 total upload calls regardful of the nature of the game. If 1000 players played constantly, that would create over 300.000 calls every minute. So my question is, how big are these numbers in reality? Have anyone tried this method or perhaps something similar? I hope this is not very off-topic. Thank you.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TheSOULDev · Aug 20, 2017 at 03:45 PM

How large the overhead is depends on the size of the data that is downloaded. You send and receive packets. If you send a lot, it is going to take a long time. If you send them frequently, you'll need to download a lot of data. Let's say that the information you're sending per second is something the size of 500 Bytes. Running that 300000 times in 5 minute would be 150000 kB, or 150 MB, which comes down to 0.5 MB/s, which is quite frankly not that much, even the weakest server and network can probably handle that. Because the encryption and decryption of data is done by the client and not the server (I assume you want the server to just be a pointer, rather than control packets at the moment), it doesn't take a toll on it.

Now, I'm sure someone attempted this, but think of it this way - how much data are you going to be recording? 1000 players will record 150 MBs in 5 minutes if every second you send and record 500B. You will need to make the packets orders rather than plain data, just to edit a database, so it doesn't just add something like a new member in a stack (because what you wanna do is basically having a stack-based multiplayer), but simply edits the existing data for a turn.

Overall, I don't think the bandwidth is a problem. For testing purposes any computer acting as a server will do. However, if it's a 2 player game, I suggest you consider peer-to-peer and go from that.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BogdanVasc · Aug 20, 2017 at 04:49 PM 0
Share

Thank you very much for the well described answer. One more question that perhaps is out of your knowledge: how fast can the database iterate through its rows? As with 1000 active players (1000 rows) + let's say 100 players waiting to peer (as mentioned at step 1; another 100 rows), it'll give a total of 1100 rows, separated in two different tables. Considering each room has a unique key to be identified, does iterating through 1000 rows heavily affect the speed? Also, I forgot to mention that the data download/upload is done via PHP (similar to the Unity tutorial "Server Side Highscores"), though I doubt there is any better solution for this matter.

avatar image TheSOULDev BogdanVasc · Aug 21, 2017 at 11:50 PM 0
Share

How fast it goes depends on what you do to go through (I assume you would have keys of the room acting as indexes, so have some sort of a hash table with info), and while I neither know the precise answer, there also isn't one. It depends on how fast your hardware and the managing program are. However, simply iterating through that data shouldn't be a problem. Think of it as a foreach loop with slightly more overhead.

The only question that remains is how fast do you want it to go? If you go super fast, then it will need a fast server if you have many players. $$anonymous$$y suggestion is to try and build it like HEarthstone - in Hearthstone, you can play things as fast as you can, but the speed has a limit - what the opponent sees is limited by, I guess, what the server sends. So technically, you could cap the speed if you ever saw it be a problem for the player that's waiting for their opponent's turn to end, and in that way, you're optimizing both traffic and overhead, while not making the playing player feel bad. Now, Hearthstone doesn't pause, but it sends things as fast as it can, and then if the servers are getting thrashed, it normally slows down. So it is flexible, really, but whether or not the servers are lagging is going to only be visible when the servers are really about to crash because the speed limit is high enough to mask everything else.

Overall, iterating through your "rows" would only be unbearably slow if you crunched a lot of data per tick or if you had some wild encryption checks going on. Even if those things happen, you can still optimize it by placing speed limits for the party that depends on the server to get information, essentially masking it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

127 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Hosted Database for Mobile Game 0 Answers

Server and Network no communication 1 Answer

What is the CCU of the default Unity Networking? 1 Answer

How to hide a started/full server 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges