Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > png-file as a HTTP-Response...

Reply
Thread Tools

png-file as a HTTP-Response...

 
 
David Gösele
Guest
Posts: n/a
 
      12-21-2009
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Albert Schlef
Guest
Posts: n/a
 
      12-24-2009
Robert Murmel wrote:
> 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.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      12-25-2009
Albert Schlef wrote:
>> 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
--
Posted via http://www.ruby-forum.com/.

 
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




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57