png-file as a HTTP-Response...

D

David Gösele

Hello,

Im quite stuck with my little project of writting a File-Controller in
ruby.
The actual problem is, that if I stream a png-file to a client
TCP-Socket, the browser is getting the file realy slowly, so that it is
possible to see the file beeing build on the page. It doesn't matter if
I do this on a 100MbBits/s Server or doing it as localhost. I tried many
diffrent ways of writing to the client-socket: syswrite, puts, write and
all with 1024 buffer or without any buffer. The result is just the same,
a very slow answer.
I am not a ruby-expert and probably it is just a misstake of my own, but
I hope you will help me with this, because I am realy stuck...

thanks...

Attachments:
http://www.ruby-forum.com/attachment/4333/test.rb
 
A

Albert Schlef

Robert said:
the browser is getting the file realy slowly
[...]

server = Thread.start {
while (cl = serverSocket.accept)
[...]
end
}
while (true)
true
end

This "while true; end" is known as a "busy loop" (google for this term)
and is not CPU-friendly. Perhaps it steals CPU cycles form your working
thread.

Remove this busy loop and the "server = Thread.start" line and have only
this:

while (cl = serverSocket.accept)
[...]
end

and see if it solves the problem.
 
B

Brian Candler

Albert said:
server = Thread.start {
while (cl = serverSocket.accept)
[...]
end
}
while (true)
true
end

This "while true; end" is known as a "busy loop" (google for this term)
and is not CPU-friendly. Perhaps it steals CPU cycles form your working
thread.

you can just replace it with:

server.join
 

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

Forum statistics

Threads
473,998
Messages
2,570,242
Members
46,834
Latest member
vina0631

Latest Threads

Top