Skip to main content

Large scale ambitions

Learning new things is important for every developer. I've mentioned this before, and in the spirit of doing just that, I've started a somewhat ambitious project.

I want to do a large-scale simulation, using Elixir and Go, coupled with a physics simulation in C++. I've never done anything in Elixir before, and only played a little bit with Go, but I figure, how hard can it be?


I've dubbed this project exsim - it's a simulation done in Elixir. Someday I'll think about a more catchy name - for now I'm just focusing on the technical bits. Here's an overview of the system as I see it today:

exsim sits at the heart of it - this is the main server, implemented in Elixir.
exsim-physics is the physics simulation. It is implemented in C++, using the Bullet physics library.
exsim-physics-viewer is a simple viewer for the state of the physics simulation, written in Go.
exsim-bot is a bot for testing exsim, written in Go.
exsim-client is the game client, for interacting with the simulation. I haven't actually started this yet - more on that later.

Note that this is very much work in progress - I'm not describing a completed project, my plan is to post a series of blogs about this project as it evolves, warts and all. I fully expect to experience some failures and may do stupid things because I'm learning the language - I'll write about those things as well.

So what am I simulating? Well, I've been working on EVE Online for quite some time now, so of course I'm going to do a space simulation. The purpose of this exercise is to learn two new programming languages and get familiar with the physics system so I don't want to spend time on an original game design. I'm not saying I'm going to reimplement EVE, but I am going to take some aspects of it and see how they could work in Elixir and Go.

The server

The core of this project is exsim - this is the game server, done in Elixir. It's what players (bots) connect to - it maintains the state of the world and each ship in it and distributes the state to game clients (bots) as appropriate.

To begin with, all communication between components is done in JSON format. This may not be the most efficient format, but I've opted to at least begin with a text based format. This allows me start up the server and connect to it with a simple telnet client, typing in the commands on the fly. I chose JSON because it is well supported in Elixir, Go and C++ so I don't have to spend time on writing a parser.

The physics server

The physics server is really just a thin wrapper around the Bullet physics library. The physics server runs a solar system, with a collection of ships in it. Eventually there will be a sun, planets, space stations and jump gates (to travel to other solar systems) in there as well.

The physics server has a master socket connection to the server, and can have one or more viewer connections as well. The master connection can issue commands to the server, to add/remove ships, set ship properties, step the simulation and get the state. The viewer connections get a copy of the state, to enable a debug view of the state of the simulation.

The commands are again in JSON format (as well as the responses), using RapidJSON for parsing (and emitting) the JSON strings.

The physics viewer

The physics viewer is a simple 2D viewer implemented in Go, using the Pixel 2D game library. It opens a socket connection to the physics server and listens for state packets. It draws a shape for each ship listed in the state, giving a quick visualization of the state of the solar system. For this to work, I'm limiting all movements to the x-y plane - eventually this will have to be replaced with a 3D viewer.


Botting in a live game is bad, but running bots for testing is awesome. I don't want to have to run multiple clients connecting to the server to test things - I want to run one program that simulates dozens of players. Eventually I want to use bots to load test the server, not with dozens, but thousands or tens of thousands of simulated players.

So far, I've only implemented one extremely simple bot. It connects, sets a random target location to fly towards, waits a few seconds and sets a new target location, and so on.

Current status

The server accepts connections from the bots, adding ships to the physics scene, ticks the simulation and broadcasts the state. There is no partitioning of the solar system - every ship is notified of the state of every other ship. There is also no error handling, not even of closed connections. I need to harden that up somewhat soon, if only to make it easier to iterate on things. 

The next step is to see how many ships I can throw into the solar system and see where the bottlenecks are. In some very preliminary tests I'm seeing indications that JSON may not be feasible to use in any large scale communications, but I need to run some more tests before I decide to toss it out.


Popular posts from this blog

Mnesia queries

I've added search and trim to my expiring records module in Erlang. This started out as an in-memory key/value store, that I then migrated over to using Mnesia and eventually to a replicated Mnesia table. The fetch/1 function is already doing a simple query, with match_object. Result=mnesia:match_object(expiring_records, #record{key=Key, value='_', expires_at='_'}, read) The three parameters there are the name of the table - expiring_records, the matching pattern and the lock type (read lock). The fetch/1 function looks up the key as it was added to the table with store/3. If the key is a tuple, we can also do a partial match: Result=mnesia:match_object(expiring_records, #record{key= {'_', "bongo"}, value='_', expires_at='_'}, read) I've added a search/1 function the module that takes in a matching pattern and returns a list of items where the key matches the pattern. Here's the test for the search/1 function: search_partial_…

Replicated Mnesia

I'm still working on my expiring records module in Erlang (see here and here for my previous posts on this). Previously, I had started using Mnesia, but only a RAM based table. I've now switched it over to a replicated disc based table. That was easy enough, but it took a while to figure out how to do, nonetheless. I had assumed that simply adding ... {disc_copies, [node()]} ... to the arguments to mnesia:create_table would be enough. This resulted in an error: {app_test,init_per_testcase, {{badmatch, {aborted, {bad_type,expiring_records,disc_copies,nonode@nohost}}}, ... After some head-scratching and lots of Googling I realized that I was missing a call to mnesia:create_schema to allow it to create disc based tables. My tests for this module are done with common_test so I set up a per suite initialization function like this: init_per_suite(Config) ->mnesia:create_schema([node()]), mnesia:start(…

Optimizing Wine on OS X

I've been doing some performance analysis of EVE running under Wine on OS X. My main test cases are a series of scenes run with the EVE Probe - our internal benchmarking tool. This is far more convenient than running the full EVE client, as it focuses purely on the graphics performance and does not require any user input.

Wine Staging One thing I tried was to build Wine Staging. On its own, that did not really change anything. Turning on CSMT, on the other hand, made quite a difference, taking the average frame time down by 30% for the test scene I used. While the performance boost was significant there were also significant glitches in the rendering, with parts of the scene flickering in and out. Too bad - it means I can't consider this yet for EVE, but I will monitor the progress of this. OpenGL Profiler Apple has the very useful OpenGL profiler available for download. I tried running one of the simpler scenes under the profiler to capture statistics on the OpenGL calls mad…