#17 How to cold start fast a Java service on K8S
The Curious Case of JDK9 Immutable Collections. Your path to Black Belt begins here: Java, MongoDB and Karate DSL. Backpressure explained. Asymptotic Notation
Welcome to the seventeenth Dukesletter edition!
I do not fear computers. I fear lack of them
—Isaac Asimov
How to cold start fast a Java service on K8S
When you deploy an application in Kubernetes you must follow some good practices to be a good citizen.
You must configure your needed resources, but what is more important: signal to Kubernetes that your application is alive and that is ready to receive requests.
To explain these concepts and more related to autoscaling and limits, Igor Domrev has written an article: “How to cold start fast a Java service on K8S”.
If you are deploying to a container remember to configure correctly the memory assigned to the JVM, making it proportional to the available memory in the container, using the new +XX:MaxRAMPercentage
configuration parameter. You can read more about it in this article: “JVM in a Container”.
The Curious Case of JDK9 Immutable Collections
Usually, new features are not free and come with some kind of tradeoff. This is the case of the new Factory Methods for Collections introduced in JDK 9.
These new factory methods instantiate new List, Map and Set collections, but implement the defined interface, and don’t behave exactly like ArrayList, HashMap, or HashSet implementations.
To learn the limitations of these collections I recommend you to read this post: “The Curious Case of JDK9 Immutable Collections” by Grzegorz Piwowarek.
I fell into this problem recently asking indirectly if Set.of(“a”,“b”).contains(null)
Usually is a bad practice to include null as a valid value in a collection. You must avoid it and it is preferable to use a null object.
Your path to Black Belt begins here: Java, MongoDB and Karate DSL
Karate is the Swiss Army Knife of functional and performance tests. Cover a lot of aspects of testing, providing an easy syntax and tooling.
In Clarity, we use it to develop the functional tests for our internal and public APIs, and our teammate, Ana Marija, has written an article explaining how we use Karate DSL: “Your path to Black Belt begins here: Java, MongoDB and Karate DSL”.
She emphasizes and explains how to communicate with a database (in our case MongoDB) to configure the scenario for the SUT or to verify some side effects not verifiable by the response.
Even though Karate is implemented with JavaScript as the language for the DSL, you can import and execute any Java code present in the classpath, like any other Java project, and is executed as another JUnit test.
If you are interested in Karate I suggest to continue with this video, where the creator of the tool explains all of its features:
Backpressure explained
When you start reading about reactive programing you see a lot the term “Backpressure”, but it is not explained in detail why it is a problem and how these frameworks (RxJava, Project Reactor, or Akka) help to solve the problem.
In “Backpressure explained — the resisted flow of data through software”, Jay Phelps explains what is Backpressure and different strategies to deal with it.
If you want to experiment and see the problem in action with RxJava code, you can continue with the following article from Baeldung: “Dealing with Backpressure with RxJava“
Asymptotic Notation
This is the typical diagram you should have in your mind when you are programming an algorithm. How is the complexity? Can N grow in an unexpected way?