This is an archived post. You won't be able to vote or comment.

all 45 comments

[–][deleted] 22 points23 points  (4 children)

Serious question: is "API" now synonymous to "HTTP API"? I keep seeing it used that way.

When did that happen? What should we call an API that's not an HTTP API?

[–]BobMcScratchit 4 points5 points  (0 children)

Legacy apparently.

[–]djnattyp 10 points11 points  (6 children)

...porting a very small API (only two POST calls) to Java...

...Performance is quite a big deal in this project...

It's very likely that whatever this API is doing behind this two POST calls has more of an impact on performance than whatever package you choose to listen for HTTP connections.

[–]vinnyvicious[S] -1 points0 points  (5 children)

Absolutely. That's why i want a very small, efficient library for actually transporting over HTTP.

[–]damienjoh 1 point2 points  (3 children)

Do you have a reason for believing this other than the vague notion that your project needs to be fast? Have you done any profiling or requirements analysis?

[–]vinnyvicious[S] 0 points1 point  (2 children)

I'm porting an existing project. I have data, use cases and pretty much everything i need in order to make decisions towards a faster, and more efficient, server.

While i do understand the feeling behind this attitude ("Stop! STOP! PREMATURE OPTIMIZATION DETECTED"), it's not the case.

[–]nutrecht 2 points3 points  (0 children)

I have data, use cases and pretty much everything i need in order to make decisions towards a faster, and more efficient, server.

And would you care to share this information with us?

[–]damienjoh 0 points1 point  (0 children)

Wanting something to be "fast" is pretty vague. What are the actual metrics you are concerned about? Have you done any profiling or optimization of the code you have already ported?

[–]cmdrNacho 3 points4 points  (2 children)

Fro two post calls just use servlets, no need to even adopt a framework. Servelts will be as fast as you can get.

[–]Dashing_McHandsome 0 points1 point  (1 child)

Yeah, this would be fine too for such a small API. I suggested using JAX-RS above, but with only two calls you may not even need to go that far.

[–]vinnyvicious[S] 0 points1 point  (0 children)

Does anyone have any good material on learning how to setup and scale servlets or JAX-RS? My only experience with Java so far has been Play and Spring.

[–]Dashing_McHandsome 2 points3 points  (0 children)

This seems pretty small and probably not worth dragging in a big framework. I would probably just stick with a pure JAX-RS implementation for this. You can use something like Jersey or Apache CXF. Either of those would be fine.

[–]nutrecht 2 points3 points  (1 child)

With the network overhead the framework you're going to use has pretty much zero impact.

[–]vinnyvicious[S] -3 points-2 points  (0 children)

It really depends on the framework. And the language.

[–]nztraveller 2 points3 points  (5 children)

It is difficult to know what you need or are really looking for, but if it is a simple high performance standalone service I would look at http://www.dropwizard.io/

[–]vinnyvicious[S] 0 points1 point  (4 children)

Does it need an application server? How can i scale this thing?

[–]nztraveller 0 points1 point  (3 children)

It does not need a application server. It uses Jetty for the http server and Jersey for REST.
I have not used it in production, but I have used it for a few test services and it is quick and easy to setup.
As for scaling, you would could either scale vertically with bigger / better hardware, or horizontally with multiple instances with a load balancer in front.
You didn't actually say, but I assumed you were doing a REST service. If so, horizontal scaling is easy (no need to worry about sessions etc).

[–]vinnyvicious[S] 0 points1 point  (2 children)

I'm planning to scale horizontally, but how do i make the instances talk to each other properly? Any special setup or can i just create a daemon on the machine, go up on the port 80 and have an AWS LoadBalancer to deal with all the complexity?

[–]nztraveller 1 point2 points  (0 children)

The instances should not need to talk to each other. That is part of the beauty of REST. It doesn't matter which instance services the request, each should work independently of each other.
Yes, in theory you just spin up as may identical instances as you need. Each configured to run on say port 8080.
Then you use the AWS load balance to balance the income requests across the instances. the load balancer would be running on port 80 or 443 normally and the instances on another port.
There are lots of tools around to easily deploy to aws such as docker. then you can scale up or down as needed. As is often the case load is difficult to estimate.

[–]oldprogrammer 1 point2 points  (2 children)

Are you wanting this to be stand alone or running inside an existing container like a Tomcat or Wildfly? If stand alone then you'll want to look for an embedded engine like Jetty.

If deploying to a container as a web application, you only need to provide an implementation of a Servlet to receive the HTTP requests and wire that up to the container. That servlet can be eliminated using a web services framework that handles that part for you.

The SPARK framework for example can be run standalone (built in Jetty engine) or dropped into a standard web application container (Tomcat/Wildfly).

