3 ms·
I run an online game that has has instanced multiplayer. We have a single process on each server that starts up and loads every single game resource. After thi
by Negitivefrags 8y ago
I run an online game that has has instanced multiplayer.
We have a single process on each server that starts up and loads every single game resource. After this is waits for requests from the instance manager to create new instances. As new instances are required, this "spawner" process fork()s to create one.
Each process uses less memory because all the loaded resources the game needs to run are shared between all the copies.
You also get slightly faster performance because commonly used data still in the CPU cache when switching between processes.
If we used a thread per instance, then we wouldn't have crash isolation between the different game instances, which is handy.
It's also possible to explicitly mmap a shared memory segment to load resources in that without using fork()s copy on write, but it's just more tricky, and the fork() method is totally robust no matter what code other programmers might write.