Chip Multi-threading and the future

S

Stephen Kellett

Hi Folks,

Here is an article which is not about Ruby, but is about the future of
computing (re multi-threading and chip multi-threading).

http://www.tbray.org/ongoing/When/200x/2005/06/12/Threads

I post this simply because Ruby's support for multi-threading is poor.
If there is one area that needs improvement its multi-threading. When
you read that article its even more apparent that Ruby needs improving
on that front.

Finally at the end he asks "How many threads is enough?". Well for a C++
Thread analysis program I manage, we have many users analyzing in excess
of 64 threads and one up to 600+ threads in a real world situation. No
stats for the Java, Python and Ruby ones though :-(

Anyway, hope you find the article interesting.

Stephen
 
L

Lothar Scholz

Hello Stephen,

SK> Hi Folks,

SK> Here is an article which is not about Ruby, but is about the future of
SK> computing (re multi-threading and chip multi-threading).

SK> http://www.tbray.org/ongoing/When/200x/2005/06/12/Threads

SK> I post this simply because Ruby's support for multi-threading is poor.
SK> If there is one area that needs improvement its multi-threading. When
SK> you read that article its even more apparent that Ruby needs improving
SK> on that front.

Correct. But look at "eval.c" and you know why we need a complete
reimplementation of ruby, there is absolutely no way to add this to
the existing code base. And when i hear Matz comments that YARV will
be integrated into eval.c this winter, then i doubt multi-threading
will be done right.

One problem we share with the python community :)
They also need a complete python rewrite to handle more then one
thread at a time.

Another solution:

The problem could be easily solved if th OS producer will implement better
thread local store implementation. When a thread local variable has
the same speed as a global one we simply need to fix a few declarations.

And such a thread local store is easy to implement, just switch a few
memory pages inside the MMU when switching threads. Allmost zero
overhead and just a few lines in the thread scheduler. Of course there
must also some linker functionality in the program loader.

I think that this will come much earlier then a rewrite. I hope for
Longhorn as this will be also important for Microsoft.
 
E

Eric Hodel

Hi Folks,

Here is an article which is not about Ruby, but is about the future
of computing (re multi-threading and chip multi-threading).

http://www.tbray.org/ongoing/When/200x/2005/06/12/Threads

I post this simply because Ruby's support for multi-threading is
poor. If there is one area that needs improvement its multi-
threading. When you read that article its even more apparent that
Ruby needs improving on that front.

For web serving, Rails has primarily uses FastCGI, which is a multi-
process model.

43 Things runs our site off of a 2 CPU box with HT enabled, so we get
4 CPUs. The multi-process model works great for this, you don't have
to worry about threads here because of the way Rails is designed.
You do, however, have to worry about memory.

(It would be nice if you could fork(2) a live Rails process so it
wasted less memory, but I think you would loose the benefits of
memory savings the first time the GC runs. Doug Beaver had a nice
presentation about this at the last Seattle.rb meeting, where he
proposed building a separate tree for GC marking...)

But then I need to process the web server's logs, which involves DNS
lookups. This is acceptable but not-so-great because I'm using ruby
threads for that, and that probably chews up more CPU than needed
switching between the 100 threads.

(For reference, 1 worker thread takes about 5 hours, 20 cuts that to
3, and 100 cuts that to 40-50 minutes for files in the 750,000 to
500,000 line range.)

I could rewrite it to be multi-process instead of multi-threading,
but then the code loses its simplicity. I could also rewrite it to
spawn new threads up to N when threads are blocking, but then, again,
I lose simplicity.
Finally at the end he asks "How many threads is enough?". Well for
a C++ Thread analysis program I manage, we have many users
analyzing in excess of 64 threads and one up to 600+ threads in a
real world situation. No stats for the Java, Python and Ruby ones
though :-(

So we run 30 FastCGI processes for web serving and 100 ruby threads
for DNS lookup, just for reference.
 
E

Eric Hodel

Hello Stephen,

SK> Hi Folks,

SK> Here is an article which is not about Ruby, but is about the
future of
SK> computing (re multi-threading and chip multi-threading).

SK> http://www.tbray.org/ongoing/When/200x/2005/06/12/Threads

SK> I post this simply because Ruby's support for multi-threading
is poor.
SK> If there is one area that needs improvement its multi-
threading. When
SK> you read that article its even more apparent that Ruby needs
improving
SK> on that front.

Correct. But look at "eval.c" and you know why we need a complete
reimplementation of ruby, there is absolutely no way to add this to
the existing code base. And when i hear Matz comments that YARV will
be integrated into eval.c this winter, then i doubt multi-threading
will be done right.

It was my impression that the current eval.c will be replaced
completely with YARV so that nobody has to worry about cutting out
the globals currently in eval.c.
 
G

gabriele renzi

Martin Ankerl ha scritto:
The article mentions Erlang just very briefly. Erlang is especially
designed for concurrency, and allows a lot of simultanuous processes. I
think concurrent design like this will be the future.

but erlang processes are not processes in the OS sense, AFAIR.
Anyway, probably worth investigating :)


FWIW, just loosely related, I'd like to have some kind of "Worker"
concept that could be mapped over green threads, os thread, processes
and whatever based on a common interface. I guess how hard would it be.
 
G

gabriele renzi

Stephen Kellett ha scritto:
Hi Folks,

Here is an article which is not about Ruby, but is about the future of
computing (re multi-threading and chip multi-threading).

http://www.tbray.org/ongoing/When/200x/2005/06/12/Threads

Ah, I think a thing is fun to note: it seem that our dear koichi
sasada is quite involved in cpu-based threading[1], and other parallel
stuff[2]


[1] http://www.atdot.net/yarv/RubyConf2004_YARV_pub.pdf, see slide6
[2] http://www.namikilab.tuat.ac.jp/~sasada/publication.html
 
T

Thomas Hurst

* Eric Hodel ([email protected]) said:
For web serving, Rails has primarily uses FastCGI, which is a multi-
process model.

No, FastCGI is a client-server model. A threaded server would be very
nice, although I'm not sure if mod_fastcgi's process manager's aware of
the possibility. Certainly as an external server a threaded app server
would behave identically to a multi-process one, since it's just bog
standard socket ops.
43 Things runs our site off of a 2 CPU box with HT enabled, so we get
4 CPUs. The multi-process model works great for this, you don't have
to worry about threads here because of the way Rails is designed.

I don't think Rails does anything special here? As far as FastCGI goes
it works just like any other FastCGI Ruby app.
You do, however, have to worry about memory.

(It would be nice if you could fork(2) a live Rails process so it
wasted less memory, but I think you would loose the benefits of
memory savings the first time the GC runs.

You should be able to; I've been planning on adding support for external
servers and enabling libfcgi's preforking stuff in the C extension for
quite a while. If nothing else you gain proper external server support,
and beyond that there will likely be a lot of sharing with parse trees
and initial data structures.
But then I need to process the web server's logs, which involves DNS
lookups. This is acceptable but not-so-great because I'm using ruby
threads for that, and that probably chews up more CPU than needed
switching between the 100 threads.

Are there no async DNS libraries for Ruby about? Seems a bit overkill
to use a thread just for a DNS lookup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top