lua-nginx-module
lua-nginx-module copied to clipboard
Feature/tcp socket select
I hereby granted the copyright of the changes in this pull request to the authors of this lua-nginx-module project.
Implements #1620
@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).
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 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
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.