News for hackers. Stuff that matters.
Re:Scripting Nginx with Lua (2012) by terhechte on Friday July 11, 2014 @04:21AM (#8019259)
I tend to always use OpenResty for a certain set of tasks these days. Notably, when it is mostly about lightweight data processing. I.e. an API that reads from a DB, transforms some fields and returns json, or a simple proxy server that slightly modifies the data (or just returns it). Or, performing simple calculations based on a few inputs.

All this usually just requires a few lines of code and due to the nature of OpenResty, it scales really well and is very lightweight in terms of CPU consumption and memory.

I haven't really used it for anything bigger yet, mostly because then I'd rather prefer Django or Clojure (depending on the tasks) as they have much more functionality / packages for web development.

Particularly the nonblocking IO for db/file/networking operations (out of the box) is neat. Another interesting aspect is that, once you've set up the system, development feels a lot like PHP development, where every lua file can be one page and changing the file results in a direct change on the frontend (if you turn the lua code cache off).

On the other hand, there're some pitfalls, the project is young, it still lacks packages for many, many things (notably, if you want to do crypto, you have to FFI right into the C library, for now. There's a new sha/hmac module, but it's not part of the current OpenResty distribution yet). Also, sometimes it is difficult to find solutions to problems, as it is not widely used as Django or Rails. If you're interested in using it, take some time to read up on LuaJIT as there're several important optimization techniques to really get the best out of it (see below).

All in all, for smaller projects, I love the stack as it is simple, lightweight, and easy to install.

Here're some useful links:

Lua(Jit) Profiler: https://github.com/jgrahamc/lulip/

IDE With Debugger for OpenResty (Pretty cool, you can debug while your browser requests): http://notebook.kulchenko.com/zerobrane/debugging-openresty-...

LuaJIT Performance Guide: http://wiki.luajit.org/Numerical-Computing-Performance-Guide

Lua Performance Guide: http://www.lua.org/gems/sample.pdf

Re:Scripting Nginx with Lua (2012) by girvo on Friday July 11, 2014 @07:33AM (#8019617)
The whole debug while requesting a page sounds great, that's a feature I adore from Xdebug.
Re:Scripting Nginx with Lua (2012) by jgrahamc on Friday July 11, 2014 @06:48AM (#8019537)
If you are interested in working on or with OpenResty then CloudFlare is hiring people in London and San Francisco. We employ agentzh and he works on OpenResty at CloudFlare. We use it _extensively_ throughout the CloudFlare stack.

And also we really, really need more people with experience of OpenResty, NGINX, Lua and LuaJIT.

https://www.cloudflare.com/join-our-team

Re:Scripting Nginx with Lua (2012) by xfalcox on Friday July 11, 2014 @09:10AM (#8019916)
agentzh is a great and helpful guy! We're using openresty in a big enterprise setup (100.000+ employees) and it's great.

Sometimes you just want to get a simple json endpoint with some dynamic data, and you can do that in 4 lines in lua+openresty.

Re:Scripting Nginx with Lua (2012) by GrinningFool on Friday July 11, 2014 @09:39AM (#8020048)
One of the concerns I have about openresty is that so much of it relies on agentzh. He does amazing work at an insane rate - a rate that I'm a bit concerned (as someone who uses openresty & luajit extensively) can't be sustained in the long term, and is in serious jeopardy if he gets a better offer.
Re:Scripting Nginx with Lua (2012) by meowface on Friday July 11, 2014 @05:03PM (#8022390)
Yeah, the pace at which he pumps out code is absolutely incredible.

However, I imagine he wouldn't want to work for another company unless they also allowed him to spend a lot of time on the project.

Re:Scripting Nginx with Lua (2012) by zeitg3ist on Friday July 11, 2014 @05:10AM (#8019349)
If you'd like to go a bit higher level without sacrificing performance, I suggest Lapis, a Lua/Moonscript framework built on top of OpenResty: http://leafo.net/lapis/

(not the author, just a fan!)

Re:Scripting Nginx with Lua (2012) by jeangenie on Friday July 11, 2014 @01:32PM (#8021361)
Thanks for sharing. Lapis looks really cool. For anyone curious about performance see ChikkaChiChi's comment[1].

[1] https://news.ycombinator.com/item?id=8021069

Re:Scripting Nginx with Lua (2012) by zeitg3ist on Friday July 11, 2014 @02:05PM (#8021516)
Looking at this table, I should've said "without sacrificing too much performance". Impressive results, though!
Re:Scripting Nginx with Lua (2012) by egeozcan on Friday July 11, 2014 @06:34AM (#8019520)
Lapis + pgmoon do look like a wonderful combination indeed. I'm also a fan, but my experience is limited to small experiments.
Re:Scripting Nginx with Lua (2012) by sciurus on Friday July 11, 2014 @09:39AM (#8020045)
At Lonely Planet we've had a good experience using OpenResty directly behind our CDN. We use it to perform rewrites, route requests to the appropriate applications, manage splits for a/b testing, block malicious traffic, gather metrics, and more!

We touch on our use of it a little bit towards the end of http://velocityconf.com/velocityeu2012/public/schedule/detai.... The last slide is still true- we're hiring! Ruby (remote possible), javascript, devops, and more. See http://www.lonelyplanet.com/jobs/

Re:Scripting Nginx with Lua (2012) by fasteo on Friday July 11, 2014 @10:46AM (#8020350)
I already posted this some time ago, but let me insist on this one:

Openresty (nginx+lua) is probably one of the most underrated technologies we have available nowadays. In my experience, every webapp can offload a ton of work(1) to openresty. The lua code is usually simpler and a lot faster that the equivalent code in the app.

(1) think caching, auth/acl, security filters, stats, logging

Re:Scripting Nginx with Lua (2012) by domrdy on Friday July 11, 2014 @04:51AM (#8019314)
We've recently switched from a file based URL rewrite system to nginx/lua/redis. Before we'd literally include() the rewrites into our configuration files which made -s reload a pain. All in all the implementation was relatively painless, decreased our server reponse time quite a bit and scales way better than our previous naive approach.
Re:Scripting Nginx with Lua (2012) by rahimnathwani on Friday July 11, 2014 @03:34AM (#8019186)
If, like me, you didn't understand the difference between tengine and OpenResty, see here:

https://github.com/openresty/ngx_openresty/issues/54

Re:Scripting Nginx with Lua (2012) by anonfunction on Friday July 11, 2014 @04:59AM (#8019327)
We've just done this at our API focused startup and been really impressed with the performance. OpenResty makes interfacing the server with your business logic and external services a breeze. Nginx and Lua/LuaJIT have been battle tested for years and they are extremely fast and reliable.

Open Source on GitHub: https://github.com/Mashape/mashape-agent

Re:Scripting Nginx with Lua (2012) by justincormack on Friday July 11, 2014 @05:03AM (#8019340)
Re:Scripting Nginx with Lua (2012) by ChikkaChiChi on Friday July 11, 2014 @12:38PM (#8021069)
OpenResty caught my attention in the most recent TechEmpower Benchmarks. It definitely deserves your attention if you need something that can handle concurrent requests at a large scale:

http://www.techempower.com/benchmarks/#section=data-r9

Re:Scripting Nginx with Lua (2012) by brianmtully on Friday July 11, 2014 @09:43AM (#8020064)
A great project built on top of openresty: http://coronium.io/
Re:Scripting Nginx with Lua (2012) by maheart on Friday July 11, 2014 @06:24AM (#8019497)
Off topic, but does anyone know what software was used to make/generate the slides webpage?
Re:Scripting Nginx with Lua (2012) by justincormack on Friday July 11, 2014 @06:35AM (#8019522)
It is Shower http://shwr.me/
Re:Scripting Nginx with Lua (2012) by netghost on Friday July 11, 2014 @12:45PM (#8021105)
Shower is really great. It also defines sensible print styles which work well for "print to pdf".
Re:Scripting Nginx with Lua (2012) by justincormack on Saturday July 12, 2014 @07:57AM (#8024343)
Yes, I discovered that when I needed to produce a pdf for a talk that was potentially offline, worked really well.