-
Notifications
You must be signed in to change notification settings - Fork 2k
tcpsock:setkeepalive #664
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
Comments
@Romaboy Please ensure your ngx_lua module or OpenResty is up to date. If it is indeed the latest, please provide a self-contained and minimal example that we can easily reproduce the issue on our side. Thank you. |
I had updated everything this morning, so I'm very and very happy that now can control pub/sub with semaphore. 3 hours of timeout is quite enough. But setkeepalive wasn't appear. In "content_by_lua" (moonscript): |
@Romaboy Okay, I see what is going on here. There is no |
@agentzh User subscribe to some channel, and new message in channel will be appear in any moment, maybe after hour, maybe won't appeat at all, so how is it possible to open suitable socket "upstream" with setkeepalive? Would be good to write few words in docks about 'downstream", "upstream", cause it's little confusing. |
No, maybe problem is that I read not very carefully or bad english undestending, there is someting about downstream. |
@Romaboy These are nginx terms. "downstream" means the direction towards the client side while "upstream" means the direction towards backend (or origin). |
@agentzh I've been thinking for long time how to do usable websockets among several workers and now have idea! What if get data from downstream such as user IP and other necessary data, then convert it into string (json or just separate with comma) and save into shared.dict, then in another request when some db row is added or changed check for subscribers in that shared dict, for each of those create ngx.socket.tcp (that is upstream, as I understood) with those saved IPs and send changed rows to subscribers? How do you think, is it possible? Another words, is it possible to fill ngx.socket.tcp with data from downstream only using lua primitives? |
@Romaboy I think you need ngx.semaphore for this: https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/semaphore.md#readme |
@agentzh yes, I had made chat with semphores, that was small victory, but want some more: such chat won't be run with few workers, and if there is eight CPU on server only one would be run, it's confusing... Now I see only two ways: 1) somehow deserialize connection into string, save to dict and then serialize it into new connection on other requests. But seems that is impossible |
@Romaboy There are two approaches here for inter-worker synchronization:
Hope it helps. |
|
@Romaboy Hopefully you have some kind of |
Can you please help me to figure it out? ngx_http_lua_ngx_worker_my_function(lua_State *L) {
}` |
@Romaboy I don't quite follow you. But I think you may find the following links interesting: https://github.com/openresty/lua-nginx-module#data-sharing-within-an-nginx-worker https://github.com/openresty/lua-nginx-module#lua_shared_dict https://github.com/openresty/lua-resty-lrucache Please ensure you have read these carefully before trying to hack on the OpenResty internals. |
@agentzh "Note however that Lua global variables (note, not module-level variables) WILL NOT persist between requests because of the one-coroutine-per-request isolation design." |
@Romaboy Oh, and this link too: https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/semaphore.md Do not use Lua global variables; they are evil. The documentation explains why Lua global variables are bad pretty well already. Use proper mechanisms like Lua modules and Lua shared dictionaries. Again: please read through the links I've given above. The Lua global variable thing is a dead end. |
@agentzh I'm trying to write function, that will fire events for each worker. Problem is not about lua global variables, at this state they are just for testing. And it seems that global variables are the easiest way to store data between request. Or even only way. printf("%d\n", L); And also add that line after each calling of ngx_http_lua_get_lua_vm(...) and then after each calling of ngx_http_get_module_loc_conf(...) ngx_http_lua_ngx_worker_my_function(lua_State *L) is accepting lua_State. I can't find place where this state was created! :c |
@Romaboy You're not listening to me and I'm not following you. I'm closing this ticket. Mind you, this ticket's title is "tcpsock:setkeepalive". We should not continue off-topic discussions here. |
@agentzh Sorry, I didn't want to create more ticket's. I know, this issue is not about openresty bugs, I just hoped for help in developing event bridge between workers. Also google groups are awful, but ok I will ask there. |
Hello, I'm trying to deal with websockets and want to set unlimited keepalive to socket. In nginx.conf lua_socket_keepalive_timeout 180m; does not affect. In code sock:settimeout works well, but sock:setkeepalive says, that there is not such method in sock, i.e sock:setkeepalive == nil. Why? Pleese write in docs what is maximum timeout. Thanks for great work!
The text was updated successfully, but these errors were encountered: