1. 11

  2. 6

    My experience with openresty, about 2 years ago, was wonderful. I used it to build a ratelimiter for an API written in Java. Having the proxy power, and the ability to embed complicated logic into that makes for a seriously powerful combination.

    It’s probably gotten better, but testing was tricky. I did the unit test thing, mocked out the apis I was using (which is trivial in lua, btw), and it was pretty OK, but not perfect. I am sure there are some better techniques these days. All in all, highly recommended piece of kit!

    1. 5

      Been using OpenResty quite a bit recently, it’s honestly one of the best web-anythings I’ve ever really had much to do with. You’re basically scripting the full nginx phase cycle in Lua, with full access to all the request and subrequest mechanisms and APIs, running in the embedded LuaJIT, with a long list of amazing, fast async Lua libraries bundled in. Super-fast, super-clean, always seems to do the right/sensible thing by default. It’s changed the way I do a lot of things, just by allowing me to effectively partner the way I structure and route applications with the way I partition URL namespaces in nginx config. Pretty amazing stuff, feels like a … I don’t know, laser scalpel. (Excuse the weird analogy, I just saw Star Wars.)

      Re the testing, there’s what seems like a really powerful testing system in the Test::Nginx test harness, part of the OpenResty build and written by the guy who wrote most of the OpenResty core and lua libraries. (Who, I might add, provides the most stellar support in the mailing list.) I haven’t really got too far into it but it seems to be really nicely geared towards full integration-style testing, which I really like for web stuff. Apparently busted unit testing framework also fits in with it all pretty nicely.

    2. 3

      This is a great intro and useful resource. I’ve been using OpenResty at work for both a log collection server and a REST API proxy, and the performance of it is amazing. The biggest thing I’ve had trouble with is setting up Lua and installing dependencies via luarocks. AFAIK there’s nothing like virtualenv for Lua, and if you need a particular version of Lua on OS X it’s a real pain to install. It’s not really a big deal anymore since we just run it in docker now, but I wish the tooling and docs for Lua were better. I can attest that busted works well for unit testing though :)

      1. 1

        Very true, the various Lua and LuaJIT versions have definitely made it quite difficult on OSX over time. After a bunch of reading I found that the homebrew packagers worked a way around all this so that the lua51 package installs the appropriate luarocks binary, you just have to remember to use luarocks-5.1 in the shell. (There’s no ‘canonical’ lua52 or lua53 that I can see in the homebrew repo but there is a homebrew/versions/lua53.) On debian it’s way easier, I just install everything from apt including luarocks and it Just Works.

        Thing is the OpenResty install bundles up all the JIT stuff necessary for it to work and installs it along with the nginx core and all the resty.* scripts so you don’t really need to worry about that - at least in my experience, at least on debian. I just use the OR environment and if I need to run something on the CLI then I just invoke the JIT binary directly.

        Also, since I got into doing all server-side stuff on Vagrant debian boxes, I tend to avoid doing anything that will eventually get deployed on Linux on Mac anyway, ‘cos although homebrew is a straight-up Gift From Zeus, there’s still too much inconsistency on stuff like this, and spinning up a VM is just too easy.

        All that said, I’m sure there are ways to get Lua > 5.1 working and happy on OSX including luarocks-5.x - but given that I don’t need anything specific in 5.2/5.3, I’ve never needed to dig in to it.