Skip to content

fix: Use luajit by default when run APISIX CLI#3335

Merged
membphis merged 1 commit into
apache:masterfrom
fukiki:apisix-run-deps
Jan 29, 2021
Merged

fix: Use luajit by default when run APISIX CLI#3335
membphis merged 1 commit into
apache:masterfrom
fukiki:apisix-run-deps

Conversation

@fukiki

@fukiki fukiki commented Jan 19, 2021

Copy link
Copy Markdown
Contributor

Signed-off-by: fukiki [email protected]

What this PR does / why we need it:

When run APISIX, use LuaJIT or Lua 5.1 by default.

If the local lua version is not 5.1, use openresty-luajit as default.

Fix : #3281

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@fukiki fukiki changed the title fix:Use luajit or lua 5.1 by default when run APISIX fix: Use luajit or lua 5.1 by default when run APISIX Jan 19, 2021
Comment thread Makefile Outdated
luarocks install rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local
endif
ifneq ($(LUA_VER),Lua 5.1)
sed -i '' -e "s|#!/usr/bin/env lua|#!/usr/bin/env $(LUAJIT_DIR)/bin/luajit|g" ./bin/apisix

@membphis membphis Jan 19, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a hack way. it should not be enough.

here is another way, we can make a try:

#!/bin/sh

# find the openresty, eg: which openresty
...
# find the luajit of openresty
...
# run the CLI of APISIX
$luajit -e '...'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@membphis
I don't understand very clearly.
Do you mean to create a new shell script to judge whether to use lua5.1 or luajit when running the CLI of APISIX?
It could run the CLI of APISIX selectively: lua ./bin/apisix or luajit -e ./bin/apisix?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use a shell script to write the CLI, it'll to call luajit ./bin/apisix

@fukiki
fukiki force-pushed the apisix-run-deps branch 7 times, most recently from 32bbf86 to 065a44e Compare January 20, 2021 03:01
@fukiki

fukiki commented Jan 20, 2021

Copy link
Copy Markdown
Contributor Author

@membphis Could you review commit 065a44 for me? Thank you.

By the way, about CI error: lua: /usr/bin/apisix.lua:3: unexpected symbol near '-' , the file apisix.lua is the same with old file apisix, no change, and I didn't find any reason about it, could you help me?

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put this file bin/apisix.lua to apisix/cli?

@fukiki

fukiki commented Jan 20, 2021

Copy link
Copy Markdown
Contributor Author

can we put this file bin/apisix.lua to apisix/cli?

apisix.lua is a part of cli, put it into apisix/cli will be better. Thanks.
I will modify it.

@fukiki
fukiki force-pushed the apisix-run-deps branch 2 times, most recently from 2f04024 to c0d7384 Compare January 20, 2021 10:14
Comment thread Makefile Outdated
Comment thread apisix/cli/apisix.lua Outdated
@fukiki
fukiki force-pushed the apisix-run-deps branch 3 times, most recently from ae0ab58 to e44bdfc Compare January 21, 2021 02:40
@membphis

membphis commented Jan 21, 2021

Copy link
Copy Markdown
Member

please merge the code of master branch, CI failed ^_^

Comment thread bin/apisix
@fukiki
fukiki force-pushed the apisix-run-deps branch 2 times, most recently from 612eccc to 519b4f6 Compare January 21, 2021 08:45
@fukiki

fukiki commented Jan 21, 2021

Copy link
Copy Markdown
Contributor Author

@membphis @tokers Please take a look when you have time.

Comment thread bin/apisix Outdated
-- modify the load path to load our dependencies
package.cpath = pkg_cpath .. pkg_cpath_org
package.path = pkg_path .. pkg_path_org
if [[ "$LUA_VERSION" =~ "Lua 5.1" && $USE_LUA ]]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong. we should always use luajit of openresty

Comment thread bin/apisix Outdated
-- modify the load path to load our dependencies
package.cpath = pkg_cpath .. pkg_cpath_org
package.path = pkg_path .. pkg_path_org
if [[ "$LUA_VERSION" =~ "Lua 5.1" && $USE_LUA ]]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong. we should always use luajit of openresty

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we always use luajit of openresty , it will be a big chage for old users . so we think maybe we should leave a way for old users ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine for the old users, sure for this

Comment thread bin/apisix Outdated
.. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"
# find the openresty
OR_EXEC=$(which openresty)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step may fail, and we need to do some exception checks.

If the openresty command is not found, you can actively determine whether there is this directory in /usr/local/openresty.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thrown an error if failed to find the openresty

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fukiki
fukiki force-pushed the apisix-run-deps branch 2 times, most recently from 208613a to 5583dac Compare January 22, 2021 03:28

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, ci failed, need you to process it

@fukiki fukiki reopened this Jan 26, 2021
@membphis

Copy link
Copy Markdown
Member

@spacewander told me that, this is a bug of openresty 1.15 or 1.17 .

