How to check if nginx uses LuaJit and not Lua?
Asked Answered
P

1

18

I installed http-lua-module with nginx, made a script that works perfectly fine, but now I want to be sure that nginx uses LuaJit instead of Lua (because my research shows that LuaJit is faster).

I added to the .bushrc those lines of code :

export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

I also recompiled nginx and now I just want to be sure that it uses LuaJit.

Pygmy answered 27/9, 2013 at 17:9 Comment(7)
if jit then print'LuaJIT' endScrubland
Hi Egor, can you tell me where should I write this if statement, I'm new to both nginx and luaPygmy
I'm new to nginx too. But anywhere in your Lua code you can use if jit then .. end statement to check if you run under LuaJIT.Scrubland
Thank you, it's really an anwerPygmy
@Egor, the answer box is larger and more convenient to write to.Epiphysis
@PaulKulchenko Maybe he's allergic to upvotes? ;)Chafer
@greatwolf, could be. I'll start taking his comments and posting them as answers. Not a great move, but could be effective ;)Epiphysis
M
27

Edit your nginx.conf file, add a location into your server {} block:

location = /lua {
    default_type text/plain;
    content_by_lua '
        if jit then
            ngx.say(jit.version)
        else
            ngx.say("Not LuaJIT!")
        end
    ';
}

Then start your nginx server and then access /lua in curl or in your favorite web browser. If you see outputs like "LuaJIT 2.0.2", then you're using LuaJIT; otherwise, if you see "Not LuaJIT!", then you're using the standard Lua 5.1 interpreter.

Another quicker way is to check the Lua DSO file linked with your nginx executable if dynamic linking is used (which is usually the case):

ldd /path/to/your/nginx/sbin/nginx|grep -i lua

If you see something like

libluajit-5.1.so.2 => /usr/local/openresty-debug/luajit/lib/libluajit-5.1.so.2 (0x00007fb3d38f6000)

Then you're using LuaJIT.

Magda answered 27/9, 2013 at 21:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.