14 ms·
Lwan: A high-performance and scalable web server
- kjeetgill 8y agoJeez this is amazing. Just end to end, rock solid engineering. I came to chime in that this basically hits all the same design beats as go with it's standard library (relatively low foot print, compiled binary, async user-space threading, etc.) But that sells this work short. This is amazing work!
- acidx 8y agoThank you! Although I've used a lot of tricks I've learned over the years in this project, I took a lot of inspiration from Go.
- le-mark 8y agoI agree with the caveat I didn't read anything similar to go's work stealing thread scheduling, useful for tasks with synchonized IO for example. What appeals to me is the Lua integration. I'd love for a Lua application server to become widely available. The http servers out there now don't really fit the bill for (Xavante, Luvit for example).
- acidx 8y agoYes, Lwan's thread scheduler is pretty simple, and can be borderline useless if a thread blocks. This 2014 blog post has more details; not much in that regard has changed since then: https://tia.mat.br/posts/2014/10/06/life_of_a_http_request.html https://tia.mat.br/posts/2014/10/06/life_of_a_http_request.h...
- kraftman 8y agoWhat's wrong with openresty?
- le-mark 8y agoFYI "what wrong with X?" is not the same conversation as "Are you familiar with X? It has these great features ...". Great that you want to promotoe you're favorite tech, but there are more effective ways to do it.
- MrBuddyCasino 8y agoNote: this is not related to the phony GWAN project, except maybe to poke fun at it. Previously: https://news.ycombinator.com/item?id=11373719 https://news.ycombinator.com/item?id=11373719
- agumonkey 8y agoAlso note the weird initial drawn term... must be a very fun oriented team
- deleted 8y ago[deleted]
- acidx 8y agoYes. Team. http://www.commitstrip.com/wp-content/uploads/2014/05/Strip-Vision-Open-source-650-finalenglish.jpg http://www.commitstrip.com/wp-content/uploads/2014/05/Strip-...
- deleted 8y ago[deleted]
- ksec 8y agoI wonder how does this compare to H20.[1] [1]https://h2o.examp1e.net/index.html https://h2o.examp1e.net/index.html
- acidx 8y agoDepends how you measure it. A long time ago I benchmarked it, and Lwan came out on top, performance-wise. However, performance isn't the only thing that matters in a piece of software like this. H2O is a great project; in fact, the authors were tightly involved in the definition of HTTP/2.0, and it is one of the first servers to support this version of the protocol. It is well written, and easy to grok the code. Some of its byproducts include a nice (and reusable) HTTP parser library, and clever tool named qrintf (that pre-parses the format string passed to printf()-family functions and generates optimal code for that). Also, there's a company behind it -- Lwan is just a toy I work on the weekends when I feel like it.
- LearnerHerzog 8y agoLwan... that's the best name they could come up with?
- acidx 8y agoAuthor here. It's a pun on another similarly-named web server. It's a terrible name, and I should have searched the web before, but it's too late now.
- MaxBarraclough 8y agoLooks neat! Is HTTPS support in the works?
- acidx 8y agoIn the works? No. Planned? Yes. I've been playing around with kTLS/BearSSL but so far I haven't made any stride. PRs, my inbox, and the IRC channel are open, though!
- baldgeek 8y agoCan anyone chime how this compares to nginx and openresty? Probably a dumb question , but I hope to gain some insight
- cntlzw 8y agoI am only a spare time C coder myself and was surprised that I can follow the code. Nice! Any reason why typedef struct is avoided?
- acidx 8y agoThanks! Code readability is important: not only for others (it's an open source project, and contributions are welcome!), but for myself... I have terrible memory. :) The reason struct typedefs are avoided is because I prefer to be explicit (the "Zen of Python" isn't just for Python!). It's also common practice in most of the projects I work on, and it's not much of an issue for me as far as a little bit of typing goes: I'm a fast typist.
- kibibu 8y agotypedef struct adds extra stuff to the global namespace. The Linux style suggests avoiding it: https://www.kernel.org/doc/html/v4.10/process/coding-style.html#typedefs https://www.kernel.org/doc/html/v4.10/process/coding-style.h...
- nine_k 8y ago> Low memory footprint (~500KiB for 10k idle connections) > Small disk footprint: x86-64 executable has 110KiB (~52KiB if packed with UPX) > No copies between kernel and userland for files larger than 16KiB Looks perfect for embedded stuff (and generally impressive). It needs a separate TLS terminator, though.
- acidx 8y agoYes, the small footprint was a deliberate choice, specifically for the embedded scenario. One of the things I did back in the day was to run Lwan+Lua on an Intel Galileo board, without an SD card (it has only 4MB of flash memory, which has to fit the Linux kernel, some minimal userland, and Lwan+Lua). TLS is hard given the current architecture, but I've been investigating kTLS, so maybe it'll happen someday. I would appreciate help on this front, though.
- petee 8y agoIf you haven't seen, openbsd added a new api to simplify tls programming, "as a response to the unnecessary challenges other APIs present in order to use them safely." I don't know how portable it is yet though https://man.openbsd.org/tls_init.3 https://man.openbsd.org/tls_init.3
- acidx 8y agoAh, yes, I'm very aware of libtls. The API is indeed nice, but it would require some changes in Lwan that I'd rather avoid; for instance, every socket call would need to be virtual, and it would not be possible to use something like sendfile() or mmap() a file and writev() it to the socket. I'd like to use BearSSL, which is a nice, clean implementation of TLS, makes no memory allocation (so it fits Lwan architecture very well)... but only for the initial connection handshake; I'd then hand over TLS to the Linux kernel with kTLS (https://netdevconf.org/1.2/papers/ktls.pdf https://netdevconf.org/1.2/papers/ktls.pdf). However, there's not much beyond some tests in that front.
- 8y ago
- paulsutter 8y agoSeastar does up to 8 million connections per second, performance due in part to a user mode TCP stack Previous discussion: https://news.ycombinator.com/item?id=9440886 https://news.ycombinator.com/item?id=9440886
- acidx 8y agoThe authors of Seastar used to use Lwan to benchmark their HTTP server implementation. When Seastar isn't using DPDK/usermode TCP stack, and drops to the POSIX API, Lwan is still faster.
- paulsutter 8y agoYes. And in other news a bicycle is faster than a Ferrari with no engine EDIT: touché! i agree!
- acidx 8y agoCurious that you compare Seastar with a Ferrari: those cars are known for an internal finish that's not compatible with their price tag... and Seastar is nothing like that. It's a seriously well engineered piece of software, and it shows: its readability and code quality is superb.
- dom96 8y ago> For Round 10, Lwan has taken the crown. But we expect the other top contenders won't leave this a settled matter. Am I just blind or is Lwan missing here: https://www.techempower.com/benchmarks/#section=data-r10&hw=ph&test=json https://www.techempower.com/benchmarks/#section=data-r10&hw=...
- acidx 8y agoIt's a known issue with TWFB. I don't know if they're planning on fixing it, but most frameworks that are not in newer rounds are not appearing in older rounds any longer.
- dom96 8y agoOh, that's a shame. Why is lwan no longer in the newer rounds?
- acidx 8y agoBecause I failed to move the benchmark harness from the Lwan repository to the TWFB repository. Also, I'm not really spending a lot of time on Lwan any longer; there are so many things I'd like to do, and so little time. :)
- maxpert 8y agoAmazing I am planning to shift RaspChat on this. Would be nice if same engineering effort can be put into WebSocket. This will make it much more desirable everywhere to build pub/sub systems.
- acidx 8y agoThere is SSE, which, although unidirectional, can be used in lieu of websockets for a chat application (receive messages/events via SSE, send via another endpoint). However, as I said before, this is an open source project; if you have an itch, you can scratch it. PRs are open. :)
- saganus 8y agoWhat is SSE in this context?
- acidx 8y agoServer-sent events: https://en.wikipedia.org/wiki/Server-sent_events https://en.wikipedia.org/wiki/Server-sent_events https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events https://developer.mozilla.org/en-US/docs/Web/API/Server-sent...
- tpaschalis 8y agoImpressive all and all, even more for being written in (grokkable!) C. Nice work.
- mitchtbaum 8y agoLwan used to be at the top on Techempower Benchmarks, but I don't see it anymore. I do however see a Rust webserver, called Actix-Raw, which tops the list. acidx, what do you think of that project?
- acidx 8y agoI'm not aware of it. I'm learning Rust (just bought the "The Rust Programming Language" book, FWIW), so I will check it out.
- bullen 8y agoCool, if you want something similar but in Java: https://github.com/tinspin/rupy https://github.com/tinspin/rupy
- openbasic 8y agoWould you recommend this to serve a C++ webservice, or should we stick with boost::asio?
- equalunique 8y agoIs this in any way related to the proprietary G-WAN high-performance and scalable web server? http://gwan.com/ http://gwan.com/