# Mail proxy auth\_http stats

**URL:** <https://www.ruby-forum.com/t/mail-proxy-auth-http-stats/198124>\
**Category:** NGINX\
**Created:** [October 26, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/mail-proxy-auth-http-stats/198124 "2010-10-26T19:06:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 26, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/mail-proxy-auth-http-stats/198124/1 "2010-10-26T19:06:10Z")

</div>

Hi,

I have a mail proxy configured alongside the following:

http {  
perl\_modules /etc/nginx/perl/lib;  
perl\_require mailauth.pm; // there’s a Perl::DBI call here

```
    server {
            listen 81;
            location /auth {
                     perl mailauth::handler;
            }
            location /stats {
                     stub_status on;
                     access_log off;
            }

```

}

and my mail proxy uses this server :81/auth for auth\_http

when i curl :81/stats, I always get only 1 in writing:

Active connections: 149  
server accepts handled requests  
4945 4945 2465  
Reading: 0 Writing: 1 Waiting: 148

I initially thought that this was due to some sort of a limitation of  
using the embedded-perl interpretor of nginx and so i removed this  
logic out and served it out of a different nginx+thin+rackup script  
(an ActiveRecord call) which implemented the same redirection logic i  
had wired in earlier in mailauth.pm.

So now I have one instance of nginx on server A acting solely as a  
mail proxy and another on server B serving as auth\_http server.

This time, stats from server B was like:

Active connections: 1  
server accepts handled requests  
1985 1985 1985  
Reading: 0 Writing: 1 Waiting: 0

I don’t follow why “writing” is always 1.  
I’ve even setup multiple mail proxy nginx instances to use the same  
server B’s :81/auth as auth\_http URI and yet I have writing = 1.

I’ve seen other nginx+tomcat setups where stats are like:

Active connections: 39  
server accepts handled requests  
421439 421439 986972  
Reading: 0 Writing: 28 Waiting: 11

(writing \> 1)

Can someone explain why this is the case?

-Naresh V.

---

<div class="post-metadata">

**Author:** ![Naresh\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@Naresh\_V](https://www.ruby-forum.com/u/Naresh_V)\
**Post date:** [October 26, 2010, 10:24pm UTC](https://www.ruby-forum.com/t/mail-proxy-auth-http-stats/198124/2 "2010-10-26T22:24:48Z")

</div>

Hello!

On Tue, Oct 26, 2010 at 10:34:31PM +0530, Naresh V wrote:

> ```
> location /auth {
> 
> ```
> 
> when i curl :81/stats, I always get only 1 in writing:  
> (an ActiveRecord call) which implemented the same redirection logic i  
> 1985 1985 1985  
> server accepts handled requests  
> 421439 421439 986972  
> Reading: 0 Writing: 28 Waiting: 11
> 
> (writing \> 1)
> 
> Can someone explain why this is the case?

1. Mail connections are only counted in active stats (and waiting,  
as it’s calculated as “active - (reading + writing)”). Only  
connections which may contribute to “writing” is http connections.

2. Your request to stub\_status will be in “writing” state when  
response is generated. That’s why “writing” is always at least 1.

3. With embedded perl (as well as stub\_status) and small responses  
you have no chance to have two requests in “writing” state in the  
same worker, as requests are processed one-by-one. As soon as  
nginx got full request it increments “writing”, calls perl to  
generate response, write()'s result to socket, decremets  
“writing”. There are no points where nginx may switch to another  
request between incrementing and decrementing writing as it’s not  
returns to event loops while processing request.

With many workers there are chances to see several requests in  
“writing” state (up to 1 per worker) but this requires high  
concurency which is unlikely to happen in your case (as auth\_http  
requests usually happen only once per mail connection).

For http proxy/fastcgi/… setups (or just while serving big  
static responses, even without aio) situation is a bit different:  
nginx increments “writing”, starts handling request and at some  
point it gets EAGAIN (e.g. waiting for connection to backend).  
Then it goes to event loop and starts processing other requests  
(if any). This way you may see multiple request in “writing”  
state even in single worker. Though this still requres at least  
one active request to be present in addtional to your status  
request which is unlikely to happen in your case (as auth\_http…  
see above).

Maxim D.

---

<div class="post-metadata">

**Author:** ![Naresh\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@Naresh\_V](https://www.ruby-forum.com/u/Naresh_V)\
**Post date:** [October 28, 2010, 11:00am UTC](https://www.ruby-forum.com/t/mail-proxy-auth-http-stats/198124/3 "2010-10-28T11:00:23Z")

</div>

Hi,

Thanks for the explanation - that helped.

Another quick question: supposing I want to scale up my auth\_http  
server, what would you recommend? Is the embedded-perl redirector good  
enough?

---

<div class="post-metadata">

**Author:** ![Naresh\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@Naresh\_V](https://www.ruby-forum.com/u/Naresh_V)\
**Post date:** [October 28, 2010, 11:21am UTC](https://www.ruby-forum.com/t/mail-proxy-auth-http-stats/198124/4 "2010-10-28T11:21:45Z")

</div>

Hello!

On Thu, Oct 28, 2010 at 02:29:02PM +0530, Naresh V wrote:

> Hi,
> 
> Thanks for the explanation - that helped.
> 
> Another quick question: supposing I want to scale up my auth\_http  
> server, what would you recommend? Is the embedded-perl redirector good  
> enough?

I usually use proxy\_pass to cluster of auth backends in the same  
nginx as mail proxy, i.e. something like

mail {  
auth\_http 127.0.0.1/auth;  
…  
}

http {  
upstream auth\_backends {  
server …  
server …  
}

```
server {
    listen 127.0.0.1:80;

    location = /auth {
        proxy_pass http://auth_backends;
    }
}

```

}

Maxim D.

p.s. Please do not top-post. Thank you.
