Win32 service question

Hi All,

First, I’m new to the list, so I’d like to say hello to all fellow
mongrelists :slight_smile:

Second, I’d like to ask you if there’s any way to make a simple mongrel
script run multithreaded?

No rails, just plain old

class MyHandler < Mongrel::HttpHandler
.
.
.
h = Mongrel::HttpServer.new(“127.0.0.1”, “80”)

stuff.

Since win32 lacks fork, I don’t know if I can make it process multiple
request simultaneously.
I’ve read about the mongrel rails service thing, but that’s only for
rails,
if I’m not mistaken.

Thank you in advance,
Ochronus

Csaba: You can run anything multithreaded on Windows by using Ruby
Threads. These are green threads, not native ones, and they are
non-blocking, which is what you would want. Look up some examples of
using the Thread class, which is in the Ruby language core, and you
should be on your way. You can create them in a loop and get many
running. I am new to Ruby, otherwise I would give you a concrete
example.

Csaba: You can run anything multithreaded on Windows by using Ruby
Threads.

Second, I’d like to ask you if there’s any way to make a simple mongrel
script run multithreaded?

you get threaded handlers for free, by default. you have to explicitly
go out of your way to defeat this behavior… grep -i mutex in the rails
or camping handler to see how its done

Since win32 lacks fork, I don’t know if I can make it process multiple
request simultaneously.

fork() is implemented in win32/process extension. not that youd want to
use that, or anything,

i tried it once in a real-world script that would fork itself and spawn
gcc children and it was very weird, to say the least (lots of return
values were just corrupt garbled crap). compounded by running mingw’s
bash where things are wonky already.

but this doesnt matter, since mongrel’s ruby isnt actually forking,
apache-style, to enable concurrency…

if youre further curious, check out wyhaines’ evented mongrel

On Nov 21, 2007 4:49 AM, Csaba O. [email protected] wrote:

Thank you both, Geoffrey and cdr for your help.
I didn’t know it was threaded on win32 by default :slight_smile:

Then I don’t really get why there’s so big performance difference bw/ a unix
backed mongrel
and a win32 one…

The current (official) build of ruby on windows is compiled with a
older, not-so-optimized compiler (Visual C 6.0). It is 30% slower than
the same code compiled with GCC 3.4.5 (or 4.2.1).

Future versions of ruby for windows will provide updated builds, we
are working on that :slight_smile:


Luis L.
Multimedia systems

Leaders are made, they are not born. They are made by hard effort,
which is the price which all of us must pay to achieve any goal that
is worthwhile.
Vince Lombardi

Thank you both, Geoffrey and cdr for your help.
I didn’t know it was threaded on win32 by default :slight_smile:

Then I don’t really get why there’s so big performance difference bw/ a
unix
backed mongrel
and a win32 one…