[ale] Re: Threading? (was: Re: [ale] C#)

Michael D. Hirsch mhirsch at nubridges.com
Thu Sep 26 09:18:45 EDT 2002


On Wednesday 25 September 2002 09:46 pm, Jeff Hubbs wrote:
> OK, I've held back my ignorance about as long as I can.
>
> Can you explain to me "threading?"  I think I stopped coding a little
> too early in life (Pascal-on-VAX/VMS-era) to really understand what
> all this is about.  My crude understanding is that threading is where
> one process branches off into multiple "threads" of execution, the
> distinction between processes and threads being that threads all
> execute in the same context.  Is my conceptualization more or less
> correct?

That is about right.  There are two ways to do threads.  The first way 
(user threads) is to write a threading library which gets linked in to 
your code.  This library has some clever code that switches between 
threads.

The other way (kernel threads) is to have an OS that understands threads 
and let the kernel scheduler schedule them.  In Linux the kernel 
actually doesn't know the difference betwenn threads and processes and 
it schedules them identically.

Remember all the debates about "preemptive" vs. "cooperative" OSes.  
Windows and Mac were cooperative and Unix and NT were preemptive.  This 
is a very similar debate.  With user threads, when a thread is stuck in 
a system call, there is no way for the scheduling library to run 
another thread.  With kernel threads, when a thread is in a system call 
the kernel may be able to schedule some other process or thread.

> And can you elaborate a bit about "python has way worse threading
> than java?"  What constitutes "worse?"  Is there an underlying reason
> why that is so?

Sure, as you might guess from the above, the issue is what kind of 
threads they use.  Java supports both kinds of threads, but almost 
everyone uses kernel threads.  When one thread is blocking on I/O, 
other threads can run.  (Java calls these "green threads" and "native 
threads".)

Python only has user threads (I think--I'm no expert on this aspect of 
python).  When a thread does I/O the threading library is pretty clever 
and can time it out, but until it either times out or finishes, no 
other thread in that process will proceed.  So in, say, a web server 
like ZOPE, if there are a lot of connections there will be a lot of 
threads blocking on I/O.  This will slow it down incredibly.  Also if 
the threads have to pull data off the disk they will block on disk 
access, again slowing it down.  For this reason ZOPE tries to cache all 
it's objects in RAM.  It is quite possible to run out of RAM for this.  
Also, until everything is in RAM there are lots of threads blocking on 
disk access.

I think I read somewhere that python is trying to use kernel threads, 
but I don't recall if that was in version 2.2, which is already 
release, or in a future version.

I love python--I would say it is my favorite language--and I hope it 
gets better threading support soon.

--Michael

> - Jeff
>
> On Wed, 2002-09-25 at 20:10, Michael D. Hirsch wrote:
> > On Wed, 2002-09-25 at 15:19, Benjamin Scherrey wrote:
> > > Do it in python. You get an even easier language to use than
> > > java, all the platform independence (and perhaps more), and can
> > > always plug in some C/C++ stuff in the backend if performance
> > > becomes an issue. I'm doing all my web development in python now
> > > using mod_python and quixote. Database connectivity is great as
> > > well which is better than I can say for java or C# (although I'll
> > > be interested when a good implementation of jdo comes out).
> >
> > AAK!  I love Python, but don't do it in python.  Unless version 2.2
> > has changed things dramatically, python has way worse threading
> > than java.  Java at least uses native threads, so they are
> > scheduled efficiantly.  Last I heard python did it's own threading
> > and a highly threaded program where the threads are I/O bound will
> > just crawl.  This was something that killed us when using ZOPE,
> > another extremely cool program.
> >
> > --Michael
> >
> > >       good luck & let us know what you do,
> > >
> > >               Ben Scherrey
> > >
> > > On Wednesday 25 September 2002 02:54 pm, cfowler wrote:
> > > > Right now I'm at the beginning of a large Java project.  I'm
> > > > just desiging forms for now.  But this is just graphics.  I'm
> > > > doing research as to the best way to go.  I need to be scalable
> > > > when it comes to threads and I believe that Java may bite me in
> > > > the end. I want to handle 100+ TCP connections into one client.
> > > >
> > > > On Wed, 2002-09-25 at 14:48, Geoffrey wrote:
> > > > > cfowler wrote:
> > > > > > Anyone here using C# on Linux?
> > > > >
> > > > > Why would you?
> >
> > ---
> > This message has been sent through the ALE general discussion list.
> > See http://www.ale.org/mailing-lists.shtml for more info. Problems
> > should be sent to listmaster at ale dot org.


---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.






More information about the Ale mailing list