Auto-Scalable Payara Micro Cluster for Java EE Microservices
Auto-Scalable Payara Micro Cluster for Java EE Microservices
An advanced package has been developed to help make Payara Micro Cluster integration with Jelastic Platform smooth and quick.
Join the DZone community and get the full member experience.Join For Free
Maintain Application Performance with real-time monitoring and instrumentation for any application. Learn More!
Payara Micro is a minimalistic application server based on GlassFish 4.1 and with Java EE 7 support. Having just 70 MB footprint, this server is provisioned with Hazelcast for automatic clustering. Payara JCache, as a key-value store, benefits from the embedded Java API and simple management by allowing running WAR packages directly from command line. Payara Micro is optimized for microservices and modern container-based infrastructure. It can be easily run inside the cloud, providing automatic clustering for large-scale JavaEE applications.
To make Payara Micro Cluster integration with Jelastic Platform smooth and quick, a dedicated pre-packaged solution has been developed. It automates all the required installation steps, allowing to deploy and launch a fully-functional and highly scalable Payara Micro Cluster in a matter of clicks.
Jelastic Payara Micro Cluster Specifics
The advanced Payara Micro Cluster package contains the minimal required amount of nodes (containers) by default but includes all the necessary tools to scale horizontally based on the increased amount of incoming traffic.
This solution is built on top of Docker containers, leveraging the following images:
- jelastic/payara-micro-cluster: Payara Micro application server (1 instance by default to be automatically scaled out horizontally when the load raises).
- jelastic/haproxy-managed-lb: HAProxy load balancer, which automatically adds and removes application servers within load balancing configs when their number is changed.
- jelastic/storage: Dedicated Data Storage container for storing custom data; by default, it contains a simple load simulation application to test the main cluster scaling possibilities.
As a basic benefit of hosting at Jelastic Cloud Platform, all containers in this package are preconfigured to be automatically scaled vertically (up to 16 cloudlets by default, which stands for 6,400 MHz of CPU and 2,048 MiB RAM) based on the load. This allows you to utilize resource smartly, using just as much as it’s currently required.
Additionally, all servers within a cluster have special load alerts enabled to automatically send notifications when container capacity is almost at its limit. This indicates that more resources have to be allocated for a server or it should be scaled horizontally.
Obviously, all these predefined settings can be tuned up to your needs via the dashboard.
Quick Deploy of Payara Micro Cluster
Installation of the Payara Micro Cluster with all additional scaling configurations represents a completely automated process. All you need to do is import the corresponding project from the Jelastic JPS Collection at GitHub.
1. Import the URL
Click the Import button on the top pane of the dashboard and insert the JPS link in the URL tab.
Click Import at the bottom of the frame to proceed.
2. Specify Parameters
Within the appeared confirmation window, specify some general environment parameters for your cluster.
- Environment. Type the desired environment name to be used as an internal domain
- Display name. Alias that will be displayed for the environment within the dashboard.
- Region. Select the preferable hardware region (if available).
Click Install to proceed.
Wait a few minutes for Jelastic to automatically create all of the required instances and configure the cluster for future automation.
That’s it! Payara Micro Cluster with out-of-the-box automated scaling is successfully deployed and ready for work. Now, let’s check how it can cope with traffics of varying intensities.
Payara Cluster Load Testing and Scaling
The presented Advanced Payara Micro Cluster package is provisioned with a special inbuilt load testing application, which includes separate options for RAM and CPU loading. This tool is physically located on the Storage node and is automatically mounted to the app server layer upon cluster installation.
With its help, you can discover cluster scaling possibilities and check its behavior in real conditions of changeable load. To open the load test, access the following link using the appropriate domain name (either an internal or a custom one).
Depending on the resource type you’d like to simulate the load for (i.e. RAM or CPU), fill in the required parameters:
- Load: Amount of resources to generate (in % for RAM and threads for CPU).
- Duration: Testing time (in seconds).
Click on Run for the appropriate section.
1. Launch the Tests
So, let’s launch the tests one by one (we’ll use the settings from the image above) and explore the effect they cause:
CPU tests will be run in just two threads to simulate regular conditions of serving a few users and check the automatic vertical scaling. The average load, in this case, equals 11 cloudlets. This corresponds to approximately 4,400 MHz of CPU consumption.
For the RAM test, we’ll apply the moderate load (e.g. 80% of allocated memory) to increase the number of Payara Micro instances due to the automatic horizontal scaling being triggered.
When loading is finished, you’ll see the Calling GC string appear, means that Garbage Сollection is initiating as a part of the test. This JVM memory management tool automatically detects the amount of RAM that is no longer needed (in our case, it was used to handle load simulation) and frees it to reduce the spend.
2. See Results
To see the result, you can refer to the Statistics dashboard section for your Payara cluster and follow load changes visually, in the form of graphs. Keep in mind that they are built based on average values for the chosen Interval, thus diagram peaks can slightly differ from the text test output.
The CPU load graph (on the left) generally corresponds to the consumption values received during the test. Such load can be easily handled by a single Payara Micro Container.
As for the green RAM graph, its maximum value reaches about 1500 MiB. This implies execution of the corresponding predefined Memory horizontal scaling trigger, so the amount of Payara Micro Containers is automatically increased.
Tip: By referring to the environment Settings > Monitoring > Auto Horizontal Scaling section, you are able to tune any of the existing triggers or add new scaling conditions.
3. Track the Results
To track the results of horizontal scaling while running the tests, you can use the following built-in tools at Jelastic dashboard.
The Monitoring > Events History section within environment Settings stores details on scaling operations that were automatically executed based on preconfigured scaling triggers.
As you can see, the cluster scaled out up to two Payara Micro Nodes during the test we’ve handled and returned back to the single app server topology when the load fell.
The Log section allows you to track what actually happens in your Payara Micro Cluster during such scaling in/out. In particular, you can refer to:
- lb_manager.log at the HAProxy node to see the new hosts being automatically added to and removed from the load balancer routing.
- run.log within the application server layer to track the ongoing cluster activities.
Also, you’ll be notified of all scaling changes with the corresponding email messages.
In such a way, you can be sure that a Java application within your Payara cluster will be able to handle a diverse amount of incoming traffic without the necessity to keep an eye on its change. Moreover, this will be done with the highest efficiency, automatically adding new resources and servers on load spikes and removing the redundant ones during the time of inactivity, eliminating you from any manual reconfiguration mess.
Have any questions or comments for the further improvements? Need some additional assistance with the package installation or hosting? Let us know with a comment below or refer for the help from our technical experts at Stack Overflow.
Published at DZone with permission of Tetiana Markova , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.