Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > question: threads behaviour

Reply
Thread Tools

question: threads behaviour

 
 
Raphael Bauduin
Guest
Posts: n/a
 
      03-01-2011
Hi,

As ruby threads are so called green threads, what's the behaviour when
one thread is blocked on IO?
If the thread is blocked on a system call, is the whole process, ie
all threads blocked because the kernel scheduler considers the process
as blocked on IO? Are there IOs blocking a thread without blocking the
whole ruby process?

Thanks

Rapha=EBl

 
Reply With Quote
 
 
 
 
me@kmwhite.net
Guest
Posts: n/a
 
      03-01-2011
On Tue, 1 Mar 2011 17:45:26 +0900, Raphael Bauduin <(E-Mail Removed)>
wrote:
> Hi,
>
> As ruby threads are so called green threads, what's the behaviour when
> one thread is blocked on IO?
> If the thread is blocked on a system call, is the whole process, ie
> all threads blocked because the kernel scheduler considers the process
> as blocked on IO? Are there IOs blocking a thread without blocking the
> whole ruby process?
>
> Thanks
>
> Raphaël


I'm new to threading, but from what I've been able to find, if the
currently active thread is blocked on IO, it should block the rest of them.
At least, certain circumstances could cause that. According to (the rather
old) post at http://www.justskins.com/forums/when...ck-107159.html
, it's possible to block on IO. My own tests are unable to confirm that,
even for large test sizes. My guess is that in the 7ish years since that
post, many improvements have gone into the interpreter. The post at
http://stackoverflow.com/questions/3...he-main-thread
has more information on ways of using them to not block each other.

http://www.ruby-doc.org/docs/Program...t_threads.html was
where I started for threading, but the only references I see to blocking in
it talk about the Thread.critical= method.

http://stackoverflow.com/questions/5...ng/57802#57802
has a nice synopsis of the threading types between ruby implementations.

 
Reply With Quote
 
 
 
 
Eric Wong
Guest
Posts: n/a
 
      03-01-2011
Raphael Bauduin <(E-Mail Removed)> wrote:
> Hi,
>
> As ruby threads are so called green threads, what's the behaviour when
> one thread is blocked on IO?


They're only green threads on Ruby 1.8, 1.9 uses native threads.

> If the thread is blocked on a system call, is the whole process, ie
> all threads blocked because the kernel scheduler considers the process
> as blocked on IO? Are there IOs blocking a thread without blocking the
> whole ruby process?


1.8 will schedule other threads if the blocking IO is for a socket/pipe
and uses the normal Ruby IO interfaces (or the extension author was
careful). Filesystem I/O (including NFS) can block the entire process
in 1.8.

--
Eric Wong

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      03-01-2011
On Tue, Mar 1, 2011 at 10:27 AM, Eric Wong <(E-Mail Removed)> wrote:
> Raphael Bauduin <(E-Mail Removed)> wrote:
>> As ruby threads are so called green threads, what's the behaviour when
>> one thread is blocked on IO?

>
> They're only green threads on Ruby 1.8, 1.9 uses native threads.
>
>> If the thread is blocked on a system call, is the whole process, ie
>> all threads blocked because the kernel scheduler considers the process
>> as blocked on IO? Are there IOs blocking a thread without blocking the
>> whole ruby process?

>
> 1.8 will schedule other threads if the blocking IO is for a socket/pipe
> and uses the normal Ruby IO interfaces (or the extension author was
> careful). =A0Filesystem I/O (including NFS) can block the entire process
> in 1.8.


Where do you take that from? AFAIK internally Ruby 1.8.* uses non
blocking IO calls in combination with select() to be able to let other
threads work while IO is under way.

So: if IO blocks generally other threads continue to work - even on 1.8.

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
Eric Wong
Guest
Posts: n/a
 
      03-01-2011
Robert Klemme <(E-Mail Removed)> wrote:
> > 1.8 will schedule other threads if the blocking IO is for a socket/pipe
> > and uses the normal Ruby IO interfaces (or the extension author was
> > careful). *Filesystem I/O (including NFS) can block the entire process
> > in 1.8.

>
> Where do you take that from? AFAIK internally Ruby 1.8.* uses non
> blocking IO calls in combination with select() to be able to let other
> threads work while IO is under way.


Yes, I meant "blocking" from a user-visible perspective, not from a
kernel perspective. If there's an EAGAIN it'll block the current thread
from a user perspective and schedule others using select(), but not
actually block on the syscall that caused EAGAIN.

--
Eric Wong

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      03-01-2011
On 03/01/2011 08:16 PM, Eric Wong wrote:
> Robert Klemme<(E-Mail Removed)> wrote:
>>> 1.8 will schedule other threads if the blocking IO is for a socket/pipe
>>> and uses the normal Ruby IO interfaces (or the extension author was
>>> careful). Filesystem I/O (including NFS) can block the entire process
>>> in 1.8.

>>
>> Where do you take that from? AFAIK internally Ruby 1.8.* uses non
>> blocking IO calls in combination with select() to be able to let other
>> threads work while IO is under way.

