Skysoft13

Skysoft13

How is the performance of elixir in game backend project?

I have an idea for a mobile game app, I want to use elixir for backend, how is the elixir performance for game backend, any idea?

Marked As Solved

kartheek

kartheek

Game Backend Servers are different from Game Servers when it comes to gaming domain:

  • Game Backend Servers: infra services like auth, storage, economy, etc
  • Game Servers: multiplayer servers handle player presence and sync data between clients like mobile apps, web pages, etc.

Game Backend Servers you can build in Elixir/Erlang. When it comes to Game Servers the answer is a little bit complicated.

There are different genres of games like FPS, RPG, MMORPG, Casual, Turn based, etc and each one has a different latency requirement. First person shooter (FPS) games need a very low network latency (in milliseconds). Turn based games on the other hand can have higher network latency like a second or two.

Most of the game engines like Unity have multiplayer frameworks like Mirror, DarkRift, Unet, etc. There are different client server architectures in game networking like authoritative, relay, etc.

Process of building a multiplayer game server using networking libraries like mirror on Unity, etc is completely different from regular servers. Take an example of building an authoritative multiplayer game in Unity using Mirror:

  • Few Mirror framework callbacks relating to game functionality need to be implemented for Server and Client in C# classes. Callbacks for client and server are colocated in C# classes - like client code and server code are in same file but with annotations that it is server code and this is client code.
  • Select a transport which is most suitable for the game - tcp or udp based.
  • Two builds can be generated from Unity Editor a game client build (which can be android app or iOS app) and a headless server build.
  • A headless server build is generated using Unity Editor. This headless server build contains everything except graphics. This is no different from a unity game client (iOS/Android) - Unity runtime manages everything.
  • For every game session, a new instance of headless game server is spawned. This instance is killed when the game is over.

For games with low latency requirements like FPS, MMORPG - Elixir/Erlang runtime is more suitable to build relay servers(not authoritative servers) which fan out the incoming messages. One of the client acts as Server and it will makes all decisions relating to the game. Other clients contain approximations relating to game data until state is synced by Client Server(client which is acting as server). Relay is used as medium to sync data between Client Server and clients. Physics simulations, transforms, lag compensations are very difficult to implement in Elixir/Erlang for lack of libraries and a way to import game environment( OBJ files like models, meshes, etc) into the Elixir/Erlang world. There is no point in reinventing the wheel - there are many mature networking libraries which handle these scenarios. Even if some one wants to use Elixir/Erlang for relay servers - they have to implement a custom relay transport in the networking libraries like Mirror.

In case of turn based casual games like card games, board games, bingo, battleship, chess, etc - Elixir/Erlang runtimes can be used to build Game Servers. Phoenix Channels + GenServer + Postgres using Ecto will be enough to implement a turn based game server.

What are you looking to build Game Server or Game Backend Server? What genre is your game? What are the latency requirements ?

23
Post #4

Also Liked

greven

greven

Elixir is a great fit for a game server, if you did come to find some bottlenecks there is always space to optimize performance by using a NIF (Rust with Rustler, etc), but that would only be the case if CPU bound tasks would come into play.

But to answer correctly it really depends on what you are doing on that game server, If it would be taxing on the CPU maybe a better solution could be found on a lower level language.

You can find a good discussion about the same topic here: Is Elixir suited for a performance game server?

kartheek

kartheek

If I were to build a soccer game - which involves syncing the positions of the ball and players - i would do with either

  • Unity with Mirror or Photon
  • Unreal

https://www.udemy.com/course/unity-multiplayer/ is a good course to start out.

For any assets, i would buy from Unity asset store or use a primitive objects like sphere, cylinder, etc and complete game play first.

I would not touch any asset tools before completing game play unless I have a team which creates assets.

Rustixir

Rustixir

Elixir is great for backend of games
When that game is multiplayer .
Or need Process players data and communicate between them .

Like Chess,

But you enjoy from Elixir performance when you write a game like GTA Online.

My mean is you have 1K / 100K / 1M players
they can be play over your servers and very simple share information without think about which player exist on which server .

If you need write many rule based logic or handling level of each player or some low cost processing Just use Elixir and forget NIF ( using aother language with Elixir )

If you need some heavy algorithm processed inside your server instead of mobile/Xbox/Ps4
then your work is harder.

I wrote a Rule based game engine that need to much share info between players. In Erlang ( that is brother of Elixir :grin: ) works great.

My suggest :

  1. Use ETS to much ( storage in-memory )

  2. Use Mnesia to much ( storage in-memory + persistent + Distributed )

  3. For implementing Room/Channel if you
    need, use pg module or phoenix pubsub

Good luck my friend

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement