Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Two issues with webrick - both threading & OS related

Reply
Thread Tools

Two issues with webrick - both threading & OS related

 
 
rdlugosz.1044583@bloglines.com
Guest
Posts: n/a
 
      08-31-2004
All -

I've recently been playing with a simple webrick servlet that will
allow me to build playlists and stream mp3s off of my home system. I've ran
into some very peculiar issues that appear to be thread & OS related. It
seems that on Linux, my program will only handle *one* connection at a time;
i.e. - if your media player is streaming a file, the browser cannot load the
pages to look at other music directories. However, on WinXP I can have several
simultaneous connections to the system & there are no blocking issues.

The media program aside, working with Jim Weirich today we discovered some
other interesting things. A absolutely basic webrick servlet that has a Thread.sleep
in it's do_get will block all access to the servlet on any OS - the blocked
request will execute immediately upon the blocker completing. Here's the
code:
class SleepServer < HTTPServlet::AbstractServlet
def do_GET(req,
res)
sleep(30)
res.body = '<h1>DONE</h1>'
end

def do_POST(req,
res)
do_GET(req, res)
end
end

This seems pretty strange; it's
as if webrick is operating in a "Single thread model" servlet mode. I'm sure
that's not the correct behavior.


Finally, another issue we ran into is
one somehow related to threads and IO and is OS specific. The code below
executes properly on Linux, but appears to deadlock on XP.
class Streamlet
< WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
res["content-type"]
= "text/plain"
reader, writer = IO.pipe
Thread.start{

1000.times{|i|
puts i
writer << "a" * 1000

writer << "\n"
}
writer.close
}
res.body
= reader
end
end

Personally, I think this problem is even more strange,
since Ruby is handling the threads internally it doesn't seem like it should
deadlock on one OS and not the other.

The issue I'm having with my media
player is strange too, since it has problems only on Linux yet our test code
(the sleep(30) servlet) is broken on both platforms...

Sorry for the length
of the email, but I felt the detail was required. I appreciate any suggestions
you may have.

-Ryan
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Yohanes Santoso
Guest
Posts: n/a
 
      08-31-2004
(E-Mail Removed) writes:

> The media program aside, working with Jim Weirich today we discovered some
> other interesting things. A absolutely basic webrick servlet that has a Thread.sleep
> in it's do_get will block all access to the servlet on any OS - the blocked
> request will execute immediately upon the blocker completing. Here's the


Funny, I do not observe that behaviour:

--------------------------------------------------
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

start_webrick {|server|
server.mount('/sleep', SleepServer)
server.mount('/greet', GreetServer)
}
--------------------------------------------------

I then open 3 terminals and run:

Terminal 1:

dede:~$ w3m -dump http://localhost:8080/sleep
Start: Tue Aug 31 06:16:35 PDT 2004
End: Tue Aug 31 06:16:45 PDT 2004

Terminal 2:

dede:~$ w3m -dump http://localhost:8080/sleep
Start: Tue Aug 31 06:16:37 PDT 2004
End: Tue Aug 31 06:16:47 PDT 2004


Terminal 3:

ede:~$ w3m -dump http://localhost:8080/greet
Hi, now is: Tue Aug 31 06:16:39 PDT 2004
dede:~$ w3m -dump http://localhost:8080/greet
Hi, now is: Tue Aug 31 06:16:41 PDT 2004
dede:~$ w3m -dump http://localhost:8080/greet
Hi, now is: Tue Aug 31 06:16:43 PDT 2004
dede:~$ w3m -dump http://localhost:8080/greet
Hi, now is: Tue Aug 31 06:16:50 PDT 2004
dede:~$ ruby -v
ruby 1.8.1 (2004-02-03) [i386-linux]

Notice that while the /sleep in terminal 1 is waiting, another /sleep
call on terminal 2 is issued. And while terminals 1 and 2 are waiting
for the output, multiple /greet calls on terminal 3 can be executed
just fine.

So, I do not observe the blocking phenomenon you observed.

I can't verify your next problem since I don't have access to XP.

YS.


 
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
WEBrick: Has anyone used WEBrick::Session? Lloyd Zusman Ruby 2 02-21-2013 06:49 PM
WEBrick::Daemon and WEBrick Aaron Smith Ruby 2 03-18-2007 03:47 AM
2 computers, both online, both invisible to each other ? b Computer Support 9 04-21-2006 04:06 AM
rails: webrick & lighttp/fcgi threading model didier.prophete@gmail.com Ruby 7 01-11-2006 01:27 PM
Threading help with testing webrick and xmlrpc Luke Kanies Ruby 0 07-22-2005 08:24 PM



Advertisments