Two issues with webrick - both threading & OS related

So, how about it, list, which ruby

build for win32 should he be using?

cygwin or mscv or something else?

OK - now it gets interesting... on LINUX this time:
ryan@deuce:~$ uname
-a
Linux deuce.dlugosz.net 2.4.20-20.7smp #1 SMP Mon Aug 18 14:46:14 EDT
2003 i686 unknown

ruby info:
URL: http://deuce.dlugosz.net:12306
[2004-08-31
17:23:09] INFO WEBrick 1.3.1
[2004-08-31 17:23:09] INFO ruby 1.8.1 (2003-12-25)
[i686-linux]

I get the *same* blocked request problem!

And finally,
on a second *completely separate* linux box (with the same ruby & webrick
versoins):
Linux vps.dlugosz.net 2.4.20-021stab022.3.777-enterprise #1 SMP
Wed Aug 4 19:02:12 MSD 2004 i686 i686 i386 GNU/Linux

I *still* get the
blocking issue. At this point I'm either running into a webrick bug or I've
got a fundamental flaw in the script. I'll post it at end againso that you
can look at precisely what I'm doing...

Also his second problem is about

select() on win32 does not operate on

the return of pipe().

That makes
sense - I'm not using the cygwin version, but rather the one-click installer.
The IO stuff claims that it's not supported on all platforms so perhaps this
is the expected result?

Thanks for your help!
-Ryan

THE CODE:
require
'webrick'
include WEBrick

class SleepServer < HTTPServlet::AbstractServlet

  def do_GET(req,resp)
    resp.body="Start: #{Time.new}\n"
    sleep(10)

    resp.body << "End: #{Time.new}\n"
    resp['content-type'] = 'text/plain'

  end
end

class GreetServer < HTTPServlet::AbstractServlet
  def do_GET(req,
resp)
    resp.body="Hi, now is: #{Time.new}\n"
    resp['content-type']='text/plain'

  end
end

default_port = (12301 + (Dir.pwd.hash % 1000)).to_s

$port
= (ARGV[0] || default_port).to_i
puts "URL: http://#{Socket.gethostname}:#$port"

$s = HTTPServer.new(
  :Port => $port,
  :DocumentRoot
=> Dir::pwd
)

p $s[:MaxClients]

$s.mount('/sleep', SleepServer)
$s.mount('/greet',
GreetServer)
trap("INT"){ $s.shutdown }
$s.start

···

--- ruby-talk@ruby-lang.org wrote:

For what it's worth, I took the script you posted and ran it on my linux box, and it worked. I requested /sleep, and while it was sleeping I requested /greet, and it sent me /greet right away.

$ uname -a
Linux serling 2.6.7-gentoo-r6 #1 Wed Jun 30 12:38:35 MDT 2004 i686 Intel(R) Pentium(R) M processor 1600MHz GenuineIntel GNU/Linux

$ ruby -v
ruby 1.8.2 (2004-07-29) [i686-linux]

Perhaps it is something with 1.8.1?

- Jamis

···

rdlugosz.1044583@bloglines.com wrote:

--- ruby-talk@ruby-lang.org wrote:

So, how about it, list, which ruby

build for win32 should he be using?

cygwin or mscv or something else?

OK - now it gets interesting... on LINUX this time:
ryan@deuce:~$ uname
-a
Linux deuce.dlugosz.net 2.4.20-20.7smp #1 SMP Mon Aug 18 14:46:14 EDT
2003 i686 unknown

ruby info:
URL: http://deuce.dlugosz.net:12306
[2004-08-31
17:23:09] INFO WEBrick 1.3.1
[2004-08-31 17:23:09] INFO ruby 1.8.1 (2003-12-25)
[i686-linux]

I get the *same* blocked request problem!

And finally,
on a second *completely separate* linux box (with the same ruby & webrick
versoins):
Linux vps.dlugosz.net 2.4.20-021stab022.3.777-enterprise #1 SMP
Wed Aug 4 19:02:12 MSD 2004 i686 i686 i386 GNU/Linux

I *still* get the
blocking issue. At this point I'm either running into a webrick bug or I've
got a fundamental flaw in the script. I'll post it at end againso that you
can look at precisely what I'm doing...

Also his second problem is about

select() on win32 does not operate on

the return of pipe().

That makes
sense - I'm not using the cygwin version, but rather the one-click installer.
The IO stuff claims that it's not supported on all platforms so perhaps this
is the expected result?

