Instead…

I wound up distracting myself even more from my already sidelined weekend plan.

I keep harping on about ZeroMQ but I don’t think I’ve yet managed to really convey why it’s so worth programmers looking at…

The problem is, when you look at ZMQ for the first time, it just looks “meh, sockets”. But that is just the API. ZeroMQ isn’t primarily a networking library! It does a whole lot of stuff, across multiple languages, all through that one single API. So all you have to do to change the scope of your application is change the URL of the socket you plan to connect to…

Sure: With sockets, you can have multiple clients connect to the same destination. In ZMQ you can have multiple clients and servers talk to the same destination without having to know about it inside the application… The multiplexing is transparent and built-in.

And that’s just one aspect of why I really like it.

The work I was going to do over the weekend requires several knock-on changes to the rest of the game-server systems. Players will keep a persistent connection to our map/mission server.

Despite all the subsystems we’ve added, the map mission host has gone from using 80-90% CPU to using single digits with a heavy load. Mostly this is because work has simply gotten moved elsewhere to work around the fact players only talk to it before they spawn and after they despawn.

The map/mission host is supposed to be the server streaming you the latest updates from strat. But, instead, that data has to be forwarded various places. One of these is the cell hosts, which incorporate sending you strat changes with your periodic update, which otherwise describes updates to your vis list and the players on it.

For CP and Facility updates, there is no really good reason for this data to be there – except that you don’t have a connection to the map/mission host. And the system for streaming updates on the map/mission host doesn’t take advantage of modern CPU architecture because it’s only dealing with a handful of users who aren’t spawned.

It occurred to me that we could cut out an awful lot of middle-man and CPU waste by allowing clients to tune in to the stream of updates being sent to the host processes.

DENIED: Right now the strat host uses four different mechanisms for streaming that data to different hosts. Sigh.

Sitting pondering this, I realized that it would take just a few minutes to replace all of them with a ZeroMQ pub/sub socket pair sending out updates, and a second req/rep socket for taking requests for a full snapshot.

Once again, ZeroMQ surprised me by making it trivial.

The throughput is as impressive as always, and it can be fronted by zmq “devices” (little forward applications) so that the strat machine itself doesn’t have to handle the multicasting.

It was also delicious to be able to test interaction with the new interface from pretty much any language I chose: C++, Lua, Python, Perl, Ruby…

So much so that I put together this YouTube video to try and demonstrate some of why I’m really starting to love ZeroMQ.

If you watch through to the end, I do a little benchmark of simple parallelism with ZeroMQ and Async::Worker.

7 Comments

Interesting, but I got lost when you got to the parallel version of the example, since I don’t know how your async_worker works. It wasn’t clear to me how the threads are spawned, etc.

Nice video !

You just hit the front page of http://www.zeromq.org/ :-)

Thanks, Lutorm :) I’m looking for feedback. And that was a gaping hole – hence the splash.

The threads are created automatically for you the first time you dispatch a task, and they stay up until the end of the application, waiting on IO (which makes them os-scheduling friendly).

“Batches” are consecutive groups of numbers to be crunched by a worker. Thus increasing the batch size reduces the number of workloads and means each individual worker spends more time in the for the loop – hence it runs faster up to a point.

Tuning that becomes a non-trivial issue and I didn’t want to get into that since it’s not, specifically, ZeroMQ but my noddy little addon :)

Well done Oli!

No. Well done Laccy!

Could you put the slides up somewhere? :)

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

You may use these HTML tags and attributes:

<a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: