Nginx response time

17,105

In order to optimize my nginx system I have used the following 3 tutorials/tips.

1. A few tips I used to boost my nginx system

Tip 1 – Accelerate and Secure Applications with a Reverse Proxy Server

Tip 2 – Add a Load Balancer

Tip 3 – Cache Static and Dynamic Content

Tip 4 – Compress Data

Tip 5 – Optimize SSL/TLS

Tip 6 – Implement HTTP/2 or SPDY

Tip 7 – Update Software Versions

Tip 8 – Tune Linux for Performance

Tip 9 – Tune Your Web Server for Performance

Tip 10 – Monitor Live Activity to Resolve Issues and Bottlenecks

More info: https://www.nginx.com/blog/10-tips-for-10x-application-performance/

2. Very good tutorial to optimize Nginx configuration

https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration

3. Tracking Application Response Time with Nginx

I added the following block to /etc/nginx/nginx.conf

log_format timed_combined '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '$request_time $upstream_response_time $pipe';

Next we modify our access_log directives to use the new format:

access_log /var/log/nginx/yourdomain.com.access.log timed_combined;

Here’s an example of the log output:

 66.249.71.173 - - [08/Nov/2010:14:16:18 -0600]  "GET /blog/2010/apr/30/installing-geodjango-dependencies-homebrew/ HTTP/1.1" 200 6569 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 0.640 0.640 .

The last part will show you the time it took to serve:

0.640 in this case

Some clever log filtering can now show you exactly where and when your stack is slowing down, giving you clues about where to start optimizing.

More info: https://lincolnloop.com/blog/tracking-application-response-time-nginx/

Share:
17,105
Kaylas
Author by

Kaylas

Updated on June 17, 2022

Comments

  • Kaylas
    Kaylas almost 2 years

    I manage a website created using symfony2, i need to "stabilize" the response time of it.

    The response time is floating from 100ms (lower limit) to 1200ms, and it improve randomicaly (i have already excluded the visit dependency).

    The config as following:

    • Centos 7 x64
    • 4Gb Ram / 2 VCpu
    • Php-fpm 5.6.23 with this settings:

    pm = static pm.max_children = 100 pm.start_servers = 3

    • APCu enabled
    • OPcache enabled
    • I can't use fastcgi cache.

    Any suggestion?

    Thanks

    UPDATE 13:11

    RT Correct:

    [01/Sep/2016:11:01:04 +0200] XX.XX.XX.XX - "GET / HTTP/1.1" "0.044"  200 15035 "-" "XXXXX" "XX.XX.XX.XX"
    
    [01/Sep/2016:11:01:31 +0200] XX.XX.XX.XX - "GET / HTTP/1.1" "0.061"  200 15035 "-" "XXXXX" "-"
    

    RT Not Correct:

    [01/Sep/2016:11:19:23 +0200] XX.XX.XX.XX - "GET / HTTP/1.1" "1.114"  200 15035 "-" "XXXXX" "XX.XX.XX.XX"
    
    [01/Sep/2016:11:25:33 +0200] XX.XX.XX.XX - "GET / HTTP/1.1" "1.131"  200 15035 "-" "XXXXX" "-"
    

    **SAME USER (monitoring system) **

  • Kaylas
    Kaylas over 7 years
    It have a LB on top.
  • Kaylas
    Kaylas over 7 years
    Cache static and compress data is already done. No ssl enabled, http2 already up, software is up to date, already tuned webserver and linux.
  • Engo
    Engo over 7 years
    Nginx’s upstream module makes the process of logging response times trivial with its upstream_response_time variable.
  • Engo
    Engo over 7 years
    Some clever log filtering can now show you exactly where and when your stack is slowing down, giving you clues about where to start optimizing.
  • Engo
    Engo over 7 years
    Have you ever used this before?
  • Kaylas
    Kaylas over 7 years
    Yes i enable the upstream on log, if you want i can post it
  • Kaylas
    Kaylas over 7 years
    How i can find the bottlenecks?