[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Spin buffers

John Carter

7/16/2007 2:21:00 AM

4 Answers

Robert Klemme

7/16/2007 5:28:00 AM

0

On 16.07.2007 04:20, John Carter wrote:
> Hmm. Just being reading the Dr. Dobbs.
>
> I certainly have hit the bottleneck talked about in this article...
> http://www.ddj.com/dept/architect...
> when using the 'thread.rb' Queue class.

What exactly makes you believe that? Can you show some code and / or
figures that back this theory?

> I hacked around it by creating a Queue of Arrays, but that probably
> creates more garbage than I should.

Difficult to say without seeing the code. Generally I'd say that Queue
is pretty efficient already since it's implemented in C AFAIR.

> This "Spin Buffer" trick looks Good...
> http://www.ddj.com/dept/architect...?pgno=2
>
> Anyone have a ruby Spin Buffer implementation lying around?

I'd check with the RAA.

Kind regards

robert

ara.t.howard

7/16/2007 5:46:00 AM

0


On Jul 15, 2007, at 8:20 PM, John Carter wrote:

> Anyone have a ruby Spin Buffer implementation lying around?

no, but i'd be inclined to try writing one on top of guy's mmap ext -
the interface is that of string so the example should map (no pun
intended) rather well.

cheers.

a @ http://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




MenTaLguY

7/18/2007 12:57:00 AM

0

On Mon, 2007-07-16 at 14:30 +0900, Robert Klemme wrote:
> What exactly makes you believe that? Can you show some code and / or
> figures that back this theory?

Seconded. Measure first, then optimize.

> > I hacked around it by creating a Queue of Arrays, but that probably
> > creates more garbage than I should.

That probably performs slower than Queue.

> Difficult to say without seeing the code. Generally I'd say that Queue
> is pretty efficient already since it's implemented in C AFAIR.

Depends on the version of Ruby. It certainly is if you're using
fastthread. If he's not using fastthread, I'd recommend giving it a
try.

> > This "Spin Buffer" trick looks Good...
> > http://www.ddj.com/dept/architect/199902...
> >
> > Anyone have a ruby Spin Buffer implementation lying around?

"Spin Buffers" are _snake oil_; they get their "speed" at the expense of
correctness -- the implementation given in the DDJ article is not
threadsafe. If it were rewritten to be threadsafe, it would actually be
slower than some simpler alternatives.

-mental

MenTaLguY

7/18/2007 12:59:00 AM

0

On Mon, 2007-07-16 at 14:46 +0900, ara.t.howard wrote:
> no, but i'd be inclined to try writing one on top of guy's mmap ext -
> the interface is that of string so the example should map (no pun
> intended) rather well.

What does mmap have to do with communication between Ruby threads?

(and again, I'd like to emphasize that "spin buffers" are snake oil)

-mental