[Python-Dev] Add sendfile() to core?

Andrew Kuchling akuchlin@mems-exchange.org
Wed, 20 Mar 2002 14:53:58 -0500


The Medusa distribution contains a small module that wraps the
sendfile() system call, available at least on Unix and FreeBSD.  
The man page explains what sendfile() does:

       ssize_t  sendfile(int  out_fd,  int  in_fd, off_t *offset,
       size_t count)

       This call copies data  between  one  file  descriptor  and
       another.   Either  or  both  of these file descriptors may
       refer to a socket (but see below).  in_fd should be a file
       descriptor  opened  for  reading  and  out_fd  should be a
       descriptor opened for writing.  offset is a pointer  to  a
       variable  holding  the  input  file  pointer position from
       which sendfile() will start reading data.  When sendfile()
       returns,  this  variable  will be set to the offset of the
       byte following the last byte that was read.  count is  the
       number of bytes to copy between file descriptors.

       Because this copying is done within the kernel, sendfile()
       does not need to spend time transferring data to and  from
       user space.

sendfile() is used when writing really high-performance Web servers,
in order to save an unnecessary memory-to-memory copy.  Question:
should I make up a patch to add a sendfile() wrapper to Python?

(Personally I think we can live without it.  If you're writing servers
in Python, an interpreted language where creating an integer can end
up calling malloc(), then worrying about the cost of memory-to-memory
copying seems misplaced.  Another strike against it is that it isn't
portable; other Unixes have similar but different calls with different
names.)

--amk                                                             (www.amk.ca)
  "Aww, c'mon! Where's your sense of fun?"
  "I'm the standard model, Zachary. 'Fun' was optional."
    -- Zot and Peabody, in ZOT! #1