# Directio sendfile aio

**URL:** <https://www.ruby-forum.com/t/directio-sendfile-aio/243888>\
**Category:** NGINX\
**Created:** [January 22, 2016, 10:08am UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888 "2016-01-22T10:08:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [January 22, 2016, 10:08am UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888/1 "2016-01-22T10:08:42Z")

</div>

From an nginx book i read setting

###########  
http {

sendfile on;  
sendfile\_max\_chunk 512k;  
aio threads=default;  
directio 4m;  
############

is good as it use (if i understand it correctly)

sendfile for files less than 4m and directio for files larger than 4m

But the above config is causing issues like static css files images etc  
not  
being served. I am not sure what exactly is the issue But commenting out

directio from the above fix it or commenting out sendfile fix it .

But adding them both creates a mess.

The question is is the above combination valid and if yes what might be  
causing the issue .

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [January 22, 2016, 10:54am UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888/2 "2016-01-22T10:54:16Z")

</div>

## You did not provide any configuration snippet for the thread pool you are using and only showing partial configuration bits. I hope the unshown is configured properly…

_B. R._

On Fri, Jan 22, 2016 at 10:08 AM, Anoop A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [January 22, 2016, 11:06am UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888/3 "2016-01-22T11:06:32Z")

</div>

On Friday 22 January 2016 14:38:13 Anoop A. wrote:

> From an nginx book i read setting

What’s the name of the book?

> ###########  
> http {
> 
> sendfile on;  
> sendfile\_max\_chunk 512k;  
> aio threads=default;  
> directio 4m;  
> ############
> 
> is good as it use (if i understand it correctly)

In some specific use case scenarios these settings can be good.

> The question is is the above combination valid and if yes what might be  
> causing the issue .

Could you provide the full configuration and a debug log  
(see [A debugging log](http://nginx.org/en/docs/debugging_log.html))?

I’m unable to reproduce any issues on a simple configuration  
example with the settings above.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [January 22, 2016, 12:28pm UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888/4 "2016-01-22T12:28:20Z")

</div>

On Friday 22 January 2016 16:30:38 Anoop A. wrote:

> So the setting
> 
> sendfile on;  
> sendfile\_max\_chunk 512k;  
> aio threads=iopool; #thread\_pool iopool is defined in the main context  
> directio 4m;
> 
> is good ?

[..]

I wouldn’t recommend these settings for everyone. Actually there  
are no settings that work for everyone and that’s the reason why  
these directives exist and tunable.

Direct IO is questionable if you aren’t serving gigabytes of movies.  
You don’t need direct IO and aio if your working data set is less  
than the amount of RAM.

“sendfile\_max\_chunk 512k” with “directio 4m” looks surplus.

Actually the default settings usually work well. So in general it’s  
not a good idea to tune anything unless you’re experiencing problems  
and fully understand what you’re going to change and why. Also you  
need some metrics and/or benchmarks to test your settings, blind  
tuning can make the result worse.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [January 22, 2016, 12:00pm UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888/5 "2016-01-22T12:00:52Z")

</div>

I think the weird issue I mentioned had something to do with  
ngx\_pagespeed  
with a memcached backed and memcached was not running . It is working  
fine  
with memcached now running .

Somehow the sendfile and directio setting was affecting that. as I  
mentioned the issue fixed with enabling either sendfile and directio on  
with memcached not running (I think pagespeed falls back to a file based  
cache if memcached is not running) .

Right now with

sendfile on;  
sendfile\_max\_chunk 512k;  
aio threads=iopool;  
directio 4m;

and memcached running ;I dont see any issues .

if memcached is not running (used by pagespeed) and the above setting  
produce weird errors that goes away if directio and sendfile is used in  
a  
mutually exclusive fashion.

#########  
the book is NGINX High Performance  
By Rahul S.

You can check the exact section in page #53 available in google books as  
a  
sample.  
#########

So the setting

sendfile on;  
sendfile\_max\_chunk 512k;  
aio threads=iopool; #thread\_pool iopool is defined in the main context  
directio 4m;

is good ?

On Fri, Jan 22, 2016 at 3:35 PM, Valentin V. Bartenev [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [January 22, 2016, 1:14pm UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888/6 "2016-01-22T13:14:29Z")

</div>

On Friday 22 January 2016 17:25:42 Anoop A. wrote:

> aio threads=default;  
> directio 100m;

[..]

Something like this can work better, since it reduces usage of Direct IO  
only for reading really quite big files.

But a possible side effect of this setting will be slowdown of serving  
such files.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [January 22, 2016, 12:56pm UTC](https://www.ruby-forum.com/t/directio-sendfile-aio/243888/7 "2016-01-22T12:56:23Z")

</div>

My use case is mixed mass hosting environment where some vhost may be  
serving large files and some may be serving small files and where adding  
something like location /video with directio enabled is not practical as  
I  
being the webhost may not be knowing if the vhost user is serving a  
video  
etc .

In such cases …do you recommend using something like

sendfile on;  
sendfile\_max\_chunk 512k;  
aio threads=default;  
directio 100m;

in the http context . The logic being

file served of size 100m or less use sendfile and anything larger than  
100m  
( in which case it may have a high chance of being a multimedia file) is  
served via directio .

Part of these setting are derived from what I understood is good from

> **[Boosting NGINX Performance 9x with Thread Pools](https://www.nginx.com/blog/thread-pools-boost-performance-9x/)**
>
> Learn how the thread pool in NGINX 1.7.11 and NGINX Plus R7 boosts performance up to 9 times by offloading blocking operations from the worker process
