-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
At the moment, HTTPServerResponseImpl::sendFile uses StreamCopied::copyStream which in turn uses intermediate buffer copies. This is inefficient on Linux as the buffers are copied from user space to user space and again from user space to kernel space.
poco/Net/src/HTTPServerResponseImpl.cpp
Line 131 in 3fc3e5f
| StreamCopier::copyStream(istr, *_pStream); |
poco/Foundation/src/StreamCopier.cpp
Line 36 in 3fc3e5f
| istr.read(buffer.begin(), bufferSize); |
As the size of the file increases this will become evident as the kernel buffer cache will get filled up pretty quickly and we have to resort to running
$ free -m
total used free shared buff/cache available
Mem: 32115 1859 12880 1 17374 29812
Swap: 3935 167 3768
$ echo 3 | sudo tee /proc/sys/vm/drop_caches
3
$ free -m
total used free shared buff/cache available
Mem: 32115 1866 29841 1 407 29816
Swap: 3935 167 3768
Linux has sendfile system call. This can be used to speed up the sends and also minimize the memory usage of the process and in turn reduce the kernel buffer cache.