performance issue after update from 2.26 (lock mechanism)
Opened this issue · 11 comments
Running latest version of resty:
root@openresty:~/lua-gd-master# opm list
openresty/lua-resty-string 0.11
bungle/lua-resty-session 3.6
When loading the page the first time, the page is loaded that fast, but when reloading it takes around 10 seconds.
I've located the problem already as it's the declaration of the redis object:
#!/usr/bin/env lua5.1
local session = require "resty.session".start{
name = "cookie_name",
storage = "redis",
strategy = "regenerate",
--see https://github.com/bungle/lua-resty-session#redis-storage-adapter for redis config parameters
redis = {
prefix = 'oresty',
ssl = 'off',
ssl_verify = 'off',
},
cookie = {
lifetime = 1800,
},
secret = "sQlraJPuVjLYJ1KMR9y6wzs5wtkTkbJd" --required to set a fixed session secret, to prevent session lost on oresty restart / reload
}
local captcha = require 'captcha'
local base64 = require 'base64'
--user is not authorized
if not session.data.authorized then
ngx.say("no auth")
--store captcha inside session
session.data.code = cap:getStr()
session:save()
-- display webpage...
else
ngx.say("auth success")
end
.....
Commenting out the line of local session...
will reduce loading time dramatically.
With declaration:
The problem seems to be located inside the release of 3.0. Running the script with version 2.26
doesn't cause this problem.
@pekineseZ, so where do you think exactly the issue is?
I've located the problem already as it's the declaration of the redis object:
I mean what do you mean about it?
Does it only happen on unauthenticated or after successful login? Please remember to :save
or :close
any session that was opened with :start
. I see that your else branch does not :close
.
See: https://github.com/bungle/lua-resty-session#about-locking
Or set redis = { uselocking = false }
@bungle I've prepared a code sample, can I email it to you somehow?
Using redis = { uselocking = false
solves the problem but will strategy = "regenerate",
has any effect now, also now the cookie content won't be saved.
A few lines regarding the set part:
session.data.code = "1"
session:save()
redis config:
strategy = "regenerate",
redis = {
port = '6379',
uselocking = false,
},)
Yes, regenerate basically allows more than one cookie on async (XHR) scenarios (it will TTL the old ones).
Locking on the other hand makes :start
to wait other requests :start
to call save/close/destroy to unlock.
But it is possible there is bug somewhere. I just want to be sure it is not on your code.
@bungle Any chance to send you my code (reduced, so you can spin up a setup in a few minutes) by e-mail?
It's commented so you can get a quick view of it.
Working fine with lua-resty 2.26 (running in production).
Perhaps I should add another arguments to start:
session.start(config, function(session)
session.data.id = dog
end), "close|save|destroy")
That will then call close
/save
/ destroy
automatically after executing the function in pcall
..
It is possible that 2.26
had a bug or that 3.x
has the bug. But you can send the code to here or aapo.talvensaari@gmail.com.
@bungle Check your mails for details, think you can reproduce the problem easy, script was reduced, so you can reproduce it that easy.
It seems like the issue was more in the client code, so I will close this.