kernelsauce/turbo — pull request #60 by kernelsauce (2013-08-04 14:26:09+00:00)
Title: IOStream deque -> low-level buffers + offset.

On big transfers the deque implementation used in the IOStream classes were slow and also caused a lot of temporaries. This is now replaced with real buffers and offsets. The API remains the same except for the addition of IOStream:write_buffer and IOStream:write_zero_copy which enables the API user to write the new 'turbo.structs.buffer' class directly, which avoids conversion from C style char* to Lua interned string. Zero copy writes means the buffer is not copied and is treated as a constant.

The new turbo.structs.buffer class offers a mutable bytearray implementation with reasonable safety. The user may shoot himself in the foot by abusing the returned pointers if that is what he wants.

The turbo.web.StaticFileHandler has been rewritten to use the zero-copy feature and throughput has now been increased from 2Gbit/s to 20Gbit/s on my Lenovo W510, on transferring a 1MB .jpg file using Apache benchmark with keep alive option. The memory usage has obviously also dropped dramatically as the file contents is not copied to each streams internal deque.