Tags

4.28.2011

Curse you, Nagle!

WARNING: Technical post :P

I've been tinkering with the high scores server a bit because performance seemed more sluggish than it aught to be. We use MySQL for storing data, and I'm using the mysqlpp connector for accessing it. Each request spawns its own thread and its own mysqlpp::Connection to the database, which takes a bit of time. I created a simple 'connection pool' that keeps open connections around to serve requests, which helped speed quite a bit. Still, extremely simple requests were taking 400ms to complete... completely unacceptable!

I turned my eyes to the sockets next. We use boost::asio as the core of our network library. For some reason, a send/recv for one packet was causing a 300ms delay. Didn't make sense at all since the latency between server and client was around 70ms. Turns out Nagle's algorithm is enabled by default in most sockets, which is normally a Good Thing in a high-throughput scenario. Our situation is NOT this kind of scenario however, so each of our messages was waiting around for other data to join it and being delayed. I disabled the delay with the following command:

socket.set_option( boost::asio::ip::tcp::no_delay(true) );

Now the request that was taking 400ms now takes around 80ms. Much better! You can definitely tell a difference in snappiness in the game menus.

No comments:

Post a Comment