# High CPU when upstream server down

**URL:** <https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262>\
**Category:** NGINX\
**Created:** [March 8, 2011, 9:12pm UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262 "2011-03-08T21:12:15Z")\
**Posts on this page:** 8\
**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:** [March 8, 2011, 9:12pm UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/1 "2011-03-08T21:12:15Z")

</div>

Nginx goes to nearly 100% CPU when I take down my upstream servers  
(gunicorn). Has anybody heard of this as an issue?

$ nginx -v  
nginx version: nginx/0.7.67  
$ uname -a  
Linux ip-10-242-226-66 2.6.35-27-virtual #48-Ubuntu SMP Tue Feb 22  
23:09:12 UTC 2011 i686 GNU/Linux

Summary of top:

top - 20:10:17 up 1 day, 29 min, 4 users, load average: 1.11, 0.83,  
0.56  
Tasks: 79 total, 2 running, 77 sleeping, 0 stopped, 0 zombie  
Cpu(s): 6.4%us, 36.9%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si,  
56.7%st  
Mem: 1705708k total, 442308k used, 1263400k free, 91240k  
buffers  
Swap: 917500k total, 0k used, 917500k free, 249920k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

30663 www-data 20 0 5492 1944 916 R 99.9 0.1 5:26.32 nginx

```
1 root 20 0 2848 1652 1216 S 0.0 0.1 0:00.47 init

2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd

3 root 20 0 0 0 0 S 0.0 0.0 0:03.74 ksoftirqd/0

4 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0

5 root RT 0 0 0 0 S 0.0 0.0 0:00.20 watchdog/0

6 root 20 0 0 0 0 S 0.0 0.0 0:01.91 events/0

7 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuset

```

Posted at Nginx Forum:

