From: Marcin Raczkowski Date: 2007-05-10T18:45:47+09:00 Subject: Re: basic threading question: can ruby use real threads? On Wednesday 09 May 2007 19:20, Gary Wright wrote: > On May 9, 2007, at 2:57 PM, Marcin Raczkowski wrote: > > I didn't say it makes use of POSIX threads - i just recomended it > > becouse they > > are well ... faster. > > > > only thing right now that'll let you use botht procesors is fork > > Just my opinion but my default choice would be fork when I need > concurrency rather than threads. The main reason is that it forces you > to be explicit in how you structure the communication between processes. > One process can't inadvertently change the state of another. > On a multi-processor box you'll get IO multiplexing and real CPU > concurrency automatically with fork. > > Some problems can't be partitioned easily into separate addresses > spaces, > in which case threads are a better choice. Even then I might consider > using shared memory among cooperating processes first. > > I realize that the Unix fork/exec model of processes doesn't quite apply > in the Windows environment. Anecdotal evidence makes me think that > Windows programmers tend to reach for threads as a multi-tasking > solution > more often than Unix programmers. > > One more observation. The desire for real concurrency using multiple > processors is great for problems that can be cleanly partitioned, but if > you have a problem that requires concurrent access to shared data then > you'll have to keep in mind the memory/cache contention that will be > created when processing is distributed across multiple processors (via > processes or threads). > > Gary Wright As i mentioned earlier - easiest way to get REAL concurency (java VM will NOT use both processors - for few reasons JavaVM ALWAYS use one processor - scalling for example Tomcat in production enviroment require running 2-4 java VM's) is to use Slave gem - I'm using it for my project for concurent parasing of logs - overhead on DRb is not big -and what's more you can use it on few machines if you want to scale it further http://www.codeforpeople.com/lib/ruby/slave/slave-1.2.1/ creating new forks is really easy and you can create just one class for procesing of data that can be concurent and everything else can be done in main program -- Marcin Raczkowski --- Friends teach what you should know Enemies Teach what you have to know