# Help with AIO

**URL:** <https://www.ruby-forum.com/t/help-with-aio/211502>\
**Category:** NGINX\
**Created:** [September 6, 2011, 12:22am UTC](https://www.ruby-forum.com/t/help-with-aio/211502 "2011-09-06T00:22:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 6, 2011, 12:22am UTC](https://www.ruby-forum.com/t/help-with-aio/211502/1 "2011-09-06T00:22:15Z")

</div>

Hi

I configured Nginx with \*aio \*mode \*on \*and 1 _worker process_  
In benchmarking I saw limit of 1024 concurrent sessions even configured  
to  
4096 _worker connections_  
When I looked in the source code I could see that io\_setup is called  
with  
fix value of 1024 max events  
can anyone please explain me the hard coded limit  
Is it OK to change it or it is derived from other limit I am not aware  
of  
any help will be appreciated

thanks  
Hagai

–

_Hagai A._  
Qwilt | Work: +972-72-2221644| Mobile: +972-54-4895656 |  
removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [September 6, 2011, 9:34am UTC](https://www.ruby-forum.com/t/help-with-aio/211502/2 "2011-09-06T09:34:14Z")

</div>

Hello!

On Tue, Sep 06, 2011 at 01:21:00AM +0300, Hagai A. wrote:

> Hi
> 
> I configured Nginx with \*aio \*mode \*on \*and 1 _worker process_  
> In benchmarking I saw limit of 1024 concurrent sessions even configured to  
> 4096 _worker connections_

Sure it’s not limitation of the benchmarking tool you use? Most  
tools out there use select() and hence limited to 1024  
concurrent connections.

> When I looked in the source code I could see that io\_setup is called with  
> fix value of 1024 max events  
> can anyone please explain me the hard coded limit  
> Is it OK to change it or it is derived from other limit I am not aware of  
> any help will be appreciated

io\_setup() maxevents is a limit on number of aio requests allowed  
to be submitted simulteneously; if nginx hits this limit, it will  
fallback to normal blocking read.

If you are going to change it, make sure to keep total for all  
processes lower than /proc/sys/fs/aio-max-nr.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [September 6, 2011, 9:47am UTC](https://www.ruby-forum.com/t/help-with-aio/211502/3 "2011-09-06T09:47:50Z")

</div>

Thanks a lot  
I will try it

On Tue, Sep 6, 2011 at 9:33 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

_Hagai A._  
Qwilt | Work: +972-72-2221644| Mobile: +972-54-4895656 |  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [September 15, 2011, 4:22pm UTC](https://www.ruby-forum.com/t/help-with-aio/211502/4 "2011-09-15T16:22:38Z")

</div>

Hi

## When benchmarking AIO read, I reached more than 1024 concurrent Async IO

1. I saw a weird error log
2. Nginx did not fallback to regular blocking read

I looked on the source code – src/os/unix/ngx\_linux\_aio\_read.c  
line:105  
and I think there is a problem in errno handling

// Current Code  
//----------------------------------------------------------------------------  
\*n = io\_submit(ngx\_aio\_ctx, 1, piocb);

```
if (n == 1) {
    ev->active = 1;
    ev->ready = 0;
    ev->complete = 0;

    return NGX_AGAIN;
}

n = -n; 

```

\<---------------------------------------------------------??

```
if (n == NGX_EAGAIN) {
    return ngx_read_file(file, buf, size, offset);
}

ngx_log_error(NGX_LOG_CRIT, file->log, n,
              "io_submit(\"%V\") failed", &file->name);

if (n == NGX_ENOSYS) {
    ngx_file_aio = 0;
    return ngx_read_file(file, buf, size, offset);
}

return NGX_ERROR;*

```

// I think it should be  
//----------------------------------------------------------------------------  
\*n = io\_submit(ngx\_aio\_ctx, 1, piocb);

```
if (n == 1) {
    ev->active = 1;
    ev->ready = 0;
    ev->complete = 0;

    return NGX_AGAIN;
}

if (n == 0)
{
    ngx_log_error(NGX_LOG_CRIT, file->log, 0,
              "io_submit(\"%V\") failed - 0 - I/O request blocks",

```

&file-\>name);

```
    return NGX_ERROR;
}
else
{
    n = errno;
}

```

- 
  - if (n== NGX\_EAGAIN) {  
return ngx\_read\_file(file, buf, size, offset);  
}

ngx\_log\_error(NGX\_LOG\_CRIT, file-\>log, n,  
“io\_submit("%V") failed”, &file-\>name);

if (n== NGX\_ENOSYS) {  
ngx\_file\_aio = 0;  
return ngx\_read\_file(file, buf, size, offset);  
}

return NGX\_ERROR;\*  
//----------------------------------------------------------------------------

your help will be appreciated  
Thanks  
Hagai

On Tue, Sep 6, 2011 at 9:33 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

_Hagai A._  
Qwilt | Work: +972-72-2221644| Mobile: +972-54-4895656 |  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [September 16, 2011, 12:39pm UTC](https://www.ruby-forum.com/t/help-with-aio/211502/5 "2011-09-16T12:39:22Z")

</div>

On Thu, Sep 15, 2011 at 04:21:44PM +0200, Hagai A. wrote:

> //----------------------------------------------------------------------------  
> n = -n; \<---------------------------------------------------------??  
> Thank you, this is a bug. I confused this with \_syscall(2).

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [September 17, 2011, 12:59pm UTC](https://www.ruby-forum.com/t/help-with-aio/211502/6 "2011-09-17T12:59:20Z")

</div>

On Fri, Sep 16, 2011 at 06:10:02PM +0400, Igor S. wrote:

> > > ```
> > > }
> > > 
> > > ```
> 
> Also I’m going to introduce the directive:
> 
> events {  
> worker\_aio\_events 100;  
> }
> 
> to set how much aio events worker may request to the kernel.  
> I’m going to set default value to 32 events per worker.  
> Currenly this value is hardcoded to 1024 and it seems it is too large,  
> since default /proc/sys/fs/aio-max-nr value is 65536 and this means  
> that you can run no more than 64 workers.

I think it should be renamed to

events {  
worker\_aio\_requests 100;  
}

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Hagai\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9a28c/32.png) [@Hagai\_A](https://www.ruby-forum.com/u/Hagai_A)\
**Post date:** [September 16, 2011, 4:10pm UTC](https://www.ruby-forum.com/t/help-with-aio/211502/7 "2011-09-16T16:10:51Z")

</div>

On Fri, Sep 16, 2011 at 02:39:07PM +0400, Igor S. wrote:

> > // Current Code
> > 
> > ```
> > n = -n; <---------------------------------------------------------??
> > 
> > ```
> 
> Thank you, this is a bug. I confused this with \_syscall(2).

Linux AIO fixed in these two commits:

[http://trac.nginx.org/nginx/changeset/4130/nginx](http://trac.nginx.org/nginx/changeset/4130/nginx)  
[http://trac.nginx.org/nginx/changeset/4131/nginx](http://trac.nginx.org/nginx/changeset/4131/nginx)

Also I’m going to introduce the directive:

events {  
worker\_aio\_events 100;  
}

to set how much aio events worker may request to the kernel.  
I’m going to set default value to 32 events per worker.  
Currenly this value is hardcoded to 1024 and it seems it is too large,  
since default /proc/sys/fs/aio-max-nr value is 65536 and this means  
that you can run no more than 64 workers.

–  
Igor S.