do you have any suggestions about this?

luajit: lj_asm_x86.h:2819: asm_loop_fixup: Assertion `((intptr_t)target & 15) == 0' failed.
./bin/apisix: line 40: 24266 Aborted                 (core dumped) $LUAJIT_BIN $APISIX_LUA $*
Error: Process completed with exit code 134.

@spacewander

Copy link
Copy Markdown
Member

The problem occurs with openresty-debug. Since people might use openresty-debug package, the robust way is to avoid using LuaJIT unless you are using OpenResty 1.19.

@fukiki

fukiki commented Jan 27, 2021

Copy link
Copy Markdown
Contributor Author

About the bug of openresty-debug, there are two suggestions:

  1. Add conditions: when OpenResty version is not 1.19 , allow to use Lua 5.1
  2. Modify document: introduce the bug , explain the reasons and solutions

@membphis

Copy link
Copy Markdown
Member

About the bug of openresty-debug, there are two suggestions:

  1. Add conditions: when OpenResty version is not 1.19 , allow to use Lua 5.1
  2. Modify document: introduce the bug , explain the reasons and solutions

I think this is fine. you can make a try ^_^

@tokers

tokers commented Jan 27, 2021

Copy link
Copy Markdown
Contributor

@fukiki I think the title can be changed :), we only want to run APISIX CLI with LuaJIT.

@fukiki

fukiki commented Jan 28, 2021

Copy link
Copy Markdown
Contributor Author

@fukiki I think the title can be changed :), we only want to run APISIX CLI with LuaJIT.

About the bug of openresty-debug, only using OpenResty 1.19 not Lua 5.1?

#3335 (comment)
#3335 (comment)

@fukiki
fukiki force-pushed the apisix-run-deps branch 2 times, most recently from 531e38b to 818fe47 Compare January 28, 2021 09:27
@fukiki

fukiki commented Jan 29, 2021

Copy link
Copy Markdown
Contributor Author

About the bug of openresty-debug, there are two suggestions:

  1. Add conditions: when OpenResty version is not 1.19 , allow to use Lua 5.1
  2. Modify document: introduce the bug , explain the reasons and solutions

I think this is fine. you can make a try ^_^

@membphis I've already done, could you review my pr please? Than you.

@membphis

Copy link
Copy Markdown
Member

@membphis I've already done, could you review my pr please? Than you.

let me take a look. many thx for your nice job

@fukiki fukiki changed the title fix: Use luajit or lua 5.1 by default when run APISIX fix: Use luajit by default when run APISIX CLI Jan 29, 2021
Comment thread apisix/cli/ngx_tpl.lua
Comment thread apisix/cli/ngx_tpl.lua
@membphis

Copy link
Copy Markdown
Member

@fukiki I think we can merge this PR soon ^_^

@fukiki
fukiki force-pushed the apisix-run-deps branch 2 times, most recently from 6b70000 to ac25353 Compare January 29, 2021 03:52
@fukiki

fukiki commented Jan 29, 2021

Copy link
Copy Markdown
Contributor Author

@membphis The lua_package_path of stream has already updated.

@liuxiran

Copy link
Copy Markdown
Contributor

so cool @fukiki ~!

Since all checks have passed, pls take a look again at your convenience

@membphis @tokers @imjoey @Fuchange

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except minor style things

@tokers do you have time to look at this PR?

Comment thread doc/zh-cn/install-dependencies.md Outdated
Comment thread doc/install-dependencies.md Outdated

- If you want use Tengine instead of OpenResty, please take a look at this installation step script [Install Tengine at Ubuntu](../.travis/linux_tengine_runner.sh).

- By default Apache APISIX runs with luajit of OpenResty 1.19 (priority) or Lua 5.1. If you run in to an issue `luajit: lj_asm_x86.h:2819: asm_loop_fixup: Assertion '((intptr_t)target & 15) == 0' failed`, it is caused by to the compatibility of OpenResty version. OpenResty 1.19 is recommended, please take a look at this installation step script [linux-install-openresty](../utils/linux-install-openresty.sh).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apache APISIX runs with luajit -> Apache APISIX runs with LuaJIT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@membphis I submitted about the style things.

Comment thread Makefile
ifeq ("$(wildcard /usr/local/openresty-debug/bin/openresty)", "")
@echo "ERROR: OpenResty not found. You have to install OpenResty and add the binary file to PATH before install Apache APISIX."
exit 1
else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about echoing a warn message here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tokers The warn message will be better, I've submitted.

@tokers

tokers commented Jan 29, 2021

Copy link
Copy Markdown
Contributor

LGTM, except minor style things

@tokers do you have time to look at this PR?

Just reviewed.

@membphis
membphis merged commit 98be489 into apache:master Jan 29, 2021
@membphis

Copy link
Copy Markdown
Member

@fukiki many thx, merge already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document how-to-build.md should add a troubleshooting of luasocket

7 participants