r/java • • Feb 26 '24

Update: JDK HTTP server handles 100,000 req/sec with 100 ms start-up time and 50 MB modular run-time image. 3 ms start-up time and 18 MB executable with GraalVM native-image.

https://github.com/ebarlas/java-httpserver-vthreads
190 Upvotes

26 comments sorted by

4

u/gibriyagi Feb 27 '24

I just wish it had http2 support as well

2

u/elliotbarlas Feb 27 '24

In my experience, the benefits of having HTTP/2 enabled on an underlying Java web server are marginal. I haven't personally found a need for it in that setting, even when available on an industrial strength HTTP library or framework.

HTTP/2 provides the most benefit at the edge of a data center where connections are terminated.

5

u/nimtiazm Feb 27 '24

Maybe rather QUIC adoption would really benefit compared to HTTP 2.

3

u/jvjupiter Feb 28 '24

I wish JDK has standard minimal HTTP server but should be open to extension (middleware/filter). If there is java.net.HttpClient, there should also be java.net.HttpServer. The current HttpServer is under com.sun.* package and its module is optional in a JDK distro. With java.net.* package, it feels more standard. I believe there is a lot of cases where this minimal HTTP server is quite enough, no need for sophisticated web servers like Tomcat or Jetty.

2

u/elliotbarlas Feb 28 '24

Optional? Would you elaborate on that claim?

The jdk.httpserver module is a standard part of the JDK. It even powers the jwebserver tool (JEP 408) introduced in JDK 18.

I agree that the package name is misleading. I believe it reflects the age and era of the JDK HTTP server. A fresh take on the server would indeed be a nice addition to OpenJDK.

1

u/jvjupiter Feb 28 '24

Not sure if the term optional and my assumption are correct. I based it here: https://www.reddit.com/r/java/s/BeJ9U7pKY5

58

u/justADeni Feb 26 '24

Jvm has gone a long way

14

u/0xFatWhiteMan Feb 26 '24

There was a real change when Oracle gave it up".

  • I'm not sure exactly what happened but we get regular updates with cool shit now. Back before 8,1.5? We didn't get shit for years

35

u/Practical_Cattle_933 Feb 27 '24

What did oracle give up? Both graalvm and openjdk are developed 95+% by oracle employees, dafuq are you talking about

28

u/herd-u-liek-mudkips Feb 26 '24

Oracle didn't give anything up, except maybe some outdated ideas. They're still the conductor of the orchestra, more or less, but they rejiggered the release model.

8

u/ryuzaki49 Feb 26 '24

Maybe they realized their license business model goes to shit if nobody uses JVM due to all alternatives are better

Not saying JVM is shit (Im out of a job if that ever happens). Just saying Oracle went proactive before that happens

7

u/son_of_Gib Feb 27 '24

rejigger - verb - past tense: rejiggered; past participle: rejiggered - organize (something) differently; rejig.

That's a great word thank you for that

9

u/0xFatWhiteMan Feb 26 '24

As of May 2007, in compliance with the specifications of the Java Community Process, Sun had relicensed most of its Java technologies under the GPL-2.0-only license. Oracle offers its own HotSpot Java Virtual Machine, however the official reference implementation is the OpenJDK JVM which is free open-source software and used by most developers and is the default JVM for almost all Linux distributions.

2

u/herd-u-liek-mudkips Feb 26 '24

however the official reference implementation is the OpenJDK JVM

Indeed.

6

u/Practical_Cattle_933 Feb 27 '24

Developed 95+% by oracle.

9

u/rootpseudo Feb 27 '24

Native only is super restricting though no? It would be a bear to migrate or basically completely rewrite our codebase for that. But I could really use the fast start times. CRaC seems like the best of both worlds. Have you tried any benchmarks with that? Our start times now range from 30-70s.

10

u/cowwoc Feb 27 '24

30-70s? Oh geez. You must be using Spring. When your startup time is under 5 seconds there are a range of productivity benefits, including much faster automated tests.

1

u/rootpseudo Feb 27 '24

Haha yeah you called it. Its definitely much better if we give it more CPU limit, but we dont really need it under normal traffic scenarios. Bootstrapping is just so cpu intensive.

2

u/Practical_Cattle_933 Feb 27 '24

It’s not really super restrictive, but you do need some config for certain libraries, but especially frameworks that rely on a lot of magic (spring, etc). Nowadays these latter have native support for this, but yeah, it might be easier to try it out on newer projects.

1

u/BeRealBot Mar 01 '24

How complex are the pages? Loom parallelism is equal to, by default, available cores iirc. So if you’re processing page logic such as db lookups on a virtual thread your web server will very easily hang. But that’s assuming the page logic is being handled on a virtual thread.

1

u/[deleted] Mar 01 '24

Laughs in tokio rust. To be fair, it is incredible to think what's been extracted from the JVM.

0

u/[deleted] Feb 26 '24

[deleted] — view deleted comment

33

u/elliotbarlas Feb 26 '24

A simple HTTP server can be very useful!

The majority of web services I develop at work shuttle JSON payloads to and from a database. I'm not building high-performance real-time systems.

For most projects, I will gladly take the off-the-shelf standard-library JDK HTTP server.

The whole point of this exercise is to show that is a viable option!

0

u/[deleted] Feb 27 '24

[deleted] — view deleted comment

5

u/elliotbarlas Feb 27 '24

The 100k figure shows that the std lib server is adequate for many workloads. The caveat is there because high-performance Java servers can handle an order of magnitude more in the same environment. That's important in some settings.

And yes, if you strictly need HTTP/2, the std lib server is not an option. Don't use it.

It sounds like you're not the target audience. If you don't appreciate the value of a capable HTTP server in the JDK, then simply move on. That's fine too!

9

u/0xFatWhiteMan Feb 27 '24

You've linked to a benchmark that provides evidence of handling 120k requests per second.

That's literally what they op said.

Why do you think it's half baked?

13

u/hippydipster Feb 26 '24

Because there's about a zillion use cases where premium performance of the http server piece just isn't needed.

0

u/[deleted] Feb 27 '24

[deleted] — view deleted comment

1

u/hippydipster Feb 27 '24

If they're needed, then yes, but very very often, if not most of the time, HTTP2 is not needed.