[Twisted-Python] Serving files, again

Jp Calderone exarkun at intarweb.us
Wed Feb 26 12:50:31 MST 2003


On Wed, Feb 26, 2003 at 07:51:35PM +0000, Clark C. Evans wrote:
> On Wed, Feb 26, 2003 at 07:20:02PM +0000, Clark C. Evans wrote:
> | 
> | I don't know if this is your question; but I'd return the contents
> | of file.txt when the file size is less than a pre-defined size, say 32K.
> | Beyond that, the file should be DEFERRED into a thread which sends
> | the file a chunk at a time.   Further, it'd be cool if I could 
> | specify in the request object if the response should be compressed
> | via gzip.
> 
> Actually, shouldn't it always be deferred?  The file system may
> be writing at the time (via another thread) so doing a file read
> (even for a tiny file) at this point could cause significant lag 
> or am I completely mis-understanding this whole async-stuff?

  We usually consider IO on local fixed disks to be fast enough.  In any
case, select() in POSIX tells you that files are always ready for reading,
so being smarter about it requires using a different mechanism (which is
entirely possible, but requires a different reactor, not to mention platform
support).

  BTW, deferring to a thread would not be the way to go.  Something similar
to twisted.spread.util.Pager would probably be appropriate, or maybe
something that implements IProducer.  Or maybe just a chain of Deferreds :)
No need to go into threads for this, though.

  Jp

-- 
        "I quite agree with you," said the Duchess; "and the moral of
that is -- Be what you would seem to be' -- or, if you'd like it put
more simply -- Never imagine yourself not to be otherwise than what it
might appear to others that what you were or might have been was not 
otherwise than what you had been would have appeared to them to be
otherwise.'"       -- Lewis Carrol, "Alice in Wonderland"
-- 
 up 18 days, 0:29, 5 users, load average: 0.47, 0.28, 0.14
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20030226/424ce591/attachment.sig>


More information about the Twisted-Python mailing list