Monday, June 2, 2008

Torque CPU performance.

This could *significantly* reduce my CPU usage:


Torque and CPU usage

Of all of the performance /
scalability considerations of stock TGE 1.5, this was my first concern.
A single dedicated server running on a very nice Linux box (Dual CPU /
Dual Core 64 bit AMD Opteron with 2gb RAM) consumed over 50% of the
CPU... and that was an empty server!

The problem is that
although on the surface the engine appears event driven, it's actually
polling the event queue instead of waiting on the event queue and it
has a sleep() that essentially makes it poll once per tick (1/32 of a
second). The problem is the stock sleep implementation turned into a
sleep(0), which essentially did nothing except give up the current time
slice and made the game engine run in a fairly tight loop.... this is
ok if you're running a single zone server per CPU, but if you're
wanting to run 10 zones on a dual CPU box then... well... it's not
going to happen.

The quick fix is to re-implement sleep() so
that it sleeps for the appropriate amount of time. An empty server
takes negligible CPU, and a decently loaded server only takes about 5%
of the CPU... awesome!

Long-term fix is to eliminate the polling
and make everything event driven, although at the moment it doesn't
appear that this solution is required. You'll end up running out of
memory before you run out of CPU cycles (10 zones on a single box
pretty much chews up all 2gb of RAM).

No comments: