Hello, we are sending image files using EventMachine and for some reason the image files take significantly longer to send than their text counterparts. We are using send_data(File.read). Does anybody else have this issue? Does ruby handle binary data inefficiently? Thanks, Brian
On Wed, Aug 27, 2008 at 7:05 PM, Brian Takita <brian.takita at gmail.com>wrote:> Hello, we are sending image files using EventMachine and for some > reason the image files take significantly longer to send than their > text counterparts. > We are using send_data(File.read).Well, the problem you''re going to run into is that you''re first reading the entire file into memory in a single buffer, then EventMachine is building its own buffer of data to write to the connection. I believe there''s some fast file streaming stuff for EventMachine available -- Tony Arcieri medioh.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080827/8d854f79/attachment.html>
Try send_file_data instead: http://github.com/eventmachine/eventmachine/tree/master/lib/eventmachine.rb#L1550-1557 Aman On Wed, Aug 27, 2008 at 6:15 PM, Tony Arcieri <tony at medioh.com> wrote:> On Wed, Aug 27, 2008 at 7:05 PM, Brian Takita <brian.takita at gmail.com>wrote: > >> Hello, we are sending image files using EventMachine and for some >> reason the image files take significantly longer to send than their >> text counterparts. >> We are using send_data(File.read). > > > Well, the problem you''re going to run into is that you''re first reading the > entire file into memory in a single buffer, then EventMachine is building > its own buffer of data to write to the connection. > > I believe there''s some fast file streaming stuff for EventMachine available > > -- > Tony Arcieri > medioh.com > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080828/646f6eee/attachment.html>
On Wed, Aug 27, 2008 at 7:15 PM, Tony Arcieri <tony at medioh.com> wrote:> On Wed, Aug 27, 2008 at 7:05 PM, Brian Takita <brian.takita at gmail.com>wrote: >> Well, the problem you''re going to run into is that you''re first reading the > entire file into memory in a single buffer, then EventMachine is building > its own buffer of data to write to the connection. > > I believe there''s some fast file streaming stuff for EventMachine available >Brian, if you are smaller files, use send_file_data. Smaller is somewhat variable, but probably sits between 16k and 32k. If you are sending larger files, use stream_file_data. You should be able to get high transfer rates with these methods. Kirk Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080828/3c42fefa/attachment.html>