scylladb / alternator-load-balancing

Various tricks, scripts, and libraries, for load balancing multiple Alternator nodes
Apache License 2.0
18 stars 11 forks source link

Overhaul Java load balancer #6

Closed nyh closed 3 years ago

nyh commented 3 years ago

This patch is an overhaul of the Java load balancer.

The main goal was to add support for v1 of the AWS SDK for Java, whereas the existing code only support v2.

README.md was also completely rewritten, to explain the two SDK versions and how to use them.

The v1 support is very different, and much simpler, than the old v2 implementation. The reason why the simpler implementation was possible is a different (and better) understanding of how SSL would be used in a load-balanced Alternator setup. The README.md suggests how we should simplify the v2 implementation to be like the new v1 implementation, but actually doing this is left to the future. We may want to do similar changes also to the implementations in other languages.

Additionally, the pom.xml was cleaned from unnecessary stuff, and building of the library and demos actually works now. The demo is built, but no longer part of the generated jar file - which only contains the minimum needed for applications - these of course don't need the demo.

The existing code also had errors dealing with various combinations of SSL and authentication checks, which this patch fixes.

In this patch, I replaced the separate GetItem/PutItem/CreateTable demos by one demo (Demo1.java for v1, Demo2.java for v2) which does a bunch of requests. It makes it easy to demonstrate how different requests in sequence contact different Scylla nodes.

NOTE: the code in this patch still has a lot of debugging printouts. These should be removed (or replaced by Java logging) in the future.

Signed-off-by: Nadav Har'El nyh@scylladb.com

nyh commented 3 years ago

@eliransin @slivne here is the AWS SDK for Java v1 support I promised for the load balancer.

@fruch if you still want to use the client load balancer in your Java v1 application, I'll be happy if you can try this. The README.md explains how to build the jar (trivial, mvn package) and how to use it (also very easy). If you have any comments on the documentation or how it works (or doesn't work), I'll be happy to improve it.

nyh commented 3 years ago

Oh, and I forgot to mention in the commit message that this fixes issue #5...

fruch commented 3 years ago

@nyh

Initial test hydra-kcl was working nicely with one local node.

I've commented out all the System.printf, we should have a better logging setup, or using a more common library, or adding a callback to the construct, to handle logging. throwing everything to stdout doesn't really help

nyh commented 3 years ago

@nyh

Initial test hydra-kcl was working nicely with one local node.

Thanks. I just realized something - do you also use this for DynamoDB streams? How, do you use the same RequestHandler also for the stream client? It should work, but I didn't think of trying!

I've commented out all the System.printf, we should have a better logging setup, or using a more common library, or adding a callback to the construct, to handle logging. throwing everything to stdout doesn't really help

Yes, I should switch to using trace-level logging messages, and only enable them in the demo. I'll do that.

nyh commented 3 years ago

@fruch @psarna @eliransin pushed a new version, with:

  1. Silly tracing printouts replaced by clean java.util.logging logging. The demos (Demo1.java and Demo2.java) enable the tracing messages, but ordinary applications will not.
  2. Deduplicated the AlternatorLiveNodes class (which maintains the list of live nodes). In the previous version of this PR, only the SDK v1 code used this class, and the v2 code uses another copy. In this PR, both use the same AlternatorLiveNodes code. This common code uses Java's HTTP features to avoid relying on either version of the SDK so the same code will work on both.
nyh commented 3 years ago

pushed a new version with "some.url.com" replaced by the same IP address example (https://127.0.0.1:8043) used later in the example.