ficusio / openresty

Lightweight OpenResty Docker image
132 stars 37 forks source link

lua_code_cache off not working #14

Open soerenmartius opened 8 years ago

soerenmartius commented 8 years ago

I inherited from your alpine version dockerfile and ran into issues.

FROM ficusio/openresty:latest
COPY nginx/conf /opt/openresty/nginx/conf
EXPOSE 8081

Setting up a new container works as expected, also it uses my custom nginx.conf

nginx.conf

worker_processes 8;
worker_rlimit_nofile  20000;

events {
  worker_connections 5120;
}

http {
  access_log off;
  error_log stderr notice;

  keepalive_timeout 65;
  resolver 8.8.8.8;

  init_by_lua '
    require "resty.core"
  ';

  lua_shared_dict locks 1M;
  lua_shared_dict cache 10M;

  server {
    listen 8082;
    root /var/www;

    #get productviews for user + product
    location ~ /productViews.js {
        lua_code_cache off;
        default_type text/html;
        content_by_lua_file conf/example.lua;
    }

    location ~ / {
        return 200;
    }

  }
}

example.lua

ngx.print('<H1>Hello World.</H1>');

However. Setting lua_code_cache to off won't work on alpine linux. The usual warning

lua_code_cache is off; this will hurt performance

won't come up as expected. Also, if i change the code in example.lua it won't show me the new content but it comes up with an syntax exception in the logs and crashes. Although the syntax i am using is fine.

If i switched to the debian version and it all works as expected. Something seems to be broken with alpine linux version.

soerenmartius commented 8 years ago

I reckon this is caused by missing musl libc in alpine linux

skozin commented 8 years ago

Yeah, Alpine version has problems with lua_code_cache set to off. This is caused not by missing musl libc, but, on the contrary, by the fact that musl libc is used instead of glibc when building OpenResty for Alpine, as Alpine in general uses musl libc instead of glibc. I'm not sure about the cause of this lua_code_cache behavior, but I've run into it too. I suspect this is a bug in musl or a musl/glibc compatibility problem. Also, it's hard to build OpenResty profiling tools with musl libc.

That's why I recommended using Debian flavor in the Usage during development section. Probably I need to emphasize it more in the readme.

That said, we've had no issues caused by musl libc in production.

skozin commented 8 years ago

The only real fix I see now is to build OpenResty with glibc in Alpine flavor too, but that would substantially increase the image size. I'm not sure it's worth it, given that you can use Debian version for development.

soerenmartius commented 8 years ago

Thanks for quick reply @skozin. Making it a bit more clear in the documentation would be nice. But also i did run into issues on production. The logs showed me syntax error but the script was correct though. It even popped up with errors on lines which didn't exist.

skozin commented 8 years ago

So you're not using lua_code_cache off in production, and still get the similar problems?

soerenmartius commented 8 years ago

Sorry for late reply. Yes exactly. Also sometimes I run into syntax errors altough the syntax is correct. If i switch to debian it is working correctly