Hands-On High Performance with Spring 5
eBook - ePub

Hands-On High Performance with Spring 5

Techniques for scaling and optimizing Spring and Spring Boot applications

Chintan Mehta, Subhash Shah, Pritesh Shah, Prashant Goswami, Dinesh Radadiya

Share book
  1. 408 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On High Performance with Spring 5

Techniques for scaling and optimizing Spring and Spring Boot applications

Chintan Mehta, Subhash Shah, Pritesh Shah, Prashant Goswami, Dinesh Radadiya

Book details
Book preview
Table of contents
Citations

About This Book

A hands-on guide to creating, monitoring, and tuning a high performance Spring web application

Key Features

  • Understand common performance pitfalls and improve your application's performance
  • Build and deploy strategies for complex applications using the microservice architecture
  • Understand internals of JVM - the core of all Java Runtime Environments

Book Description

While writing an application, performance is paramount. Performance tuning for real-world applications often involves activities geared toward detecting bottlenecks. The recent release of Spring 5.0 brings major advancements in the rich API provided by the Spring framework, which means developers need to master its tools and techniques to achieve high performance applications.

Hands-On High Performance with Spring 5 begins with the Spring framework's core features, exploring the integration of different Spring projects. It proceeds to evaluate various Spring specifications to identify those adversely affecting performance. You will learn about bean wiring configurations, aspect-oriented programming, database interaction, and Hibernate to focus on the metrics that help identify performance bottlenecks. You will also look at application monitoring, performance optimization, JVM internals, and garbage collection optimization. Lastly, the book will show you how to leverage the microservice architecture to build a high performance and resilient application.

By the end of the book, you will have gained an insight into various techniques and solutions to build and troubleshoot high performance Spring-based applications.

What you will learn

  • Master programming best practices and performance improvement with bean wiring
  • Analyze the performance of various AOP implementations
  • Explore database interactions with Spring to optimize design and configuration
  • Solve Hibernate performance issues and traps
  • Leverage multithreading and concurrent programming to improve application performance
  • Gain a solid foundation in JVM performance tuning using various tools
  • Learn the key concepts of the microservice architecture and how to monitor them
  • Perform Spring Boot performance tuning, monitoring, and health checks

Who this book is for

If you're a Spring developer who'd like to build high performance applications and have more control over your application's performance in production and development, this book is for you. Some familiarity with Java, Maven, and Eclipse is necessary.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Hands-On High Performance with Spring 5 an online PDF/ePUB?
Yes, you can access Hands-On High Performance with Spring 5 by Chintan Mehta, Subhash Shah, Pritesh Shah, Prashant Goswami, Dinesh Radadiya in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation en Java. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781788830638

Spring Boot Microservice Performance Tuning

In the previous chapter, we learned about Java Virtual Machine (JVM). Starting with the internals of JVM and Java's class-loading mechanism, we learned how memory management is performed in Java. The last section of the chapter focused on garbage collection and JVM tuning. The chapter was full of pretty important details for application performance optimization.
In this chapter, we will move toward solving performance problems. The approach is to develop microservices. Microservices are having a boom in the software development industry right now. There is a lot of buzz around microservices and related keywords. This approach basically works at an application-architecture level to tune the application's performance. It describes how we can improve application performance by setting up the architecture in a different manner. We will cover the following topics in this chapter:
  • Spring Boot configuration
  • Metrics with the Spring Boot Actuator
  • Health checks
  • Microservices using Spring Boot
  • Microservices with Spring Cloud
  • Spring microservice configuration example
  • Monitoring microservices with Spring Boot admin
  • Spring Boot performance tuning

Spring Boot configuration

In this section, we will focus on making Spring Boot work for us. Before jumping on to Spring Boot configuration, we will understand what Spring Boot is, why we should use it, and what Spring Boot brings to the table. We will move quickly to the how to do it part of it.

What is Spring Boot?