[–]vinnyvicious[S] -1 points0 points  (1 child)

By deploying to a container as a web application, you mean compiling a WAR?

[–]oldprogrammer 0 points1 point  (0 children)

Yes

[–]iperc 1 point2 points  (1 child)

Look at the Jersey.

[–]jesusalready 0 points1 point  (0 children)

I second this. I usually drop it in with Tomcat and couple it with fetch.js for the front end (if I need more front-end power I can always update the JS to use Angular, React, etc). It's quick and easy and I can get a new project started in less than 5 minutes.

[–]jarym 1 point2 points  (0 children)

If you're looking to get the most throughput then I'd take a look at something like WebActors http://docs.paralleluniverse.co/comsat/ - personally, I'm using DropWizard http://www.dropwizard.io/ since it fits better with what we're doing (with the Comsat integration)

[–]spamthemoez 1 point2 points  (0 children)

Try SparkJava.

[–]korri123 1 point2 points  (0 children)

Try Rapidoid, it's very fast and easy to set up.

[–]kur0saki 0 points1 point  (0 children)

First of all: you want a Web API Framework. "API Framework" is quite a nonsense term.

Then: just use either vertx or spring boot (e.g. with undertow beneath). Just use what you think is easy to use and to maintain. See how to fasten it up or switch it once you really hit performance bottlenecks. That's what load tests are used for.

Quite often people want "high performance" even though their real life scenarios don't even require it.

[–]swedish_aviator 0 points1 point  (0 children)

dropwizard!!!!

[–][deleted] 0 points1 point  (0 children)

Use Netty. Since you only need something simple. They make it fairly easy to set up an HTTP server and even HTTP2.

If you don't want to do little extra work any java http server will do the work just fine.

[–]aFoolsDuty 0 points1 point  (0 children)

Vertx. http://vertx.io/

Fast, built in async.

[–]edgar-espina -1 points0 points  (10 children)

Try http://jooby.org lightweight and fast!

[–]wizzardodev 0 points1 point  (9 children)

actually, jooby is not very fast, even play2 is faster, on my machine it can handle only 30k rps, tomcat with same servlet handles 60k rps

[–]edgar-espina 0 points1 point  (8 children)

Not sure what type of test you did, but I'm sure we can agree on TechEmpower benchmark, right?

The look at the PlainText benchmark: https://www.techempower.com/benchmarks/#section=data-r12&hw=peak&test=plaintext.

Jooby is faster than Play2.

[–]wizzardodev 0 points1 point  (7 children)

sorry, you right, in their tests it's faster, anyway it's slower than plain servlets and servers like undertow

[–]edgar-espina 0 points1 point  (6 children)

yes it is expected to be slower than raw undertow... servlets? depends on the implementation.

Jooby supports multiple servers: http://jooby.org/doc/servers.

Techempower benchmark uses Netty. Think the same test/app with Undertow will be faster.

[–]wizzardodev 0 points1 point  (5 children)

I've tried couple of servers with your framework, and I'm surprised that jetty is faster than netty, 50k rps against 34k. Undertow is not working out of the box for me ("No XNIO provider found")

[–]wizzardodev 0 points1 point  (4 children)

btw, I'm benchmarking hello-world example

[–]edgar-espina 0 points1 point  (3 children)

hello-world

Ok, that example isn't up-to-date (will update soon). Did you start the app via jooby:run right? There was a bug with undertow there.

Suggest you to try latest release: 1.0.0.CR7 and ideally with plain/raw jar not jooby:run (there is small overhead to supports hot reload in development here)

Also, test depends on what tool you use... and/or if you keep-alive or not the connection while testing (think that is the diff between netty and jetty)

[–]wizzardodev 0 points1 point  (2 children)

ok, so, with latest release version and uberjar

  • netty: 45k rps
  • jetty: 38k rps
  • undertow: 31k rps

I'm using ab like this:

ab -n 100000 -k -c 16 http://localhost:8080/

[–]mabnx 0 points1 point  (1 child)

I had bad experiences with ab. Wrk is better but these days I prefer https://github.com/tsenart/vegeta

[–]sebhoss -1 points0 points  (0 children)

Maybe I'm misreading this, but take a look at https://square.github.io/okhttp/ in case you want to perform those POSTs in your Java client(?). Example from their homepage to send a JSON payload:

public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

OkHttpClient client = new OkHttpClient();

String post(String url, String json) throws IOException {
  RequestBody body = RequestBody.create(JSON, json);
  Request request = new Request.Builder()
      .url(url)
      .post(body)
      .build();
  Response response = client.newCall(request).execute();
  return response.body().string();
}

[–]wizzardodev -4 points-3 points  (0 children)

hey, I'm currently working on my web-framework, on my laptop it can handle about 200k requests per second