Live data from Hacker News

Luvit – Asynchronous I/O for Lua

luvit.io

11–20 of 37 posts

Re: Luvit – Asynchronous I/O for Lua

#11
post #5

I've been using this lately on a personal project. For those who don't know, this is basically a clone of the Node.js API in the Lua language (using the LuaJIT compiler). This is interesting because: - LuaJIT is often faster than V8 and uses less memory - LuaJIT has a built in C FFI and supports C datatypes for working with low level libraries (or even writing low level code in Lua) - Lua has coroutines I think this…

I think Rackspace is using openresty.

http://openresty.org/

Re: Luvit – Asynchronous I/O for Lua

#12
post #4

Not sure exactly how duped this is for HN... For those that don't know.. Lua is a scripting language, perhaps a bit more structured than it's more popular counterparts (JavaScript and Python), having very good performance characteristics. It's very popular in terms of Game development. Luvit is essentially a lua interpreter with bindings to libuv (the same core IO library used in NodeJS). And could mainly be consider…

> Lua is a scripting language, perhaps a bit more structured than it's more popular counterparts (JavaScript and Python) I wouldn't say it has more structure than Python or JavaScript. Lua has only these types: number, string, boolean, table, function, nil, userdata and thread. Table acts as a hybrid between list and map, just like Array/Object in JavaScript. And users rarely are exposed directly to userdata/thread,…

I thought Lua used a register based VM.

Re: Luvit – Asynchronous I/O for Lua

#13
post #6
post #2

For those interested, lthread now supports AIO. It's still in dev branch, but I'll be merging it soon: http://webmon.com/blog/2013/02/19/lthread-now-supports-userl... https://github.com/halayli/lthread/blob/dev/src/lthread_io.c

digressing from luvit... how does the stack copying technique (as used in lthread) compare to segmented stacks (as used in go)? The swap technique is very simple but I would assume that the stack copy shows up in profiles and is significantly slower than the segmented stack technique... Are there any benchmarks?

Hm, that's unfortunately to hear. Ruby 1.8 implemented green threads by using stack copying. It was discovered that this resulted in significant performance hits: http://timetobleed.com/fixing-threads-in-ruby-18-a-2-10x-per...

Re: Luvit – Asynchronous I/O for Lua

#14
post #11
post #5

I've been using this lately on a personal project. For those who don't know, this is basically a clone of the Node.js API in the Lua language (using the LuaJIT compiler). This is interesting because: - LuaJIT is often faster than V8 and uses less memory - LuaJIT has a built in C FFI and supports C datatypes for working with low level libraries (or even writing low level code in Lua) - Lua has coroutines I think this…

I think Rackspace is using openresty. http://openresty.org/

Rackspace use hundreds of open source projects.

Luvit.io is specifically being used in our Host Monitoring Agent, which is open source and you can find here:

https://github.com/racker/virgo

This is used to collect all kinds of host metrics (CPU, disk, ram, custom scripts, mysql, etc) for the Cloud Monitoring Product.

Re: Luvit – Asynchronous I/O for Lua

#15
post #12

Earlier quoted context omitted.

> Lua is a scripting language, perhaps a bit more structured than it's more popular counterparts (JavaScript and Python) I wouldn't say it has more structure than Python or JavaScript. Lua has only these types: number, string, boolean, table, function, nil, userdata and thread. Table acts as a hybrid between list and map, just like Array/Object in JavaScript. And users rarely are exposed directly to userdata/thread,…

I thought Lua used a register based VM.

No, it's a stack machine. See http://www.lua.org/manual/5.1/manual.html#3

Re: Luvit – Asynchronous I/O for Lua

#16
post #12

Earlier quoted context omitted.

I thought Lua used a register based VM.

No, it's a stack machine. See http://www.lua.org/manual/5.1/manual.html#3

The stack is an abstraction used in the C API. If you look at the actual bytecode generated, it's all register-based.

Re: Luvit – Asynchronous I/O for Lua

#17
post #4

Not sure exactly how duped this is for HN... For those that don't know.. Lua is a scripting language, perhaps a bit more structured than it's more popular counterparts (JavaScript and Python), having very good performance characteristics. It's very popular in terms of Game development. Luvit is essentially a lua interpreter with bindings to libuv (the same core IO library used in NodeJS). And could mainly be consider…

> Lua is a scripting language, perhaps a bit more structured than it's more popular counterparts (JavaScript and Python) I wouldn't say it has more structure than Python or JavaScript. Lua has only these types: number, string, boolean, table, function, nil, userdata and thread. Table acts as a hybrid between list and map, just like Array/Object in JavaScript. And users rarely are exposed directly to userdata/thread,…

Lua IS a register based machine. The white paper done by the Lua authors is the reason most of the industry has moved to register based machines. (Apple SquirrelFish for Safari was the first to read it and implement it and everybody followed suit to compete.) http://www.lua.org/doc/jucs05.pdf

Lua has true multiple return value support. The overall usefulness of tuples in light of this feature is not clear.

Lua has first class support for functions and actually supports functional programming unlike Python which cripples many techniques and where Javascript has broken lexical scoping. Lua uses metamethod programming to allow you to build functionality like classes; Javascript has prototype inheritance which is different than Python's classical inheritance. Each is just different; not necessarily more or less structured.

Also, never confuse simple for being primitive. Lua IS incredibly simple and elegant. But all the simple things in the language work together elegantly to allow for amazingly sophisticated things.

Re: Luvit – Asynchronous I/O for Lua

#18
post #12

Earlier quoted context omitted.

I thought Lua used a register based VM.

No, it's a stack machine. See http://www.lua.org/manual/5.1/manual.html#3

You're both right. It has a stack that it uses for callframes and local variables, but the opcodes have operands to directly reference variables on it by index. In other words, it treats all of the stack for a given callframe as a set of registers.

Re: Luvit – Asynchronous I/O for Lua

#19
post #6
post #2

For those interested, lthread now supports AIO. It's still in dev branch, but I'll be merging it soon: http://webmon.com/blog/2013/02/19/lthread-now-supports-userl... https://github.com/halayli/lthread/blob/dev/src/lthread_io.c

digressing from luvit... how does the stack copying technique (as used in lthread) compare to segmented stacks (as used in go)? The swap technique is very simple but I would assume that the stack copy shows up in profiles and is significantly slower than the segmented stack technique... Are there any benchmarks?

Segmented stacks will take much more space. One of the reasons I went with stack copy is because it allows me to create a million lthreads if I wanted without worrying about memory.

Lthread is in C, an environment where you control/manage your memory. Using slab allocators and high performance malloc like jemalloc, you can avoid allocating a lot of your variables on the stack and the stack copy will become minimal. In most of the production code I have running using lthread, stack copying is on the average of 300 bytes.

Re: Luvit – Asynchronous I/O for Lua

#20
I saw this and for a while I thought "Oh yeah, that's pretty cool, but why isn't the lua community into it?" Then I really looked into luasocket[1], which uses a this api called ltn12, based around dataflow programming concepts. In most respects this is a much much more elegant way of doing network programming than the node.js way. This is the sort of thing you would want to implement on top of node.js to make the callback hell easier to deal with- and compared to luasocket, luvit is a step backward. But this is the standard way of doing networking in lua.

[1]: http://w3.impa.br/~diego/software/luasocket/

Post reply on HN