Coder Social home page Coder Social logo

Comments (14)

agentzh avatar agentzh commented on August 15, 2024

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

daxiong380380 avatar daxiong380380 commented on August 15, 2024

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

splitice avatar splitice commented on August 15, 2024

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.

daxiong380380 avatar daxiong380380 commented on August 15, 2024

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

daxiong380380 avatar daxiong380380 commented on August 15, 2024

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

agentzh avatar agentzh commented on August 15, 2024

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

agentzh avatar agentzh commented on August 15, 2024

@splitice Have you sampled some flame graphs to show us? Please see http://openresty.org/en/profiling.html

from stream-lua-nginx-module.

daxiong380380 avatar daxiong380380 commented on August 15, 2024

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

zyxtomcat avatar zyxtomcat commented on August 15, 2024

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.

daxiong380380 avatar daxiong380380 commented on August 15, 2024

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

daxiong380380 avatar daxiong380380 commented on August 15, 2024

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

daxiong380380 avatar daxiong380380 commented on August 15, 2024

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

agentzh avatar agentzh commented on August 15, 2024

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

agentzh avatar agentzh commented on August 15, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.