It is necessary for software development processes to be faster, more accurate, and more robust. Software teams are asked to develop quick prototypes for showcasing the application's features to prospective clients. The same applies to production-grade applications. The following are a few areas where software architects focus on to improve the effectiveness of development teams:
  • Use the right set of tools, which includes frameworks, IDEs, and build tools
  • Reduce code clutter
  • Reduce the amount of time spent writing repetitive code
  • Spend the majority of the time implementing business features
Let's think for a moment. Why are we discussing this? The reason is that this is the foundation for Spring Boot. These thoughts are the founding stones for the creation of any framework or tool that helps teams to improve their productivity. Spring Boot is found with exactly the same reason—to improve productivity!
With Spring Boot, it becomes easy to create production-grade applications that are powered by the Spring Framework. It also makes it easy to create production-ready services with minimal challenges. Spring Boot helps new and existing users get to their productive tasks quickly by taking an opinionated view of the Spring Framework. Spring Boot is a tool that facilitates creating a standalone Java application, which can be run using the java -jar command, or a web application, which can be deployed to web servers. The Spring Boot setup is bundled with command-line tools to run Spring programs.
The major goals of Spring Boot are:
  • To gain an extremely fast experience to get started with Spring-powered projects
  • Broad accessibility
  • Major support from out-of-the-box configuration
  • Flexibility to deviate from Spring default as the need may arise
  • That it does not generate any code
  • That it does not require XML configuration
Along with previously listed primary features, Spring Boot also provides support for non-functional features, listed as follows:
  • Support for versioning and configuration for widely known and used frameworks
  • Support for application security
  • Support for monitoring application health check parameters
  • Support for monitoring of performance metrics
  • Support for externalized configurations
Though Spring Boot provides defaults for the primary and non-functional features, it is flexible enough to allow developers to use the frameworks, servers, and tools of their choice.

Spring Initializr

Spring Boot applications can be kickstarted in multiple ways. One of the ways is to use the Eclipse-based Spring Tools Suite IDE (https://spring.io/tools/sts). Another way is to use https://start.spring.io, also known as Spring Initializr. First things first, Spring Initializr is not Spring Boot or an equivalent. Spring Initializr is a tool that has simple web UI support to configure the Spring Boot application. It can be considered a tool for a quick-start generation of Spring projects. It provides APIs that can be extended for customization in order to generate the projects.
The Spring Initializr tool provides a configuration structure to define a list of dependencies, supported Java and Spring Boot versions, and supported dependency versioning.
Basically, Spring Initializr creates an initial Spring project based on the configuration provided and allows the developer to download the project in a ZIP file. Here are the steps to be followed:
  1. Navigate to https://start.spring.io/.
  2. Choose the dependency management tool from Maven or Gradle.
  3. Choose the JVM-based programming language from Java, Kotlin, and Groovy.
  4. Choose the Spring Boot version to be used.
  5. Provide the Group artifact by inputting the group name as com.packt.springhighperformance.
  1. Input Artifact, which is the artifact ID for the Maven project. This will become the name of the project WAR or JAR file to be deployed or executed.
  2. Choose a packaging type from Jar and War.
  3. Click on the Switch to the full version link. This will open up a list of starter projects to choose from. The starter project will be explained in detail in the following section.
  4. Once we have chosen the starters or dependencies, click on the Generate Project button. This will download the ZIP file containing the initial project configuration.
The following is the Spring Initializr screen with a few configurations:
Once done, a folder structure similar to what is shown in the following screenshot will be generated:
Spring Initializr also supports the command-line interface to create the Spring project configuration. The following command can be used to generate a project configuration:
> curl https://start.spring.io/starter.zip -d dependencies=web,jpa -d bootVersion=2.0.0 -o ch-09-spring-boot-example-1.zip
As mentioned earlier, Spring Initializr supports integration with IDE. It integrates well with Eclipse/STS, IntelliJ ultimate edition, and NetBeans with NB the SpringBoot plugin.

Starters with Maven

In the preceding section, we looked at the Spring Initializr tool. It is time to quickly look at the starters or dependencies supported by Spring Boot.
Dependency management becomes challenging as the project grows in complexity. It is recommended not to manage the dependencies manually for a complex project...

Table of contents