Is Julia worth it for this project?

Hi,

I am in the process of building a browser game that essentially mimics the Football Manager game from Sports Interactive. The simulation in the original Football Manager game involves managing a football team by making tactical decisions, and playing matches, with the outcomes determined by a mix of player stats, team strategies, and in-game dynamics.

I will use Spring and React as well as Postgres. I stumbled on Julia recently and did some forecasting and other shorter programs, so I´m essentially new to it. I did not a have a specific use or project in mind with it until this one.

For the the simulation of each game played, the players(gamer) only have control of the tactics. This means the computation will roughly be: players decisions = players stats + team and individual tactical instructions + other players previous decisions.
My question if Julia would be a good language for that task, given that i want a players “decision” to be made every 0.25 seconds (a pace that was mentioned on the forums). Julia’s role would then be focused on the backend calculations and game logic, with the results being passed to the frontend for visualization (2D).

I see two core strenghts in Julia for this case (feel free to add other aspects):

  • parallelism and concurrency because of many players decisions
  • handles complex mathematical operations well

uncertainty:

  • scalability, I am a bit clueless here, also because there isn´t any simulation running yet. Less important for now.

  • does julia perform well with postgres databases in a context of high-demand environment?

  • julia and its features are meant to be a language for scientific computing, not my case

I read another post which made a bit sceptic if julia would be the right choice:

So my decision upon using Julia is also based on the question: Is my game Hard Real-Time Computing or Soft Real-Time Computing?

I personally think that a slight delay in a decision won’t alter the outcome of future players decisions in an unintended way. But this thought is only based on sentiment and the 250ms estimate, so I would be really happy to hear some of your thoughts.

My alternatives would be C++, Python with Numpy, but these are my issues:

C++: never used it and harder to learn (I admit that maybe this would be the occasion to finally begin using it)

Python: I do program in python, but i´m afraid pythons Global Interpreter Lock could be a bottleneck for CPU-bound concurrent processing.

I read a few posts here and understand that my first julia code will not be as quick as it could be, but I am ok with working on this project a little longer and investing time in optimization, as it isn´t work related.

I hope this isn´t too much gibberish and you could tell me if Julia is worth it for this project or less so.

Thank you,

Mathis

2 Likes

Is this an error? 0.25 seconds is 250, rather than 25 ms.

In this context, hard real-time is stuff like controlling hardware with a microcontroller, where an unexpected delay may cause hardware to break or some other catastrophic error, while in your case I guess you could design the simulation so it would be robust against unexpected GC pauses. So I’d say that you have a soft real-time problem, and Julia could be a good choice.

You’d have to take care about when GC happens and when run time dispatch happens in your simulation while designing and coding it.

BTW, not related to your problem, but it might be interesting to note that @Sukera actually managed to run Julia code (without the Julia runtime) on an AVR microcontroller: YT, HN, Web log. So technically, Julia is usable for hard real time, although the limitations of using Julia in such a way are surely severe.

4 Likes

Sounds soft so far, but it’s worth confirming for yourself whether missing a deadline results in a disaster after which you may hopefully restart (think a structural defect in 3D printing or a rocket going off-course), or if missing a deadline contributes to program lag that you try to optimize toward a lower frequency (typical for games). Hard realtime is a lot harder to pull off, it’s not just on the software level.

8 Likes

sorry there is a 0 missing, i meant 250ms

Ok, I´m going to look deeper in GC Managment then.

Do you have any tips minimizing GC-related pauses that are more typical in julia? There is just general good practices that that come to my mind (Preallocated Buffers, Avoid Unnecessary Temporary Objects etc. …)

I think I am going to try this out in Julia, lets see how it goes.

Thank you for your answer.

2 Likes

I don´t think missing a deadline would be a make/or break like your rocket comparison, but it could be an annoyance. I think i would be benficial for me to just start and experiment.

Thank you for your answer

  • See the performance tips, in case you didn’t already: https://docs.julialang.org/en/v1/manual/performance-tips/

  • Use JET to check for run time dispatch. In general you don’t want run time dispatch in a hot loop, in your case I think you should strive to not have any run time dispatch after the simulation starts, except possibly at the beginning or during initialization.

  • Use the profilers, especially the allocation profiler (available in the VS code REPL as @profview_allocs) to check for excessive or unexpected allocation. I usually use the “flamegraph” display, however some prefer the PProf display.

1 Like

Julia is very scalable. Being one of only a handful of languages able to scale out to supercomputer levels and join the petaflop club. Lots of features for parallelism at different levels etc.
I doubt you would need all that much at all unless you have truly incredible numbers of players.

  • does julia perform well with postgres databases in a context of high-demand environment?

Yes. LibPQ.jl is one of the most featureful and optimized LibPQ implementation. It was largely developed at my old employer because postgres queries were the bottleneck. It’s pretty solid now.

  • julia and its features are meant to be a language for scientific computing, not my case

This is fine. Somethings won’t be useful due you.

Is my game Hard Real-Time Computing or Soft Real-Time Computing?

I wouldn’t really say you game has serious real time components of any sort.
If I am understanding rightly,
Basically you would have an game “tick” that happens no more frequently than every 0.25 seconds. And if load gets really high might start to slow down. Which is common in a lot of games.

Sounds to me like you have normal computational performance concerns. (Plus a extra thing to insert sleeps if computation runs too fast)
Not the special concerns real-time introduces.

11 Likes

The new AllocCheck project is also relevant.

1 Like

ok, thank you for your advice!