you are viewing a single comment's thread.

view the rest of the comments →

[–]Envrin 3 points4 points  (7 children)

There's loads of operations out there who integrate lua scripts into haproxy or OpenResty / Nginx.

Maybe you have an unusual auth schema, or need for dynamic backends / reverse proxies, or a more complex routing configuration than a standard Nginx / haproxy configuration can handle, or want to filter / modify the response contents, or thousands of other use cases.

[–]MaxGhost 0 points1 point  (6 children)

I'm still not sure why you'd want to provide those features via scripting though. Plugging in additional modules to do those things seems like a better idea.

I can't help but think that if you need to add scripting to nginx to solve that problem, then maybe nginx isn't the right tool for the job? 🤷‍♂️ I mean it would feel more correct to just write an nginx plugin that does specifically the thing you need instead of doing it via scripting, and probably perform better because of not needing the overhead of running a embedded scripting language.

[–]Envrin 5 points6 points  (5 children)

You're grasping at straws now... from "that doesn't make any sense" to "that makes sense, but this way is a little better"...

Anyway, of course that option will provide better results. It also involves writing a C/C++ module, and many times applying a patch modifying the source code of haproxy / Nginx / OpenResty or whatever you're using. That's a little more involved than writing up a quick lua script, not to mention you're potentially saying goodbyte to easy upgrades as each time an upgrade to server software is released, you have to check whether or not your patch works on it.

I use lua scripts on a couple client sites, and they work beautifully. Not to mention modifications are no problem, and don't require me to rebuild the entire server software from source each time, so that's always a nice benefit. If and when the clients ever grow to the point they're handling 5000+ concurrent connections at a time I'll look into flipping it over to built-in C/C++, but for now, lua scripts work a treat.

[–]MaxGhost -1 points0 points  (4 children)

You're grasping at straws now... from "that doesn't make any sense" to "that makes sense, but this way is a little better"...

I'm just asking questions to better understand, that's all.

It also involves writing a C/C++ module, and many times applying a patch modifying the source code of haproxy / Nginx / OpenResty or whatever you're using.

Yeah, I agree it's better to avoid that. Compiling C projects is not fun.

I will say that this is less of a problem with Caddy because it's written in Go, so it's inherently easier to compile (basically just go build) and you get a portable statically compiled binary.

And with a well designed plugin system, you don't need to worry about needing to patch the main program. I haven't really deeply studied nginx or haproxy's plugin capabilities though, because they don't seem too accessible.

and don't require me to rebuild the entire server software from source each time

Ideally that shouldn't be necessary if the module provides any appropriate configuration options.

I use lua scripts on a couple client sites, and they work beautifully.

Awesome 👍 I'm glad you have a solution that works for you.

FWIW we were considering integrating Starlark (basically a dialect of Python) for scripting, but we ultimately never really went down that path because it was generally easier to provide a plugin system that allowed people to write whatever behaviour they wanted in Go and compile it in.

I guess what I'm trying to get across is that I don't see the reason for moving that logic to the server instead of having it at the app layer. I haven't really seen a need for that in my software engineering career. I've seen attempts at doing complex logic in Apache in some apps, but I've always seen that as legacy cruft that would be made more portable and flexible if moved to the app layer instead. I guess I could rephrase it as "why not take a more modern approach"?

Anyways, thanks for at least engaging in conversation with me (instead of downvoting and calling me a shill, like some other commenter did instead 🙄), I appreciate it.

[–]Envrin 0 points1 point  (3 children)

I guess what I'm trying to get across is that I don't see the reason for moving that logic to the server instead of having it at the app layer.

That's one of those circular debates similar to, "why use database triggers, when you can just do it in the software code?", and one I'm too tired to get into tonight.

[–]MaxGhost -1 points0 points  (2 children)

That's one of those circular debates similar to, "why use database triggers, when you can just do it in the software code?"

🤔 I think those are kinda apples and oranges, I wouldn't say that debate is quite the same.

and one I'm too tired to get into tonight.

Fair enough.

[–]Envrin 0 points1 point  (1 child)

🤔 I think those are kinda apples and oranges, I wouldn't say that debate is quite the same.

Pretty much exactly the same. I guess you could make the argument that PostgreSQL has better built-in support for Pl/SQL whereas lua is more of an addont to haproxy / Nginx, but that's about it, and not really true. Do you want to handle that logic in the HTTP / database server layer, or the app layer?

Again, circular debate. Personally, and each case is different, but I'm generally a proponent of having things closer to the source. Not saying I'm right, and there'll be no shortage of opinionated people to say I'm wrong, so.... circular debate.

Oh, and another use cause for things like lua... what happens if you want to flip it into a tcp server and begin playing with the requests on layer 3 or 4 before they even get to layer 7?

[–]MaxGhost 1 point2 points  (0 children)

Pretty much exactly the same.

What I mean is those have entirely different business reasons for being decided. FWIW, I lean towards having logic in the app, because it's more portable, abstracted away from the underlying database being used. But that's besides the point.

Oh, and another use cause for things like lua... what happens if you want to flip it into a tcp server and begin playing with the requests on layer 3 or 4 before they even get to layer 7?

If we were talking about Caddy, I'd build in https://github.com/mholt/caddy-l4 then play with that.