Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 29, 2021

Conversation

fukiki
Copy link
Contributor

@fukiki fukiki commented Jan 19, 2021

Signed-off-by: fukiki one.fhh@163.com

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
Makefile Outdated
@@ -56,6 +57,9 @@ ifeq ($(LUAROCKS_VER),luarocks 3.)
else
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
Copy link
Member

@membphis membphis Jan 19, 2021

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
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
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
Copy link
Contributor Author

fukiki commented Jan 20, 2021

@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?

Copy link
Member

@membphis membphis left a comment

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
Copy link
Contributor Author

fukiki commented Jan 20, 2021

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
Makefile Outdated Show resolved Hide resolved
apisix/cli/apisix.lua Outdated Show resolved Hide resolved
@fukiki fukiki force-pushed the apisix-run-deps branch 3 times, most recently from ae0ab58 to e44bdfc Compare January 21, 2021 02:40
@membphis
Copy link
Member

membphis commented Jan 21, 2021

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

bin/apisix Show resolved Hide resolved
@fukiki fukiki force-pushed the apisix-run-deps branch 2 times, most recently from 612eccc to 519b4f6 Compare January 21, 2021 08:45
@fukiki
Copy link
Contributor Author

fukiki commented Jan 21, 2021

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

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
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

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
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

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
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

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
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
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
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
Copy link
Member

@membphis membphis left a comment

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
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
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
Copy link
Contributor Author

fukiki commented Jan 27, 2021

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
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
Copy link
Contributor

tokers commented Jan 27, 2021

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

@fukiki
Copy link
Contributor Author

fukiki commented Jan 28, 2021

@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
Copy link
Contributor Author

fukiki commented Jan 29, 2021

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
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
apisix/cli/ngx_tpl.lua Show resolved Hide resolved
apisix/cli/ngx_tpl.lua Show resolved Hide resolved
@membphis
Copy link
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
Copy link
Contributor Author

fukiki commented Jan 29, 2021

@membphis The lua_package_path of stream has already updated.

@liuxiran
Copy link
Contributor

so cool @fukiki ~!

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

@membphis @tokers @imjoey @Fuchange

Copy link
Member

@membphis membphis left a comment

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?

doc/zh-cn/install-dependencies.md Outdated Show resolved Hide resolved
@@ -35,6 +35,8 @@

- 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
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
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
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.

@@ -35,6 +35,8 @@ ifeq ($(OR_EXEC), )
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
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
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
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
Copy link
Contributor

tokers commented Jan 29, 2021

LGTM, except minor style things

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

Just reviewed.

Signed-off-by: fukiki <one.fhh@163.com>
@membphis membphis merged commit 98be489 into apache:master Jan 29, 2021
@membphis
Copy link
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