Hello!
After working on ngx_postgres module which integrates libpq into nginx
directly, I have to say it's quite painful. The libpq library does not
really support ET events very well and we have to workaround various
issues with dirty hacks.
> hiredis has redisAsyncContext:
>
Given the simplicity of the redis protocol, I don't think it's worth
all the trouble (and overhead) of accommodating a C library's C API.
Basically the real world is very messy. We have to eventually get
everything right anyway.
> Everything that doesn't already have one of these lower level fd + events
> APIs, can simply be converted to one.
Sorry, after years of playing with raw fd and events, I really doubt it :)
> Not everything is written with luasocket; and nor should it be.
> Furthermore, luasocket apis become a mess as soon as you add SSL;
The cosocket API already supports SSL/TLS :)
> or more
> than a single socket at a time.
Have you checked out the ngx.thread API?
> Nested epolls/kqueues/etc fix this (which is part of what cqueues use
> internally)
>
OpenResty uses epolls/kqueues/etc via the nginx event model already.
What's the point here?
> Nevermind interfacing with non-socket pollable objects (e.g. things in /proc
> filesystem, which I would like to monitor via a http long polling api)
>
I'd rather abstracting such implementation details away because I
don't want the users to deal with all the potential pitfalls here on
the Lua land.
>> OpenResty is already a dialect of Lua (and we may extend the Lua
>> language syntax and semantics in the future as well).
>
> Please do not!
>
The reason that we chose Lua from the very beginning was not because
we were Lua programmers (I started learning Lua *after* I decided to
work on the ngx_lua module) but just because the core Lua language and
the LuaJIT implementation serve OpenResty's original goals well :)
Supporting other Lua projects outside OpenResty is never a goal of
OpenResty. Though we're open to collaborations and code reuse if not
sacrificing our original vision.
> Not everything is a HTTP endpoint...
Yes, serving as an HTTP endpoint is OpenResty's main focus. But we
recently found that it can naturally extend to other use cases without
much troubles. Have you checked out the resty-cli project and the
TCP/UDP server support in ngx_lua's TODO list? See
https://github.com/openresty/resty-cli
https://github.com/openresty/lua-nginx-module#todo
I'd like to see such things happen naturally without upsetting our
existing (OpenResty) users.
> Lua runs inside (e.g.) game engines, media players and more: these are not
> places nginx should be.
> However, cqueues can: it can let you call out in the middle of a game ai
> plugin.
Yeah, I can see you are completely sold to cqueues :) But unfortunately I'm not.
My way of doing things is to focus on doing one thing and doing it
well. And I may extend things a bit to accommodate some more use cases
if I won't sacrifice the existing core features much.
Frankly I'm not a guy very a big ambition. Making OpenResty run
everywhere is actually not really a goal. I said that because it was
just a better (hypothetical) alternative to intentionally supporting a
more generic and low level Lua APIs. Because the latter will turn
OpenResty into something else which I don't quite like.
> The current state of things immensely confuses beginners:
> Common questions are:
> - "Why can't I use this openresty library in project XYZ"
> - "why can't I use the normal lua library XYZ inside of openresty"?
> - "Why is everything so incompatible, lua programmers can't agree on
> anything!"
>
We will address this with our own package managing toolchain and site.
And anything outside our site or toolchain is not supposed to run in
OpenResty.
> If they are one and the same (cqueues), this problem goes away.
>
Nope, I can see a lot more (practical) problems will come in. I think
I've already listed the issues in my previous mails. So no need to
repeat them here :)
> I hope I can convince you fd + timeout is a baseline that *everything* can
> be expressed as.
> More than one fd to watch? Combine them with epoll?
> Want to watch a signal? Use a signalfd
> Want to wait for a thread to join? socketpair + send
Well, I'm not really interested in expressing everything in Lua.
I'm a C programmer and I just want Lua to be the glue. There's a ton
of implementation details involved with event-based programming, not
just fds, events, and timeout handling, and I doubt if it'll be
efficient enough to do all the heavy lifting on the Lua land instead
of C.
I can buy the idea of a portable and generic Lua APIs that various
different Lua-based systems can agree on. But I hope it to be high
level enough so that we can give enough room and freedom for the
implementors to decide the best implementation strategies. I hope we
can have the best abstraction level here. Low level APIs are certainly
not good abstractions at all IMHO. And for your cqueue API proposal, I
don't buy it as the OpenResty maintainer due to practical
considerations.
> This helps keep things small; its a low level abstraction point for other
> modules to jump in and provide functionality.
> Without it, you'll have to end up adding everything to openresty itself:
> dTLS, SCTP, async file io, etc. rather than as modules/plugins.
>
I don't mind if I can see excellent use cases for them and I can
guarantee that the implementations always work well out of the box :)
I'm not sure if you're an OpenResty user who wants to migrate his
OpenResty Lua code over to other contexts or just a Lua developer who
wants to migrate his whatever existing Lua code (running for other
contexts) over to OpenResty. For the former case, I think you can just
implement the same high level APIs (our cosockets, light threads, and
etc) in the other context, with exactly the same semantics, optimized
for your exotic new contexts, where the high level APIs can shine
again :)
Regards,
-agentzh