lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

Feature/tcp socket select

Open GuyLewin opened this issue 5 years ago • 4 comments

I hereby granted the copyright of the changes in this pull request to the authors of this lua-nginx-module project.

Implements #1620

GuyLewin avatar Dec 29 '19 11:12 GuyLewin

@spacewander do you mind looking at this too? This PR is a lot more complex than the other, but I believe it's a very important feature for us to have (for example in proxying web sockets or other TCP sockets).

GuyLewin avatar Feb 01 '20 17:02 GuyLewin

Does this new method have any advantage over running multiple coroutines (created by ngx.thread.spawn, each one contains their own sockets) and sync with ngx.semaphore? The latter one is already battle-tested.

spacewander avatar Feb 02 '20 04:02 spacewander

@spacewander thanks for going over this! Can you give an example for Lua code you'd suggest to replace this functionality? Obviously I'd want this code to run without extra threads, but all based on the epoll() (or any module)'s multiplexing logic.

GuyLewin avatar Feb 02 '20 20:02 GuyLewin

@GuyLewin You can use the example in ngx.semaphore docs as a start: https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/semaphore.md

Personally speaking, I think the coroutines could be cheap enough. And implementing a new layer of I/O multiplexing (in the Lua code) above the other one (in the Nginx) may be too complex and inflexible. Somebody has used epoll to reduce memory usage in Go: https://www.freecodecamp.org/news/million-websockets-and-go-cc58418460bb, but they called the epoll directly so this is a different story.

spacewander avatar Feb 03 '20 01:02 spacewander