>
> Yes, I meant "blocking" from a user-visible perspective, not from a
> kernel perspective. If there's an EAGAIN it'll block the current thread
> from a user perspective and schedule others using select(), but not
> actually block on the syscall that caused EAGAIN.


OK, but earlier you said that file system IO can block the entire
process - which is not exactly true and also does not match what you
said now.

Cheers

robert
 
Reply With Quote
 
Eric Wong
Guest
Posts: n/a
 
      03-01-2011
Robert Klemme <(E-Mail Removed)> wrote:
> On 03/01/2011 08:16 PM, Eric Wong wrote:
>> Robert Klemme<(E-Mail Removed)> wrote:
>>>> 1.8 will schedule other threads if the blocking IO is for a socket/pipe
>>>> and uses the normal Ruby IO interfaces (or the extension author was
>>>> careful). Filesystem I/O (including NFS) can block the entire process
>>>> in 1.8.
>>>
>>> Where do you take that from? AFAIK internally Ruby 1.8.* uses non
>>> blocking IO calls in combination with select() to be able to let other
>>> threads work while IO is under way.

>>
>> Yes, I meant "blocking" from a user-visible perspective, not from a
>> kernel perspective. If there's an EAGAIN it'll block the current thread
>> from a user perspective and schedule others using select(), but not
>> actually block on the syscall that caused EAGAIN.

>
> OK, but earlier you said that file system IO can block the entire
> process - which is not exactly true and also does not match what you
> said now.


Filesystem IO (regular files) doesn't return EAGAIN (at least not on
systems I'm familiar with).

--
Eric Wong

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      03-02-2011
On Tue, Mar 1, 2011 at 11:13 PM, Eric Wong <(E-Mail Removed)> wrote:
> Robert Klemme <(E-Mail Removed)> wrote:
>> On 03/01/2011 08:16 PM, Eric Wong wrote:
>>> Robert Klemme<(E-Mail Removed)> =A0wrote:
>>>>> 1.8 will schedule other threads if the blocking IO is for a socket/pi=

pe
>>>>> and uses the normal Ruby IO interfaces (or the extension author was
>>>>> careful). =A0Filesystem I/O (including NFS) can block the entire proc=

ess
>>>>> in 1.8.
>>>>
>>>> Where do you take that from? =A0AFAIK internally Ruby 1.8.* uses non
>>>> blocking IO calls in combination with select() to be able to let other
>>>> threads work while IO is under way.
>>>
>>> Yes, I meant "blocking" from a user-visible perspective, not from a
>>> kernel perspective. =A0If there's an EAGAIN it'll block the current thr=

ead
>>> from a user perspective and schedule others using select(), but not
>>> actually block on the syscall that caused EAGAIN.

>>
>> OK, but earlier you said that file system IO can block the entire
>> process - which is not exactly true and also does not match what you
>> said now.

>
> Filesystem IO (regular files) doesn't return EAGAIN (at least not on
> systems I'm familiar with).


http://www.kernel.org/doc/man-pages/....2.html#ERRORS

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
Eric Wong
Guest
Posts: n/a
 
      03-02-2011
Robert Klemme <(E-Mail Removed)> wrote:
> On Tue, Mar 1, 2011 at 11:13 PM, Eric Wong <(E-Mail Removed)> wrote:
> > Filesystem IO (regular files) doesn't return EAGAIN (at least not on
> > systems I'm familiar with).

>
> http://www.kernel.org/doc/man-pages/....2.html#ERRORS


From http://www.kernel.org/doc/man-pages/...d.2.html#NOTES

Many file systems and disks were considered to be fast enough
that the implementation of O_NONBLOCK was deemed unnecessary.
So, O_NONBLOCK may not be available on files and/or disks.

From what I've seen, setting O_NONBLOCK doesn't error, but read() never
actually respects it on ext{2,3,4} even when a disk is horribly slow.

--
Eric Wong

 
Reply With Quote
 
Jörg W Mittag
Guest
Posts: n/a
 
      03-02-2011
Eric Wong wrote:
> Raphael Bauduin <(E-Mail Removed)> wrote:
>> As ruby threads are so called green threads, what's the behaviour when
>> one thread is blocked on IO?

> They're only green threads on Ruby 1.8, 1.9 uses native threads.


That's not true. The vast majority of Ruby 1.8 implementations use
native threads, and I think there is at least one Ruby 1.9
implementation which uses green threads.

jwm
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[THREADS] Behaviour of Thread#stop? Xavier Nolle Ruby 3 12-16-2010 11:32 AM
debugger behaviour different to execution behaviour Andy Chambers Java 1 05-14-2007 09:51 AM
Strange Threads Behaviour... rodmc Python 2 05-05-2006 09:02 AM
TB View, Threads, Threads with unread The Invisible Man Firefox 1 03-20-2006 02:09 AM
Threads and modal dialog behaviour question =?ISO-8859-1?Q?Aloys_Oberth=FCr?= Java 6 12-09-2004 12:11 PM



Advertisments