Two issues with webrick - both threading & OS related

R

rdlugosz.1044583

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
(e-mail address removed)
 
Y

Yohanes Santoso

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.
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top