View Single Post
Old 02-13-2012, 09:03 AM   #2
dentin
Member
 
Join Date: Apr 2008
Home MUD: Alter Aeon
Posts: 245
dentin is on a distinguished road
Re: High volume scripting question

Kitriel,

Any time you add threading to the system, you're opening yourself up to a whole new class of bugs and problems. Unless you know what you're doing, have the resources to spare, and are using a language that's intrinsically thread safe, you're risking a lot.

Quite frankly, I'm not smart enough to do it well, so I handled it on AA by simply running everything single threaded and simulating the multithreading aspect using event handlers. We currently have three lists with different time bases, and shortly after boot we have about 25k events pending:

Slice events: 21555
Prompt events: 2978
Tick events: 850

While AA is a moderately sized game in terms of DB size, I wouldn't consider it particularly 'NPC active'; my guess is that with everything you want to do on your server, you're going to have an order of magnitude more stuff going on. Consider for the moment that you may end up having half a million threads, and I think the scale of the problem with threading becomes clear.

So in short, I would recommend running everything except for possibly world saves single threaded using your own internal event queues. Doing this eliminates the need for all the expensive locking, and guarantees consistency of data without it needing to be explicitly handled. You do have to take care of proper destruct handling, but that's arguably less of a concern than managing 100k threads, and will be easier to debug (especially if you use structure pools.)

Another thing to consider is that there's a CPU processing limit, and that if you're doing this because you need more cores to handle the workload, you're probably doing something wrong. At full bore with a hundred people logged in, 30k events in the queues, and 25k mobs, the AA server runs 1-5% CPU; even with a world ten times as complex, there should be no reason to thread the workload as long as the latency requirements are met.

-dentin

Alter Aeon MUD
dentin is offline   Reply With Quote