> **[High CPU when upstream server down](https://forum.nginx.org/read.php?2,181397,181397#msg-181397)**
>
> Nginx goes to nearly 100% CPU when I take down my upstream servers (gunicorn). Has anybody heard of this as an issue? $ nginx -v nginx version: nginx/0.7.67 $ uname -a Linux ip-10-242-226-66 2.6.35-27-virtual #48-Ubuntu SMP Tue Feb 22 23:09:12 UTC...

---

<div class="post-metadata">

**Author:** ![adamn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea666f/32.png) [@adamn](https://www.ruby-forum.com/u/adamn)\
**Post date:** [March 8, 2011, 9:18pm UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/2 "2011-03-08T21:18:34Z")

</div>

On Tue, Mar 8, 2011 at 2:10 PM, adamn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Nginx goes to nearly 100% CPU when I take down my upstream servers  
> (gunicorn). Has anybody heard of this as an issue?

## Configuration file? I would suspect something causing an endless loop of redirects or something like that. I did similar to myself in a QA environment a while back with an ill-concieved “catch-all” dynamic error\_page.

RPM

---

<div class="post-metadata">

**Author:** ![adamn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea666f/32.png) [@adamn](https://www.ruby-forum.com/u/adamn)\
**Post date:** [March 8, 2011, 9:36pm UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/3 "2011-03-08T21:36:07Z")

</div>

Using the same config file - everything works fine and this is not  
reproducible on 0.8.54. Here is my config. Keep in mind that the  
upstream and server section are in reality 8 upstreams and servers -  
most of which are exactly the same with the exception of the server\_name  
and the unix socket filename.

user www-data;  
worker\_processes 1;

error\_log /var/log/nginx/error.log debug;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
# multi\_accept on;  
}

http {  
include /etc/nginx/mime.types;

```
access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

upstream dev.example.com {
    server unix:/tmp/gunicorn_dev.example.com.sock;
    # For a TCP configuration:
    #server 127.0.0.1:8000;
}
server {
    listen 80;
    client_max_body_size 4G;
    server_name dev.example.com;

    keepalive_timeout 5;

    # path for static files
    root /var/www/dev-example-env/example/media;

    location = /favicon.ico {
        alias /var/www/dev-example-env/example/media/favicon.ico;
    }

    location = /robots.txt {

        alias /var/www/dev-example-env/example/media/no_robots.txt;

    }

    location /img {
        alias /var/www/dev-example-env/example/media/img/;
    }

    location /admin_media {
        alias

```

/var/www/dev-example-env/lib/python2.6/site-packages/django/contrib/admin/media/;  
}

```
    location / {

            auth_basic "Restricted";
            auth_basic_user_file

```

“/var/www/dev-example-env/example/.htpasswd”;

```
        proxy_set_header X-Forwarded-For

```

$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;

```
        if (!-f $request_filename) {
            proxy_pass http://dev.example.com;
            break;
        }
    }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
        alias /var/www/dev-example-env/example/templates/500.html;
    }
}

```

}

Posted at Nginx Forum:

> **[Re: High CPU when upstream server down](https://forum.nginx.org/read.php?2,181397,181406#msg-181406)**
>
> Nginx goes to nearly 100% CPU when I take down my upstream servers (gunicorn). Has anybody heard of this as an issue? $ nginx -v nginx version: nginx/0.7.67 $ uname -a Linux ip-10-242-226-66 2.6.35-27-virtual #48-Ubuntu SMP Tue Feb 22 23:09:12 UTC...

---

<div class="post-metadata">

**Author:** ![adamn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea666f/32.png) [@adamn](https://www.ruby-forum.com/u/adamn)\
**Post date:** [March 8, 2011, 10:46pm UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/4 "2011-03-08T22:46:20Z")

</div>

On Tue, Mar 8, 2011 at 2:35 PM, adamn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> if (!-f $request_filename) {
> proxy_pass http://dev.example.com;
> break;
> }
> 
> ```

As they say, [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/IfIsEvil)  
I’ve never seen proxy\_pass work correcly inside an if block; the fact  
that it works for you on 0.8.x seems to be happy coincidence.

Try creating a separate location (maybe regex based if necessary) and  
put your proxy\_pass statement in there.

–  
RPM

---

<div class="post-metadata">

**Author:** ![adamn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea666f/32.png) [@adamn](https://www.ruby-forum.com/u/adamn)\
**Post date:** [March 9, 2011, 1:35am UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/5 "2011-03-09T01:35:09Z")

</div>

Just got rid of the if entirely. That logic was totally unnecessary so  
now it’s just:

```
            proxy_pass http://dev.example.com;

```

Posted at Nginx Forum:

> **[Re: High CPU when upstream server down](https://forum.nginx.org/read.php?2,181397,181459#msg-181459)**
>
> Nginx goes to nearly 100% CPU when I take down my upstream servers (gunicorn). Has anybody heard of this as an issue? $ nginx -v nginx version: nginx/0.7.67 $ uname -a Linux ip-10-242-226-66 2.6.35-27-virtual #48-Ubuntu SMP Tue Feb 22 23:09:12 UTC...

---

<div class="post-metadata">

**Author:** ![adamn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea666f/32.png) [@adamn](https://www.ruby-forum.com/u/adamn)\
**Post date:** [March 8, 2011, 11:04pm UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/6 "2011-03-08T23:04:35Z")

</div>

Heh - All I did was copy the docs 🙂

[http://gunicorn.org/deploy.html](http://gunicorn.org/deploy.html)

I’ll work out a solution and post it back.

Cheers,  
Adam

Posted at Nginx Forum:

> **[Re: High CPU when upstream server down](https://forum.nginx.org/read.php?2,181397,181435#msg-181435)**
>
> Nginx goes to nearly 100% CPU when I take down my upstream servers (gunicorn). Has anybody heard of this as an issue? $ nginx -v nginx version: nginx/0.7.67 $ uname -a Linux ip-10-242-226-66 2.6.35-27-virtual #48-Ubuntu SMP Tue Feb 22 23:09:12 UTC...

---

<div class="post-metadata">

**Author:** ![adamn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea666f/32.png) [@adamn](https://www.ruby-forum.com/u/adamn)\
**Post date:** [March 9, 2011, 4:20am UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/7 "2011-03-09T04:20:52Z")

</div>

On Tue, Mar 8, 2011 at 4:02 PM, adamn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Heh - All I did was copy the docs 🙂
> 
> [http://gunicorn.org/deploy.html](http://gunicorn.org/deploy.html)
> 
> I’ll work out a solution and post it back.

As far as I can tell, that site is in no way affiliated with Igor or  
any of the other nginx developers. The authoritative site for nginx is  
[nginx.org](http://nginx.org) (and the links from there).

–  
RPM

---

<div class="post-metadata">

**Author:** ![adamn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea666f/32.png) [@adamn](https://www.ruby-forum.com/u/adamn)\
**Post date:** [March 9, 2011, 4:34am UTC](https://www.ruby-forum.com/t/high-cpu-when-upstream-server-down/204262/8 "2011-03-09T04:34:04Z")

</div>

That is true. Unfortunately there is no documentation on the nginx site  
regarding gunicorn.

Posted at Nginx Forum:

> **[Re: High CPU when upstream server down](https://forum.nginx.org/read.php?2,181397,181484#msg-181484)**
>
> Nginx goes to nearly 100% CPU when I take down my upstream servers (gunicorn). Has anybody heard of this as an issue? $ nginx -v nginx version: nginx/0.7.67 $ uname -a Linux ip-10-242-226-66 2.6.35-27-virtual #48-Ubuntu SMP Tue Feb 22 23:09:12 UTC...
