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

dom

dom

I liked this classification:

Elixir would do fine for “1 hour” and “1 second” scenarios, even with tons of users. For the “200ms” one, it depends!

Skysoft13

Skysoft13

tnx I get it :slight_smile:

Where Next?

Popular in Questions Top

New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
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
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
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

We're in Beta

About us Mission Statement