News for hackers. Stuff that matters.
Re:Jodd – The Unbearable Lightness of Java by spuz on Monday January 17, 2022 @05:50PM (#29972603)
I wonder if someone can recommend a lightweight http server library? I like Javalin but it's based on Jetty which is a fully JavaEE compliant framework and includes support for things like OSGI which I don't need. With the whole Log4j situation, I'm re-evaluating some the libraries I've previously relied on.
Re:Jodd – The Unbearable Lightness of Java by AmpsterMan on Monday January 17, 2022 @06:47PM (#29973037)
If you have Java 11+ I presume you can't get any simpler than a standard library module:

https://docs.oracle.com/en/java/javase/17/docs/api/jdk.https...

Re:Jodd – The Unbearable Lightness of Java by nayuki on Monday January 17, 2022 @07:14PM (#29973235)
This comes from way before SE 11. I was using it in 7. The doc says it comes from 6. https://docs.oracle.com/javase/7/docs/jre/api/net/httpserver...
Re:Jodd – The Unbearable Lightness of Java by AmpsterMan on Tuesday January 18, 2022 @11:00AM (#29981069)
Oh neat. I erroneously thought it might have come in part with the http module in 11.
Re:Jodd – The Unbearable Lightness of Java by vips7L on Tuesday January 18, 2022 @09:20AM (#29979480)
That server is no where near production ready.
Re:Jodd – The Unbearable Lightness of Java by 14u2c on Monday January 17, 2022 @06:33PM (#29972942)
Vert.x

It's built on top of Netty but has some additional niceties that make it more practical to use. It's also one of the fastest things out there: https://www.techempower.com/benchmarks/#section=data-r18&hw=...

Re:Jodd – The Unbearable Lightness of Java by mooreds on Monday January 17, 2022 @06:03PM (#29972715)
We looked around since we wanted to move off Tomcat and decided on Netty: https://netty.io/

I'm not on the engineering team so can't speak to the cost/benefit, but it seems to have been a pretty successful transition.

Re:Jodd – The Unbearable Lightness of Java by winrid on Monday January 17, 2022 @06:19PM (#29972848)
EDIT - it seems maybe I was wrong here

Netty copies the response body when sending to each client, so it's not as lightweight as I've found. For streaming large response bodies, it does not work well. I haven't found a good Java alternative yet (probably will switch to C++ and uWS...)

Re:Jodd – The Unbearable Lightness of Java by WatchDog on Monday January 17, 2022 @06:46PM (#29973032)
Netty core is about as close to the metal as networking gets on the JVM. It's abstractions are built over a zero-copy capable byte buffer, and there is generally a lot of care taken to avoid copying where possible. I haven't used the websocket codec, but I'm sure the maintainers would welcome a patch that removes unnecessary copying.
Re:Jodd – The Unbearable Lightness of Java by winrid on Monday January 17, 2022 @07:32PM (#29973393)
Here's what I was thinking of, under "Vert.x Memory Usage": https://www.tikalk.com/posts/2018/04/30/vertx-memory-usage-w...

Quote: "But how does Netty do things so fast ? One of the reasons is that it is using native memory pool to store network buffers. If you did some file reading or network action with Vert.x you probably used io.vertx.core.buffer.Buffer class. This class is actually a wrapper around Netty io.netty.buffer.ByteBuf class. Why am I telling you all this ? Let assume that you have a service where clients are downloading 20Mbyte files. Netty will have to allocate at least 20Mbyte for every connected client."

Although this may be an issue with how Vert.x is using Netty. I have to dig into it more.

Re:Jodd – The Unbearable Lightness of Java by WatchDog on Monday January 17, 2022 @10:24PM (#29974661)
FWIW, here is a fairly minimal example[0] of broadcasting over websockets reusing the same buffer.

I'm not very familiar with vert.x(not a netty expert either), but I think the author of that article is ascribing blame to the wrong place.

[0]: https://github.com/juggernaut/netty-websocket-broadcast-exam...

Re:Jodd – The Unbearable Lightness of Java by winrid on Monday January 17, 2022 @10:41PM (#29974809)
Not using websockets, but thanks! I have to look into it again. Right now the service is working fine so I haven't been motivated to work on it again. (in-memory CDN based on vertx-web + Caffeine + custom on-disk LRU cache)
Re:Jodd – The Unbearable Lightness of Java by mycall on Monday January 17, 2022 @10:02PM (#29974514)
> zero-copy capable byte buffer

This is similar to .NET Standard 2.1 Span<T>?

Re:Jodd – The Unbearable Lightness of Java by bullen on Monday January 17, 2022 @06:30PM (#29972918)
Re:Jodd – The Unbearable Lightness of Java by inyorgroove on Monday January 17, 2022 @09:44PM (#29974379)
Very Sinatra like: https://sparkjava.com/
Re:Jodd – The Unbearable Lightness of Java by xmodem on Tuesday January 18, 2022 @05:45AM (#29977365)
also not actively maintained sadly.
Re:Jodd – The Unbearable Lightness of Java by vbezhenar on Tuesday January 18, 2022 @05:29AM (#29977260)
https://github.com/NanoHttpd/nanohttpd

A bit outdated and not actively maintained, but it's truly small.

If you like async stuff, take a loot at Helidon.

Re:Jodd – The Unbearable Lightness of Java by pabl0rg on Monday January 17, 2022 @06:12PM (#29972791)
If you’re on Kotlin, consider http4k

It can use netty, undertow, and others under the hood

Re:Jodd – The Unbearable Lightness of Java by dopidopHN on Monday January 17, 2022 @09:42PM (#29974365)
OkHTTP or netty.
Re:Jodd – The Unbearable Lightness of Java by grishka on Tuesday January 18, 2022 @05:48AM (#29977380)
Okhttp is a client, but a good one.
Re:Jodd – The Unbearable Lightness of Java by dopidopHN on Tuesday January 18, 2022 @07:49PM (#29988396)
My bad, absolutely, not sure where my head was.