Thanks for your help!
-Ryan

THE CODE:
require
'webrick'
include WEBrick

class SleepServer < HTTPServlet::AbstractServlet

  def do_GET(req,resp)
    resp.body="Start: #{Time.new}\n"
    sleep(10)

    resp.body << "End: #{Time.new}\n"
    resp['content-type'] = 'text/plain'

  end
end

class GreetServer < HTTPServlet::AbstractServlet
  def do_GET(req,
resp)
    resp.body="Hi, now is: #{Time.new}\n"
    resp['content-type']='text/plain'

  end
end

default_port = (12301 + (Dir.pwd.hash % 1000)).to_s

$port
= (ARGV[0] || default_port).to_i
puts "URL: http://#{Socket.gethostname}:#$port"

$s = HTTPServer.new(
  :Port => $port,
  :DocumentRoot => Dir::pwd
)

p $s[:MaxClients]

$s.mount('/sleep', SleepServer)
$s.mount('/greet',
GreetServer)
trap("INT"){ $s.shutdown }
$s.start

.

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."

Jamis Buck <jgb3@email.byu.edu> writes:

Perhaps it is something with 1.8.1?

No, it isn't. My ruby is 1.8.1, as shown in earlier posts.

Looks like this problem is person-specific (is there such a
thing?). Is your ruby on linux compiled from scratch or from your
distro? If it is from distro, which distro do you have? And *donning
flame suit* if your distro is redhat, try compiling ruby from source.

YS.

Jamis Buck wrote:

For what it's worth, I took the script you posted and ran it on my linux box, and it worked. I requested /sleep, and while it was sleeping I requested /greet, and it sent me /greet right away.

Actually, that works on all the platforms I've tried.

What doesn't work (on some platforms) is requesting a /sleep while another /sleep is in progress. The second sleep will block, waiting for the first.

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Jim Weirich wrote:

What doesn't work (on some platforms) is requesting a /sleep while another /sleep is in progress. The second sleep will block, waiting for the first.

Odd ... Ryan and I tried this at work on several machines and the second request blocked until the first was done. _One_ of those machines was my Linux laptop.

I just tried this at home on my desktop and laptop, and the second request is no longer blocking. Perhaps there is some subtle difference in the code I'm using now (posted by Ryan a few messages back in this thread) and the code I used yesterday at work.

Or I'm going crazy.

(Or both, but I'm not considering that possibility yet).

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Jim Weirich wrote:

Jamis Buck wrote:

For what it's worth, I took the script you posted and ran it on my linux box, and it worked. I requested /sleep, and while it was sleeping I requested /greet, and it sent me /greet right away.

Actually, that works on all the platforms I've tried.

What doesn't work (on some platforms) is requesting a /sleep while another /sleep is in progress. The second sleep will block, waiting for the first.

Ah, I see. I misunderstood. However, I just tried the scenario you described and it seemed to work fine as well. The second sleep was started a few seconds after the first, and ended just a few seconds after the first.

···

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."

Jim Weirich wrote:

Odd ... Ryan and I tried this at work [...]

I just tried this at home on my desktop and laptop, [...]

Ok, this looks like its not a webrick issue at all. When using wget in separate windows to get the /sleep page, there is no conflict. Both wget's return 10 seconds after hitting carriage return.

When using firefox and loading the /sleep page in two different tabs, the second tab doesn't start its 10 second count until the first window completes. If you change the second window to use an alias for the host name (e.g. localhost instead of the DNS name), then both tabs complete in 10 seconds.

So it is firefox that is not sending the second request until the first is complete, but only when the request is going to the same URL.

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Use tcpflow or tcpdump to see what's going on. I suspect that Firefox
is using a single HTTP/1.1 persistent connection for requests to that
server, even across different tabs. Thus, the second page will be sent
will arrive immedately after the first has finished arriving.

cjs

···

On Wed, 1 Sep 2004, Jim Weirich wrote:

When using firefox and loading the /sleep page in two different tabs,
the second tab doesn't start its 10 second count until the first window
completes. If you change the second window to use an alias for the host
name (e.g. localhost instead of the DNS name), then both tabs complete
in 10 seconds.

--
Curt Sampson <cjs@cynic.net> +81 90 7737 2974 http://www.NetBSD.org
    Don't you know, in this new Dark Age, we're all light. --XTC