Live data from Hacker News

Erlang and First-Person Shooters (2011) [pdf]

erlang-factory.com

31–40 of 44 posts

Re: Erlang and First-Person Shooters (2011) [pdf]

#31
post #8

I wonder if they have considered moving to elixir since some of the problems they have highlighted are resolved in elixir. That would be easier for new employees and they could still keep their Erlang code base until they make the full switch.

I'm wondering the same :)...

In 2011 Exlixir didn't exist. More than likely they've stuck to Erlang as the incremental benefit is really on the language side only. If you're only moving to Elixir because of the language sugar, the only thing you're going to gain is maintenance and updates -- with a system that probably doesn't need all that much in the way of "tinkering".

Re: Erlang and First-Person Shooters (2011) [pdf]

#32
post #25

Earlier quoted context omitted.

The Cowboy webserver is fairly easy to get started with and I really recommend checking it out, since a web server feels like a "very Erlang problem" to me. To answer your question though, I got started by playing with TCP and building a basic chat server. I spawned a new Erlang process for each user, used Erlang's internal messaging to share messages between processes, and then passed those messages along to TCP to…

And it turns out a lot of problems actually fit that if you try to think about them that way. Sometimes it's worth -trying- to change your visualization; you'll find it works out better. We had to write task scheduling software where I worked, and someone unfamiliar with Erlang said something to the effect of "Oh, that's easy, priority queue". Well, no; there are all -sorts- of sharp edges to doing that. Instead we j…

I'm just curious, what are some of the disadvantages to priority queue?

Re: Erlang and First-Person Shooters (2011) [pdf]

#33
post #25

Earlier quoted context omitted.

How did you get into erlang, like in project wise? Because I played around with rabbitmq plugins, a nehe opengl examples port and some erlang notepad someone implemented. I also own both o'reilly hard copies. But other then that I don't really have a project I can see myself use erlang for(one man shop).

The Cowboy webserver is fairly easy to get started with and I really recommend checking it out, since a web server feels like a "very Erlang problem" to me. To answer your question though, I got started by playing with TCP and building a basic chat server. I spawned a new Erlang process for each user, used Erlang's internal messaging to share messages between processes, and then passed those messages along to TCP to…

Got a good book or website recommendation for learning Erlang?

How does it compare/contrast with something like Akka (which I've got rudimentary experience with in Scala)?

Re: Erlang and First-Person Shooters (2011) [pdf]

#34
post #9

From a gamers perspective, the peer-to-peer lobby system used in the CoD series is one of the worst things about it. I can remember constantly having to migrate hosts, getting owned by the host because everyone else has a ping much higher than zero, and horrible lag when the host it chose had a bad connection. Cool technology, but at the cost of fun.

As they say, when they first started with COD they had tons of scaling issues because they had never had so many before, but Erlang caused relatively few of their issues.

Re: Erlang and First-Person Shooters (2011) [pdf]

#35
post #15

Keep in mind that those are online services and can be developed in every languages since it's not hard real time ( aka C++ gameservers ). Most online services for the video game industry are actually made in Java.

> can be developed in every languages

Did you read the slides?

> Problems remain

   – C++ is the wrong language for concurrency
   – Code was becoming impossible to maintain
   – Poor error handling / debugging / metrics / scalability
   – Had to disconnect all users to change configuration
The point isn't that these things are impossible in other languages, it's that Erlang made solving these problems easier than other languages.

Re: Erlang and First-Person Shooters (2011) [pdf]

#36
post #33
post #25

Earlier quoted context omitted.

The Cowboy webserver is fairly easy to get started with and I really recommend checking it out, since a web server feels like a "very Erlang problem" to me. To answer your question though, I got started by playing with TCP and building a basic chat server. I spawned a new Erlang process for each user, used Erlang's internal messaging to share messages between processes, and then passed those messages along to TCP to…

Got a good book or website recommendation for learning Erlang? How does it compare/contrast with something like Akka (which I've got rudimentary experience with in Scala)?

http://learnyousomeerlang.com/ maybe

Re: Erlang and First-Person Shooters (2011) [pdf]

#37

Earlier quoted context omitted.

And it turns out a lot of problems actually fit that if you try to think about them that way. Sometimes it's worth -trying- to change your visualization; you'll find it works out better. We had to write task scheduling software where I worked, and someone unfamiliar with Erlang said something to the effect of "Oh, that's easy, priority queue". Well, no; there are all -sorts- of sharp edges to doing that. Instead we j…

I'm just curious, what are some of the disadvantages to priority queue?

Okay. Let's start with a perfectly naive priority queue. We have a default data structure (nevermind the implementation for now), and a thread that pulls items off the queue, and executes them. Works perfectly in test.

But we notice something; our executions take a non-zero amount of time, and so if we have two events happening simultaneously, they don't both get fired off in time. So now we have to switch to a thread pool, that gets handed events from the priority queue. Task runners, in effect. So, great. Everything works now.

But then we have to start accepting updates to tasks. That is, we are able to move a task forwards or backwards in time. Now, suddenly, we care about the underlying data structure of the queue; can we both be updating the order of events -and- be pulling from it? Does it require locking to do that?

Maybe it does require locking, in which case are we certain that we got ~that~ implemented right? Not just the queue library, but, in the event of an exception in our code, we correctly free the lock? And how long does it take to rebalance the queue? Is that acceptable, since we can't be pulling from the queue during that time?

Maybe it doesn't require locking, such as when using immutable data structures where we build a copy and swap it out, but then we might have a chance of executing a task twice (i.e., our task launcher thread reads copyA, while we're modifying copyB, and so the head of the queue in both gets executed), so now we have to keep tabs on what we launched last. But that assumes a stable priority queue in the event of two items having the same time; -that's- a fun edge case to miss.

But maybe we get all that working, by getting a lock-free priority queue in place. We have one thread reading from a priority queue, and handing tasks off to a thread pool. What size is the thread pool? What happens if a task is long running? Can we exhaust the thread pool?

What happens if we need to scale out a bit, because we're exhausting our thread pool? We only have one thing reading off the queue; can it hand those off to another machine in a timely enough fashion? Probably not, especially if we're getting GC pauses; how do we solve that? Maybe we change it so that we launch things a little early, either locally or remotely, and the thread sleeps until it's time to start the task. That will work, but what happens when we want to update the task? Now the logic exists in two places; the task could still be on the priority queue in which case we have to modify the queue, or the task could be sitting in its own thread, and we have to modify it there (arguably this existed before; if a task had started you modified it in the thread it was executing in, if the task hadn't started you had to modify the priority queue, but this makes it far less determinate).

