Comments (14)
@daxiong380380 Just use content_by_lua* of ngx_stream_lua_module and implement the proxy all in Lua via cosockets.
from stream-lua-nginx-module.
@agentzh
Hi
I had tried this method.
Cosockets can't satisfy my requirements,because cosockets just builds short TCP connection with the server,there exist a big performance problem.I want to use the upstream ability of nginx.
from stream-lua-nginx-module.
I must say we currently find ourselves in a similar situation. The performance of content_by_lua for implementing a filtering proxy just isnt very high.
I have planned body_filter_by_lua at some point, but currently its not even a remote priority.
from stream-lua-nginx-module.
@agentzh
After I read some cosocket docs,I find my recognize to the cosoket is wrang.Maybe cosoket can solve my problem:)
from stream-lua-nginx-module.
@agentzh
@splitice
Hi
when I create tcp socket during the content phase,I'd like to save this socket so that I can reuse it in the next requst,is this idea correctly?
or are there some other ways to reuse the socket in several request?
from stream-lua-nginx-module.
@daxiong380380 Reusing connections is easy on both sides. For upstream connections, you can use the builtin connection pool via the setkeepalive
method. This way you can recycle upstream connections across the "session" boundary (though not across the nginx worker process boundary). For downstream connections, just repeatedly process N
requests in the same downstream cosocket object in a loop or something. Just do not use an infinite loop to process infinite number of requests in the same connection since right now quite some (small) memory blocks are allocated in the "session" memory pool, which won't get freed until the current session (associated with the current downstream connection) is destroyed.
from stream-lua-nginx-module.
@splitice Have you sampled some flame graphs to show us? Please see http://openresty.org/en/profiling.html
from stream-lua-nginx-module.
@agentzh
Hi
`--do it in the content
local socket = ngx.socket.tcp()
socket:setkeepalive(0)
local ok, err = socket:connect(ip,port)`
I create soket during the content phase,I expect the tcp connection keep alive always with the server so that I can reuse it in the different requsts,but when I test my deamo ,I find the tcp connection would be closed after one request finished.I think I use the cosocket in an incorrect way.
So your examples are very grateful .
from stream-lua-nginx-module.
setkeepalive must after the request finished, like this:
local socket = ngx.socket.tcp()
local ok, err = socket:connect(ip,port)
--request
socket:setkeepalive(...)
from stream-lua-nginx-module.
@zyxtomcat
Thank you very much, I made a mistake, when I set keepalive after connect,the connection is not closed.
from stream-lua-nginx-module.
@zyxtomcat
Hi
when I use the cosocket to forward my tcp stream I find the connection between my client and the nginx closed after the client received the response from the server.I hope that connection can also be keep alive,how can I do that?
from stream-lua-nginx-module.
@agentzh
Hi
local sock = assert(ngx.req.socket(true))
Can I keep alive this socket,so I can keep the TCP connection between client and nginx.
from stream-lua-nginx-module.
@daxiong380380 Just use a Lua loop to repeatedly process N requests in a single Lua handler. But it's not recommended to use an infinite loop or a finite loop with too many iterations.
from stream-lua-nginx-module.
@daxiong380380 BTW, general questions should go to the openresty-en mailing list instead. This place is for bug report or developer discussions only. See http://openresty.org/en/community.html
from stream-lua-nginx-module.
Related Issues (20)
- ngx_stream_lua_worker.c:124:8: error: ‘ngx_core_conf_t’ has no member named ‘privileged_agent_connections’ HOT 4
- Lua blocks cannot coexist with proxy_pass, only proxy_pass is executed when proxy_pass is present HOT 1
- ngx.say could not use in udp mode?
- TLS connections failing on `init_worker` HOT 1
- 【help】 tcp request报文修改 HOT 1
- Openresty build with Option:--without-http_ssl_module --without-stream_ssl_module failed HOT 1
- tha lastest openresty and stream-lua-nginx-module ,has no member named ‘privileged_agent_connections’ HOT 1
- ld: symbol(s) not found for architecture x86_64 HOT 2
- content_by_lua_block not working with tcp proxy_pass. HOT 1
- Feature: sendupstream() similar to njs
- [help wanted] how can I reset ngx.req.socket in context:preread
- [Improvement] Add License File to Project HOT 2
- Will nginx1.21.5 still be supported? HOT 7
- feature required: support PCRE2 HOT 7
- starttls HOT 1
- When using OpenResty as a proxy for forwarding TCP traffic, how can I obtain the address of the backend server that the client wants to access from the captured traffic? HOT 9
- About the timeout period HOT 2
- nginx "content_by_lua_block" directive is not allowed here HOT 3
- Would love `access_by_lua_block` HOT 3
- Want to add a life time limit for stream proxy_pass session with stream-lua-nginx-module. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stream-lua-nginx-module.