Nginx Separated Subquery

I need to do some time-consuming processing of images that are served by NGinx, and I would like to be able to quickly respond to partially processed images from the cache.

Here are the steps I would like:

  • User makes first request for image A
  • User receives image A without processing
  • Connection released
  • image A is cached (A0)
  • A β€œseparate” subquery is started (S1) [first image conversion]
  • Until subquery S1 is executed, all requests for image A receive A0
  • When subquery S1 is executed, the cache value is replaced by its results (A1)
  • From now on, all requests for the image A get A1
  • A β€œseparate” subquery (S2) is started [second image conversion]
  • Until subquery S2 is executed, all requests for image A receive A1
  • When subquery S2 is executed, the cache value is replaced by its results (A2),,, etc.

I use the NGinx Lua module for image processing, and I would like to be able to use the proxy_cache functions (clearing LRU, TTL, etc.)

I tried using proxy_pass, post_action and ngx.location.capture, but they all wait for the subquery to complete to close the connection. I have seen some solutions, such as Drupal Cache Warmer , that cause an OS call to curl, but if possible, I would not want to do this.

This is my test case so far.

server {
    listen       8080;

    location / {

        rewrite_by_lua '
            ngx.say(".")
            --res = ngx.location.capture("/internal")
            ngx.exit(ngx.OK)
        ';

        proxy_pass http://127.0.0.1:8080/internal;

    }

    location /internal {
        content_by_lua '
            ngx.log(ngx.ERR, "before")
            ngx.sleep(10)
            ngx.say("Done")
            ngx.log(ngx.ERR, "after")
            ngx.exit(ngx.OK)
        ';
    }
}
+5
source share
1 answer

post_action ngx.location.capture, , .

ngx.eof().

: http://wiki.nginx.org/HttpLuaModule#ngx.eof

+4

All Articles