Luvit – Asynchronous I/O for Lua
21–30 of 37 posts
Re: Luvit – Asynchronous I/O for Lua
#22Earlier quoted context omitted.
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. I…
Lthread is a cool experiment but coroutines in C is a dubious ideal. If you're writing a program in C/C++, presumably you want ultimate control and the fastest possible execution. You wouldn't introduce extra runtime complexity and a speed hit for easier to use APIs (blocking I/O functions). You'd just use epoll and non-blocking sockets (or libuv). That's not to say that coroutines/green threads/goroutines in high-level languages where you've already decided to take a speed hit for easier use isn't useful. Said another way: if your concern is about easy to read code, C is not the right choice; if your concern is speed: copying a stack on every i/o function is not the right choice.
Re: Luvit – Asynchronous I/O for Lua
#23Not 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,…
EDIT: Also, I just remembered that Lua started as a stack-based VM, but moved to register-based at around version 5. So you could be thinking of the old Lua, too.
Re: Luvit – Asynchronous I/O for Lua
#24Earlier quoted context omitted.
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. I…
Why less memory than segmented stacks? Lthread is a cool experiment but coroutines in C is a dubious ideal. If you're writing a program in C/C++, presumably you want ultimate control and the fastest possible execution. You wouldn't introduce extra runtime complexity and a speed hit for easier to use APIs (blocking I/O functions). You'd just use epoll and non-blocking sockets (or libuv). That's not to say that corouti…
Segmented stacks aren't possible in C, because you don't have control over the stack's growth and the MMU when a function is running.
Coroutines simplifies your code a lot compared to callbacks(via libuv, epoll) and with lthread, you barely have any performance hit if you don't have sizable variables on the stack. I've written web servers and proxies in lthread that performs as fast as nginx (and sometimes faster). I think that's a pretty good deal.
> You wouldn't introduce extra runtime complexity and a speed hit for easier to use APIs (blocking I/O functions).
Your program is running in a kernel. You already have lost a lot of performance, and the complexity got introduced. Kernel does a gazillion thing while running your program, so if you really want raw performance, make sure to run your code on a bare metal CPU without kernel intervention. But that's not convenient, hence you compromise, pay a penalty, and run your program in a kernel. But does that mean you might as well use a high level language because you compromised on performance? no.
> if your concern is about easy to read code, C is not the right choice
I disagree. They aren't mutually exclusive.
> if your concern is speed: copying a stack on every i/o function is not the right choice.
lthread doesn't copy a stack on every IO function call. The lthread stack is copied only after the socket blocks or it reached its fair share. Sometimes this means an lthread can do 2 to 5 calls before it yields. And when it yields, depending on how deep you are in your call, the stack gets copied from there. If you don't have big variables on your stack, the stack copy can be just few bytes. Note that it's not the whole scheduler stack that's copied (4MB by default), but only what was consumed by lthread (usually from few bytes to 300 bytes, it varies based on the code).
You are over-simplifying your choices to this: if you want performance, use C & callbacks otherwise use a high level language. There's a wide spectrum that you are missing out in this over simplification.
Re: Luvit – Asynchronous I/O for Lua
#25I 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 ca…
The idea sounds neat, but I'm wary of concepts that aren't seeing real-world use. Node.js has momentum, Luvit has a little bit of momentum, this? In the web development community, I've never heard of the approach, which suggests using it might be more DIY than I'd like. Also the copyright date is 2004-2007. Abandoned?
Re: Luvit – Asynchronous I/O for Lua
#26I'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…
Blogging about your experience using it would probably get you some decent traffic, too.
Re: Luvit – Asynchronous I/O for Lua
#27I'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…
Link to the project? I always like to see examples. Blogging about your experience using it would probably get you some decent traffic, too.
We're working on splitting this out into a reusable platform for writing lightweight host-based agents. Luvit works out fairly well for this - our monitoring agent runs in around 5mb resident memory, works on Windows (although we haven't released that yet) and is relatively easy to code on.
Shameless plug: if this sort of stuff interests you, hit me up, my email is in my profile.
Re: Luvit – Asynchronous I/O for Lua
#28I'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…
- Lua (as a language) is for the most part better designed than JavaScript
Re: Luvit – Asynchronous I/O for Lua
#29Earlier quoted context omitted.
Link to the project? I always like to see examples. Blogging about your experience using it would probably get you some decent traffic, too.
I suspect the project he's referring to is our monitoring agent: https://github.com/racker/virgo We're working on splitting this out into a reusable platform for writing lightweight host-based agents. Luvit works out fairly well for this - our monitoring agent runs in around 5mb resident memory, works on Windows (although we haven't released that yet) and is relatively easy to code on. Shameless plug: if this sort of…
Re: Luvit – Asynchronous I/O for Lua
#30I 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 ca…
Any good open-source (or closed) examples of web apps built on this? The idea sounds neat, but I'm wary of concepts that aren't seeing real-world use. Node.js has momentum, Luvit has a little bit of momentum, this? In the web development community, I've never heard of the approach, which suggests using it might be more DIY than I'd like. Also the copyright date is 2004-2007. Abandoned?
There is the Kepler project http://www.keplerproject.org/ , which appears to be much like the commonJS project for javascript- with luasocket at its core. Kepler project lists http://slimfastclinic.com/ and http://www.bestjuicer.biz/ as websites that were built with lua. (though they may be out of date since the slimfastclinic.com says it's wordpress)
It might also be worth pointing out, just as a side note, that mod_lua for apache has existed for a while https://httpd.apache.org/docs/trunk/mod/mod_lua.html