[Openmcl-devel] Transfer the contents of a file to a tcp stream

rm at fabula.de rm at fabula.de
Tue May 3 13:17:31 PDT 2005

On Tue, May 03, 2005 at 09:07:26PM +0100, Richard Newman wrote:
> Just a thought -- the calculated speed of a transfer includes the setup 
> and tear-down times for the connection, as far as I can see.
> I don't know how big that file is, but try it with one that's 50MB or 
> more, so that the transfer time becomes more significant. It might be 
> that you're optimising the wrong part of your program.
> Failing that... profile!
> -R

Well, even without the setup/teardown of the this OpenMCL will hardly 
erver reach Apache (BTW, how would teardown affect the measured time?).
When sending _files_ (not content from memory) Apache tries hard to
use a sendfile(2) or  similar techniques (depending on the underlying OS).
When sendfile is used the kernel is instructed to copy (send) a file directly
from one file descriptor to another. First of all, with this trick data
never has to cross the (expensive) border between kernel space and userspace
(as opposed to crossing it twice in the OpenMCL sample code). On a reasonably
smart OS that data might even never pass the kernel but travers via DMA from
disk to network card.
Of course, since OpenMCL has a nice FFI interface it would be trivial to 
call sendfile from it .... but that would be cheatin' :-)

 Cheers Ralf Mattes

More information about the Openmcl-devel mailing list