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

feature: Re-implement ngx_lua's ngx.decode_args API function with FFI #130

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hongliang5316
Copy link

@hongliang5316 hongliang5316 commented Jul 10, 2017

One of our projects had used a lot of ngx.decode_args API function.
When i make a performance test for this project on the Flame Graph. I found the ngx.decode_args API function occupied most of CPU utilization, which reduce QPS seriously. So i re-implement the ngx.decode_args API function with FFI.
I use this code to test:

--10 args
 local args = {
     a = "a", b = true, c = "c", d = "d",
     e = "e", f = "f", g = "g", h = "h",
     i = "i", j = "j"
 }

 local str = ngx.encode_args(args)

 local now = ngx.time()

 for i = 1, 1e6 do
     local _ = ngx.decode_args(str)
 end

 ngx.update_time()
 ngx.say(ngx.now() - now)

The result is:
for lua c api
2.7109999656677
for ffi
1.3810000419617

It seems 100% faster, that's great!
@agentzh
What do you think about this PR?
And also openresty/lua-nginx-module#1108.
Thanks!

@spacewander
Copy link
Member

It seems FFI+JIT is a gold mine. 😃

@hongliang5316
Copy link
Author

hongliang5316 commented Jul 10, 2017

+1. 😄

@agentzh
Copy link
Member

agentzh commented Jul 10, 2017

@hongliang5316 This is awesome! I'll have a look as soon as I can manage.

BTW, you can often get better performance in a whole OpenResty application by adding the following line to your init_by_lua* handler:

require "jit.opt".start("minstitch=3")

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.

3 participants