Using LuaJIT in mid-load web-projects

2,397
-1

Published on

Talk was originally given in Russian at Russian Internet Technologies conference in 2013.

Published in: Technology
3 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,397
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
19
Comments
3
Likes
2
Embeds 0
No embeds

No notes for slide

Using LuaJIT in mid-load web-projects

  1. 1. Using LuaJIT in mid-load web-projectsAlexander GladyshCTO, LogicEditor
  2. 2. On Lua and LuaJITLua:• powerful,• fast,• lightweight,• extensible,• embeddablescrip ng programming language.
  3. 3. LanguageOn Lua and LuaJIT• Origins.• Popularity growth.• Where is Lua used?• LuaRocks.
  4. 4. Popular DialectsOn Lua and LuaJIT• Lua 5.1 vs. Lua 5.2,• LuaJIT 2.0,• Metalua.
  5. 5. LuaJIT 2.0On Lua and LuaJIT• JIT, FFI, performance.• Limita ons on x86 64.• LuaJIT vs. Lua 5.2.
  6. 6. Why Lua?On Lua and LuaJITHistorically: Were coming from computer games industry, where Lua "rules theworld".Pragma cally:• Works fast!• Pleasant to code!• Easy to learn!
  7. 7. Where to get programmers?On Lua and LuaJITReeduca on.
  8. 8. Main problems learning LuaOn Lua and LuaJIT• Mindless nkering with the language.• NIH-syndrome. Lua is to easy to nker with.• Diverging from the mainstream. Costs and benefits.• Language idiosyncrasies:• Global variables by default.• Arrays are indexed from 1.• Size of array with nil element is not defined.• Everything that is not nil or false — true (0 too).
  9. 9. Most important!On Lua and LuaJITWhen you code in Lua — code in Lua!
  10. 10. Lua / LuaJIT place in your stackOn Lua and LuaJITFirst and foremost:• User-configurable business-logic.• Code that would otherwise be wri en in C/C++/OCaml.
  11. 11. Frameworks to build webservices with LuaOur stackSome of the popular ones:• Kepler/WSAPI• OpenResty• LuvitWe have a "bicycle", built on WSAPI.
  12. 12. What web-problems are we solving with Lua?Our stack• Browser and social games.• Ad networks.• Other web-services, mobile games etc.
  13. 13. HardwareOur stack• Linode• Hetzner EX6
  14. 14. OSOur stack• Xen XCP on top of Ubuntu Sever.• domU on Ubuntu Server:• HTTP frontends (nginx).• HTTP backends (32-bit).• Workers (32-bit).• DB (Redis, MySQL).• Aux (Bind, nginx-based config-server, deployment, monitoring etc.).
  15. 15. BackendsOur stack• nginx• spawn-fcgi + mul watch• LuaJIT 2.0• FCGI/WSAPI• Applica on code
  16. 16. WorkersOur stack• runit• LuaJIT 2.0• Applica on code
  17. 17. IPCOur stack• ØMQ• Tasks:• Replacement for broken signals.• In-process cache reset.• (Workers get tasks via Redis.)
  18. 18. System tuningOur stack• OS• bit.ly/kernel-magic (for frontends and backends)• Redis• I/O Scheduler: noop on guests, deadline on host• nginx• worker rlimit nofile
  19. 19. "DevOps"Our stack• Deployment• High Availability• Monitoring
  20. 20. Main librariesOur stack• lua-nucleo, lua-aplicado (be er — Penlight, telescope)• slnunicode• luatexts, luajson• luasocket, luaposix (be er — ljsyscall)• WSAPI• lua-zmq• lua-hiredis (be er — ljffi-hiredis)• luasql-mysql
  21. 21. DSL and code genera onOur stack• HTTP request handlers.• Code (par ally sta cally validated).• Docs.• (Planned) Smoke-tests.• SQL schema.• "ORM" wrapper code.• DB schema patches.• Auto-backoffice.• Docs.• bit.ly/lua-dsl-talk• Common parts of a project are generated from text templates.
  22. 22. PerformanceOur stack• About 160M synthe c hits per day per EX6-class server in ad networks.• About 8K simultaneous ac ve users per EX6-class server in online games.
  23. 23. What did we encounter?Pi allsIn main:• Couple "mysterious" problems, due to bugs in early LuaJIT2 betas (all fixed bynow).• Problems, caused by two versions of the same LuaRocks package installed inthe system.• Exploding Redis.• Lousy Hetzner HDD reliability.
  24. 24. Diagnos cs, debugging and monitoringPi alls• Par al sta c code valida on.• Run me valida on.• Autotests.• GC tuning and monitoring.• Monitoring for request mes, memory usage etc.• Debugging with logs.
  25. 25. Main unsolved problemsPi alls• Long polling / Comet.• OS signal handling.• More efficient CPU usage with HTTP handlers.• LuaRocks:• Can install two versions of the same rock in the system.• Cant upgrade a package.
  26. 26. Next genera on stack• Unblocking API with corou nes, no callback. Get inspired by, or adaptOpenResty.• Complete transi on to LuaJIT FFI.• Consider dropping LuaRocks.• Drop FCGI, move to epoll and lua-h p-parser.• Simplify the architecture as much as possible. Drop the configura on server.More code genera on!• New DSL design.
  27. 27. Want to know more?Official Site lua.org, luajit.orgWiki lua-users.org/wiki, wiki.luajit.orgMailing Lists lua.org/lua-l.html, luajit.org/list.htmlStackOverflow stackoverflow.com/ques ons/tagged/LuaIRC #lua at irc.freenode.net
  28. 28. Ques ons?@agladyshag@logiceditor.commeetup.com/Lua-in-Moscow
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×