Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Dec 06, 2007 2:47 pm   

Big Thread improvement for v2.15
 
Now that the threading system has been pretty well tested, I am making a big change/optimization in v2.15.

In v2.15, CMUD will check to see if you are using #WAIT commands (#WAIT, #WAITSIGNAL, #WAITFOR, #WAITTHREAD) or the #THREAD command (with parameters) or the #SUSPEND command. This check is done when something is compiled (like the command line, or an alias, trigger, etc).

If the script does *not* use one of these threading commands, then the script is executed in the main UI thread without creating any thread object.

This causes a big performance boost for most scripts since they are not running in a separate thread and, therefore, do not need all of the overhead to synchronize various non-thread-safe commands with the main thread.

This should allow most threads to run at the same speed that they did in v1.34 before threads were added. But it still allows proper use of the various #WAIT commands that were added in v2.x. The best of both worlds.

To force a script to run in it's own thread, use use the '#THREAD name' command to name the thread. This might be needed if you are doing something really obscure like running #WAIT within an #EXEC command.

I have been thinking about this kind of optimization for several months. But I only wanted to add it right before the public release so that we could really stress-test the threading system. If I had added this several months ago, then most people wouldn't have used threads and we wouldn't have gotten the testing that we really needed to make CMUD stable.
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Thu Dec 06, 2007 3:51 pm   
 
Very nice. Although now I'll have to really do some thinking before I choose to implement any threading functionality in my scripts. I'll have to make sure any benefit I gain from multi-threading will outmatch the slowdown that will occur by adding it. I guess once you have it in we'll be able to see the magnitude of the difference. In general I'd want to move toward some type of threading in my scripts to take advantage of additional processors, but this will make it very seductive to have it all one thread.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Dec 06, 2007 4:39 pm   
 
The slowdown is pretty minor, so I wouldn't let that keep you from using threads when you need them.
Reply with quote
Asilient_1
Apprentice


Joined: 26 Apr 2007
Posts: 113

PostPosted: Fri Dec 07, 2007 12:34 am   
 
Who feels conned? >.>

In seriousness, this is a great change, Zugg. I can only guess how many complaints we had against multithreading because of the problems that came with it.
Reply with quote
Llwethen
Novice


Joined: 08 Dec 2006
Posts: 37
Location: Lancaster,Oh

PostPosted: Fri Dec 07, 2007 3:55 pm   Re: Big Thread improvement for v2.15
 
Zugg wrote:
Now that the threading system has been pretty well tested, I am making a big change/optimization in v2.15.

This causes a big performance boost for most scripts since they are not running in a separate thread and, therefore, do not need all of the overhead to synchronize various non-thread-safe commands with the main thread.



Delphi is using kernel-space threading isn't it? Definitely would explain the overhead and sync issues.

I just went through the nightmare of mutex/semaphores/spinlocks and the huge overhead of kernel threading. Finally chunked it all and went to a system similar to Erlang\Haskell, basically using Actor modeling and message passing for ipc. It is a bit of a mind-bender to go past object-oriented and how to deal with no locks but makes everything more sane when you don't have to worry if you somehow created a deadlock situation between modules. Threads become very cheap at that point and concurrency is easy.

Granted you'd be insane to rewrite at this point but it is something to consider for 3.0.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net