Use posix_fadvise() to hint the OS when streaming raw file

Hinting the OS about our behaviour shouldn't make a big difference in
performance but it will help the OS manage its disk cache and can reduce
memory pressure on small systems.
This commit is contained in:
Julien BLACHE 2010-02-02 20:59:46 +01:00
parent 7047126f51
commit 1df7ec1b7c
2 changed files with 11 additions and 0 deletions

View File

@ -34,6 +34,7 @@ AC_CHECK_HEADERS([sys/wait.h])
AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([sys/select.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_FUNCS(posix_fadvise)
AC_CHECK_FUNCS(strptime)
AC_CHECK_FUNCS(strtok_r)
AC_CHECK_FUNCS(timegm)

View File

@ -577,6 +577,16 @@ httpd_stream_file(struct evhttp_request *req, int id)
evhttp_send_reply_start(req, 206, "Partial Content");
}
#ifdef HAVE_POSIX_FADVISE
if (!transcode)
{
/* Hint the OS */
posix_fadvise(st->fd, st->start_offset, st->stream_size, POSIX_FADV_WILLNEED);
posix_fadvise(st->fd, st->start_offset, st->stream_size, POSIX_FADV_SEQUENTIAL);
posix_fadvise(st->fd, st->start_offset, st->stream_size, POSIX_FADV_NOREUSE);
}
#endif
/* This is an extension to the stock evhttp */
req->fail_cb = stream_fail_cb;
req->fail_cb_arg = st;