nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.28k stars 324 forks source link

unit: router does not free the used RAM #861

Open glukkkk opened 1 year ago

glukkkk commented 1 year ago

We have exactly the same problem as described here: https://github.com/nginx/unit/issues/168.

Our PHP app is based on the Lumen framework. We have a simple route that returns a JSON string of approximately 10MB in size. The script looks really simple:

header('Content-Type: application/json');
echo $prettyBigJson;

Then, we start testing it using Siege, an HTTP load tester and benchmarking utility with the concurency number of 50. After 10-20 seconds, the unit:router process starts to consume RAM rapidly. Please take a look at the attached picture. Even after the Siege test is over, the unit:router process still does not free the RAM.

image

NGINX Unit version: 1.29.1

glukkkk commented 1 year ago

Our config:

{
  "listeners": {
    "*:${NGINX_PORT}": {
      "pass": "routes"
    }
  },
  "routes": [
    {
      "match": {
        "uri": [
          "/swagger/*.yaml"
        ]
      },
      "action": {
        "share": [
          "/var/www/app/$uri"
        ]
      }
    },
    {
      "match": {
        "uri": "!/index.php"
      },
      "action": {
        "share": "/var/www/app/public/$uri",
        "fallback": {
          "pass": "applications/wwwapp"
        }
      }
    }
  ],
  "access_log": {
    "path": "/dev/stdout",
    "format": "{\"request_method\":\"$method\", \"request_uri\":\"$request_uri\", \"request_time\":$request_time, \"status\":$status, \"remote_addr\":\"$remote_addr\", \"http_user_agent\":\"$header_user_agent\"}"
  },
  "settings": {
    "http": {
      "max_body_size": ${NGINX_CONF_MAX_BODY_SIZE},
      "send_timeout": ${NGINX_CONF_SEND_TIMEOUT},
      "large_header_buffers": ${NGINX_CONF_LARGE_HEADER_BUFFERS},
      "large_header_buffer_size": ${NGINX_CONF_LARGE_HEADER_BUFFERS_SIZE}
    }
  },
  "applications": {
    "wwwapp": {
      "type": "php",
      "root": "/var/www/app/public",
      "script": "index.php",
      "processes": 20,
      "options": {
        "file": "/etc/php.ini"
      }
    }
  }
}
meezaan commented 1 year ago

Try setting max, idle_timeout and spare. See https://github.com/islamic-network/api.aladhan.com/blob/681dec1847bff1c5ad988a57b01e595673891def/etc/unit/.unit.conf.json#L15 for instance.

tippexs commented 1 year ago

What mentioned by @meezaan should work as an temporary solution.

What do you mean by pretty big JSON? Would like to reproduce this issue.

tippexs commented 1 year ago

Just saw it. Sorry 10MB JSON response. We will have a look on it

glukkkk commented 11 months ago

@tippexs Hello! Any news on this?

tippexs commented 11 months ago

Sorry for the late response @glukkkk . We are busy with the WASM Language module we are about to release.

But as I am wolkig on several PHP related tasks after the release (Aug24th) we will look into this!

glukkkk commented 11 months ago

Thanks! I appreciate it.