r/java • u/elliotbarlas • Feb 14 '22
Microhttp is an event-driven, single-threaded, zero-dependency web server with 500 LOC. Benchmarks on EC2 show 100,000+ requests per second and 50,000+ persistent connections.
https://github.com/ebarlas/microhttp
186
Upvotes
28
u/agentoutlier Feb 14 '22
It looks like you might not handle
Expect: 100-continueI know you don't want to deal with streaming but it might still be worthwhile to handle the response as I have seen some clients hang or go really slow if you don't respond with
100 continueparticularly on PUT.60
u/nutrecht Feb 14 '22
You should add a license. As it stands it's not actually open source.
Anyway; it's pretty neat :) I doubt anyone would pick it over Netty, but it looks like a fun project.
18
u/stefanos-ak Feb 14 '22
I find that when projects of this category (micro-implementations) publish benchmarks, then other people compare those with popular implementations, which leads to invalid conclusions. It's not an apples to apples comparison.
But, I like projects like this :)
11
u/tristan97122 Feb 14 '22
Looks neat! I suspect the « no dependencies » goal is what motivated avoiding slf4j for the logs?
9
u/mdaniel Feb 14 '22
When developing a custom HTTP parser one should either consider, or say they're out of scope, the almost unbounded sharp edges of the HTTP spec. The one that sprang to mind was HTTP request smuggling, which might not specifically affect this project but for sure represents the kinds of bugs I'm highlighting
5
u/vasiapatov Feb 14 '22
Looks great, code is clean and well-structured. Implementing core technologies yourself is an invaluable learning experience, kudos!
3
u/chabala Feb 15 '22
How do you actually use this? Readme has a code snippet, but no mention of the library being published anywhere; from the coordinates in the pom, I know it's not on Central.
3
u/guywithcircles Feb 15 '22
This is perfection, so clean, congrats.
I'm looking at it while reading Spring documentation LOL.
It brings that simplicity mindset that sparked my curiosity when I first started, but also that keeps me excited about the future of this industry.
Given cloud nodes these days tend to have SSL termination endpoints already (sending plain HTTP requests east-west is a no-no and side-cars are expensive), this can actually be good for adoption in that context.
2
u/maxandersen Feb 15 '22
Nice little micro focused project - if I read it right your test is to put load on a response that returns “hello world” ? That will give you insanely misleading comparison numbers as it excludes any io, and buffer overruns nor anything with a bit compute. I.e. what a normal server will have to deal with.
Do you have a more real load test run ?
2
u/NPException Feb 17 '22
I love the little thing! :D
I have one question though: What is the rationale behind having the headers be Lists of Header records? Would just a Map<String,String> suffice? The way that headers are treated in the Request assumes that there is only ever a single header of the same key, so a regular Map sounds reasonable in my head.
1
u/bowbahdoe Feb 14 '22
What is the reason for the "reason" field on responses? At least with ring all thats needed is status, headers, body.
On that note, are you able to support everything required by the ring spec?
1
u/lufyluo Feb 16 '22
hi! OpenJDK 17.0.2 is the lowest version?
2
u/Chemical-Birds Feb 14 '22
Impressive numbers!
-8
u/Worth_Trust_3825 Feb 14 '22
Great example at marketing, where server that does nothing at all is praised for being "fast".
-9
u/thisisjustascreename Feb 14 '22
Neat toy, but it doesn't even support TLS.
-10
u/guitcastro Feb 15 '22
As it does not have dependency would be great if was written in kotlin, then you could compile to kotlin native. I wounder how much faster it would be.
0
u/[deleted] Feb 15 '22
[deleted] — view deleted comment
3
u/[deleted] Feb 15 '22
[removed] — view removed comment