Etc. In Erlang, you skip past all of these issues, and implement the end solution as your first, rather more easily. There's still a data structure somewhere saying what tasks have to execute, and when (probably just in your database, though, nothing needed in memory), but you don't have to worry about managing it beyond "hey, make sure the items for the next (time period) are running in a thread (Erlang process)". You can do that with one process launching the others, and (naive) distribution across machines is incredibly easy (the same complexities of handling partitions apply to both solutions). Individual tasks are built from the beginning to handle sleeping until start time, and updates are trivial, being just a message to them that they respond to, and a modification of your data structure (database). There's no tight coupling between the two. You end up with just "whenever a change in events happens (creation or update), send a message to that process if it exists, and update the DB". And the process scheduler in Erlang handles all the concurrency. There's no locking you have to worry about, and latency will be spread equally, rather than running the risk of choking out a single task.

And this is the -naive- Erlang implementation. That's the benefit. For this particular use case, with priority queues you start running into issues, and as you solve them, your implementation looks more and more like the naive Erlang implementation.

Re: Erlang and First-Person Shooters (2011) [pdf]

#38

Earlier quoted context omitted.

I'm just curious, what are some of the disadvantages to priority queue?

Okay. Let's start with a perfectly naive priority queue. We have a default data structure (nevermind the implementation for now), and a thread that pulls items off the queue, and executes them. Works perfectly in test. But we notice something; our executions take a non-zero amount of time, and so if we have two events happening simultaneously, they don't both get fired off in time. So now we have to switch to a threa…

Thank you so much for the write up, I'm just getting into programming at school and this was a fantastic and interesting read! I've always been interested in how data structures work in real-life applications and I'm thankful for the explanation.

Re: Erlang and First-Person Shooters (2011) [pdf]

#39
post #31

Earlier quoted context omitted.

I'm wondering the same :)...

In 2011 Exlixir didn't exist. More than likely they've stuck to Erlang as the incremental benefit is really on the language side only. If you're only moving to Elixir because of the language sugar, the only thing you're going to gain is maintenance and updates -- with a system that probably doesn't need all that much in the way of "tinkering".

Elixir doesn't just add "sugar" though; it has full-fledged first-order macros, through-and-through UTF8 support, sensical argument placement (the thing being acted upon is always the first argument, making possible the |> operator), sigils, great tooling, and possibly best of all, the best Rubyists are fleeing to it. ;)

Re: Erlang and First-Person Shooters (2011) [pdf]

#40
post #11
post #3

Question for those of you who are game programmers. Is the message passing of erlang slower than shared memory threads in c++?

Everything I've ever heard on that front is that Erlang should be considered a control layer which has any CPU-bound tasks run in C. Actors/message passing is a good synchronization primitive but there is apparently a whole host of issues with memory leaks regarding it in the "Erlang in Anger" e-book. I personally lost interest in Erlang because of it only supporting actors as a concurrency mechanism. They're good fo…

I second the question of wondering what sort of concurrency is not well-serviced by the actor model? (especially considering you have zero locking to worry about)
Post reply on HN