Wednesday, November 14, 2018

Java performance tools

Performance tools for Java

Accompanying the performance of your application is a continuous task, so it is important to have the right tools. What works in the development may not be so useful in a production environment. Here, I'm going to talk about the best tools and the best time to use them. The goal is to help you create reliable, high-performance applications as quickly as possible.

1. Java Profilers

JVM profiles offer a ton of raw data by tracking all method calls, allowing you to find CPU access points and memory consumption. A good test of size is to configure an Apache JMeter job to reach an endpoint that is developing a few thousand times while it is linked to a profile creator. This allows you to specify the memory and CPU requirements for production.

Pros: optimal for tracking memory leaks, the ability to manually run the garbage collection and then review the memory consumption can easily highlight the classes and processes that are kept in memory by mistake.

Cons: Requires a direct connection to the monitored JVM; This ends up limiting the use to development environments in most cases. (Note: some profile creators can work with subprocess frames and memory in limited ways).

2. Tracking web requests and transactions in Java

The standard profile creators focus on the performance of all methods throughout the application. These tools focus on the performance of individual requests or transactions on the web.

The prefix provides deep-level performance details about your application. Including ORM calls with generated SQL, SOAP / REST API calls and tracking details of the most used third-party libraries and structures.

XRebel is configured by a Java agent in the container of the web application and provides an overlay in the application that provides details about the current request.

Pros: these tools give order to the large amount of data available in a profiler of the JVM. By helping you track the flow of a request, you can see what types of method calls are responsible for your response time.

Cons: Designed only for the development cycle. The quality control and production environments require an APM solution.

3. Java Application Performance Management (APM)

Application performance management (APM) tools assume the task of tracking all requests in a production system. The trick of these proflets is to provide the correct information intelligently so as not to impact production performance. This is done by adding time statistics and sampling traces. This gives you visibility of the level of the method for your code that is running in production.

Pros: The ability to monitor your most critical environment: Production. Identify the problems before going into production, monitoring the QA / Staging. Debug production by analyzing traces and exceptions. Summaries added to see highly used requests to help focus development time.

Cons: normally expensive to run on all the quality control / preparation and production servers. Some tools do not support asynchronous queries or do not fit correctly and slow down your application.


4. Real user monitoring (RUM)

It is not uncommon for webapps to be very dependent on the client's side; The provision of an interactive experience may require many dependencies, such as JavaScript / CSS structures, Web sources and images.

RUM provides information on the dependencies of your application, giving visibility to the download of resources and the time of representation of the page.

Some APM products include this as an additional resource. There are also independent products, such as Google PageSpeed.

5. Performance Metrics of the JVM

JVM provides a wealth of valuable information, such as garbage collection, memory usage, and thread counts. This data is available through JMX.

Stackify Retrace provides monitoring of JVM metrics through application monitors and automatically applies intelligent patterns based on the type of application discovered.

Pros: Available in any application that runs in JVM and easy to connect with applications such as JConsole.

Cons: It can be difficult to connect in a preparation and production environment. Aggregation and comparison of data can be time consuming. The statistics are collected only while the monitor is connected to the JVM.

6. Access logs to the Web server (Apache / Nginx)

If you have Apache or Nginx proxy requests for your Java application server, you can monitor the access records. This is a quick way to see how long applications are being made. You can add access logs to see which are the most popular / fastest / slowest endpoints. Doing this through the command line may take, however.

For small data sets, you can use a desktop tool such as Apache Viewer, but for preparation and production environments, a hosted registry solution is ideal.

The tracking of failed requests is also very useful, which can be done by aggregation in HTTP response codes.

Pros: quick way to get some simple statistics, by following the access records, or - if more information is needed - push a log analyzer.

Cons: does not provide details about why the request took so long. There is a lack of POST data and response content that can help pinpoint the cause of a performance problem.

Interested in learning Java? Join now:” java training in chennai “

7. Accompanying all Java exceptions

One of the biggest causes of performance problems may be application exceptions. When an exception is thrown, it causes the segment to stop while collecting the stack trace. Even manipulated exceptions that seem innocent can cause huge performance bottlenecks under heavy server load. It is important to add and monitor all your exceptions to find critical problems, new errors and monitor error rates over time.

Pros: Easy to configure, if you are using a registration structure, such as Log4j or Logback.

Cons: None

Interested in learning Java? Join now:” java training in bangalore “

8. Memory analysis

The memory analysis of the application after a failure can help identify the cause of a memory leak. You can instruct JVM to dump the heap in an OutOfMemoryErrorexception including the following argument in JVM:

-XX: + HeapDumpOnOutOfMemoryError

The heap dump file can be loaded into an analyzer - Eclipse MAT. You can immerse yourself in the Overview or Leaks Suspects reports to help identify the cause of the memory exception.

Conclusion on Java performance tools

The big conclusion is that creating and maintaining the performance of the Java application is easier than ever with all these tools. Do not be overloaded with all the things you should do. Start with the fruit hung first, as a follow-up to the exception. It is really good, at least, to know what options are available to you, and I hope you have found this list useful.



Tuesday, November 13, 2018

How to monitor Java services - performance, errors and much more

In the real world, a lot of mission critical business logic lives in background services. Buying something from an e-commerce site, such as Amazon, initiates a variety of tasks that must be completed after clicking to confirm your request. Monitoring the performance of your web applications is only part of the puzzle if you want to proactively ensure that your software is working correctly all the time.

If you want to make sure that your software is working properly, you should monitor your Java services that deal with these mission critical tasks in the background.

Why monitoring a Java service is different

Monitoring of Java Services is different from monitoring of Java web applications. Web applications have very defined "transactions" based on each Web request that is running in the application container. It is very simple that services such as the Retrace identify each request of the individual Web and accompany the performance of them.

Java services are not started or defined for the work they perform. They usually start and run continuously until the server shuts down. To properly monitor the performance of your Java services, you must define the start and end of the transactions or the operations that are executed.

Identifying "Operations" in your Java services

Java services generally follow several commonly used standards. By identifying these patterns, you can quickly assess the best way to identify operations in your code.

Think of an operation as a small unit of work that is repeated several times. You need to identify which of them you want to monitor in your code.

Common standards of use:

• Queue listener: the application listens continuously in a queue and each message captured in a queue would be an exclusive operation.

• Timer-based - Many Java services use timers to repeat a specific operation at intervals of a few seconds, such as searching a database.

• Job scheduler: it is possible to incorporate a task scheduler such as Quartz in your Java service to trigger small jobs and scale them on all servers.

Most Java services will probably execute several operations. I would suggest dividing them into the smallest logical units of work. It is better if you supervise smaller work units. This is similar to monitoring each web application in your web application compared to monitoring the performance of the web application in its entirety.

For example, our monitoring agent for Linux is a Java service. He makes a ton of different operations on a schedule every few seconds. Each of these tasks that you execute must be defined as exclusive operations so that you can follow everything you do.


How to Instrument “Operations” in Your Code for Retrace

After identifying the operations you want to accompany, you will need to make some smaller code annotations to define your operations. This is done by adding the dependency of the Stackify Java APM annotations to the pom.xml file of your project.

 

<dependency>
   <groupId>com.stackify</groupId>
   <artifactId>stackify-java-apm-annot</artifactId>
   <version>1.0.4</version>
</dependency>
Example of instrumenting your code for Retrace:
import com.stackify.apm.Trace;
 
@Trace
public class ClassToBeInstrumented
{
            @Trace(start = true)
            public void methodToStartNewTrace()
            {
                        ...
            }
}

How to install Retrace for Java Services

The Retrace uses the lightweight Java profile and other data collection techniques. A service is installed on your Linux server and runs in the background. Our agent is easily installed by means of a curl or wget command. Please, check our documents for complete instructions.

Retrace provides developers with many advantages for monitoring Java service performance. Retrace provides holistic monitoring of Java service performance, including code profile, errors, logs, metrics and much more.

Benefits of monitoring Java services with Retrace

Once your code has been instrumented and the Retrace is collecting data about your Java service, you can get some incredible details about what your code is doing. Retrace can monitor independent Java applications executed through various service managers.

Retrace automatically supports dependencies and the most common Java frameworks, without code changes. You can instantly see how they are used in your application and how they affect performance. This includes PostgreSQL, MySQL, Oracle, external web services, MongoDB, Elasticsearch, Redis, Quartz, Hibernate and much more.

Identifying the main operations

Retrace allows you to see all the operations that are running in your Java service. Quickly identify the frequency with which each of them runs, the average time of execution and much more. The performance of Java services is typically a "black box." Retrace allows you to understand exactly what your Java service is doing.

Interested in learning Java? Join now:” java training in chennai “

Tracking Top SQL Queries

Retrace automatically crawls all SQL queries executed by your code. This includes stored procedures, dynamic SQL, Hibernate queries with crazy appearance and much more. Quickly identify which queries are running, how long they take and how often they are being called.

View Application Exceptions & Logs

Because Retrace works through the Java light code profile, it also has the ability to collect untreated exceptions by being thrown by its code. You can also track exceptions that are recorded in your registration structure.

Retrace provides powerful functions for error monitoring and record management. You can send all your records to the Retrace via log4j, logback and others. With Retrace, you can search all your records in a single location and perform many other advanced records management features.

Interested in learning Java? Join now:” java training in bangalore “

Tracking Custom Application Metrics

Retrace automatically monitors the use of the CPU and the memory of your Java service. You can also use it to track many other JMX standard MBeans. Including statistics on garbage collection and exceptions are counted per second. Retrace can also monitor custom JMX mBeans created by your applications.

The custom metrics are also compatible with the use of Stackify's maven "stackify-metric" package. With just a few lines of code, you can accompany how often or for a long time your Java service does practically anything.

View Code Level Traces

One of the most powerful features of Retrace are the snapshots of the level of code that it collects. For any of the operations tracked for your Java service, you can see all the main methods, dependencies that are called, exceptions, records and much more in context.

Summary

The developers depend a lot on Java services to do a great job of mission critical. Monitoring Java services is essential to ensure that they are functioning correctly and with good performance.


Retrace is an excellent solution to monitor the performance of your Java services. For more information, see our product page on Retrace and our overview of application tracking.

Sunday, November 11, 2018

Java Profiler List: 3 different types and why you need all of them


Debugging performance problems in production can be a pain and, in some cases, impossible without the right tools. The Java profile creators have been around for a while, but the profile creators that most developers think are just one type.

Let's dive into the 3 different types of Java profiles:

1. Standard JVM profiles that track all the details of the JVM (CPU, chaining, memory, garbage collection, etc.).

2. Light profilers that emphasize its application with a little abstraction.

3. Application performance management (APM) tools used to monitor live applications in production environments.



Standard JVM profiles

Products such as VisualVM, JProfiler, YourKit and Java Mission Control.

A standard Java profiler certainly provides most of the data, but not necessarily the most useful information. This depends on the type of debugging task. These profiler will track all method calls and memory usage. This allows a developer to immerse themselves in the call structure at any angle they choose.

pros:

• Excellent for tracking memory leaks, standard profiles detail all memory usage by JVM and which classes / objects are responsible. The ability to manually run the garbage collection and then review the memory consumption can easily highlight the classes and processes that are retained in memory with error.

• Good for tracking CPU usage, a Java profile creator generally provides a CPU sampling resource to track and add CPU time per class and method to help focus on access points.

cons:

• Requires a direct connection to the monitored JVM; This ends up limiting the use to development environments in most cases. (Note: some profile creators can work with subprocess frames and memory in limited ways).
• slow down your application; Good processing power is necessary for the high level of detail provided.

Interested in learning Java? Join now:” java training in chennai “

Lightweight transaction profiles in Java

Products such as XRebel and Stackify Prefix.

The creators of light profiles adopt a different approach when tracking their application, injecting themselves directly into the code.

• Aspect Profilers uses aspect-oriented programming (AOP) to inject code at the beginning and end of the specified methods. The injected code can start a stopwatch and report the elapsed time when the method is completed. These profiler are simple to configure, but you need to know what to create. For example, see Creating the profile of the Spring AOP method.

• Java Agent profile creators use the Java instrumentation API to inject code into their application. This method has greater access to your application, since the code is rewritten at the bytecode level. This allows any code that runs in your application to be instrumented - either the code you wrote or the third-party libraries that the application depends on. Check the introduction to the Java agents to see how everything works.
Aspect profilers are very easy to configure, but they are limited in what they can monitor and are overloaded by detailing everything you want to track. Java agents have a great advantage in their tracking depth, but they are much more complicated to write.
The Stackify Prefix is a developer-oriented Java profile creator using the Java agent profile method behind the scenes. The interesting thing is that Prefix already knows the most desired classes, and developers of third-party libraries want to be instrumented. So you do not need to detail all of them. In addition, it takes all the instrumentation statistics and displays them in a simple and understandable way. For example, when running an application using Hibernate, the Prefix not only details the elapsed time for queries, but also displays parameter values for the generated SQL. When your application calls a SOAP / REST API, the Prefix provides the content of the request and the response.

Interested in learning Java? Join now:” java training in bangalore “

Low Overload, Creating Java JVM Profile in Production (APM)

APM tools like New Relic, AppDynamics, Stackify Retrace, Dynatrace.
All profilers have been optimal for development so far, but monitoring how your system works in production is critical. Production is always a different landscape - the development and preparation configurations usually do not have the same data sets and load.

Java APM tools generally use the Java Agent profile creator method, but with different instrumentation rules to allow execution without affecting performance in productions. The trick with these proflets is to provide the correct information in a smart way so as not to occupy the CPU cycles.

Why are some Java profiles so expensive?

XRebel is a legal tool, but it costs US $ 365 per year. The Stackify Prefix is free and provides much of the same functionality.
The biggest problem with APM solutions is definitely its price. Traditionally, they are so expensive that only the largest companies can deal with them. It does not make much sense to spend $ 100 a month on a server in Azure or AWS and spend another $ 200 a month for a product like the new relic.The monitoring tools should not cost more than the servers!



Friday, November 9, 2018

State of Java in 2018

2017 has been a turbulent year in the Java world. The long-awaited version of Java 9 brought many changes and interesting new features, and Oracle announced a new launch schedule for the JDK.

And that was just the beginning. In the past, developers often complained that Java was not developing fast enough. I do not think you will hear such complaints in the near future. It may be the opposite.

What is reserved for 2018

In 2018, the JDK will follow a new launch schedule. Instead of a huge release every few years, you will receive one less every six months. Then, after the release of Java 9 in September 2017, Java 10 is already planned for March 2018. But more about that later.

Overview of the business stack

Most corporate projects do not use the JDK alone. They also have a stack of corporate libraries, such as Spring Boot or Java EE, which will also evolve in the coming months. In this article, I will focus mainly on the JDK. But here is a quick overview of what you should expect from the two main stacks of business in the Java world.

The Spring development team is working hard on Spring Boot 2 and released the first release candidate in January. The team does not expect any major changes to the API and does not plan to add new features to the final version. Therefore, if you are using Spring Boot in your projects, it is time to take a closer look at the new version and plan the updates of your existing Spring Boot applications.

At the end of 2017, Oracle began delivering the Java EE specifications for the EE4J project managed by the Eclipse Foundation. As expected, this transfer is a big project that can not be completed in a few days. There is a lot of organizational and technical work that still needs to be done. Java EE needs a new name and development process. And the transfer of the source code and all the artifacts stored in different bug trackers is still underway. We will have to wait a little longer to see the effects of the transfer and the stronger participation of the community.



Short release and support cycles of JDK

As announced last year, Oracle will release two new versions of the JDK in 2018. Instead of the slow release cycle, in which every few years we produce a new release with many changes, we will now have a lower version every six months. This allows a faster innovation of the Java platform. It also reduces the associated risks of a Java update. For Java developers, these minor releases will also greatly facilitate the familiarization process with the latest changes and apply them to our projects.

I hope this is a very positive change for the Java world. It will add new dynamics to the development of the Java language and will allow the JDK team to adapt and innovate much more quickly.

Changes and new features in JDK 10

Due to the short launch cycle, Java 10 brings only a small set of changes. You can get an overview of the 12 JEP (proposal for improvement of the JDK) currently included in the JDK10 page of OpenJDK.

The most notable change is probably the support for inference of local variable types (JEP 286). But you should also know about the new release version based on time (JEP 322) and the full parallel support of the GC (garbage collector) added to the G1, or the Garbage First (JEP 307).

Release version based on time

Beginning with Java 10, the format of the Java version number is changed to improve support for a time-based release model.

The main challenge presented by the new launch model is that the content of a release is subject to change. The only thing defined at the beginning is the time when the new version will be released. If the development of a new feature takes longer than expected, it will not be cut to the next version and will not be included. Therefore, you need a version number that represents the passage of time instead of the nature of the changes included.

JEP 322 defines the format of the version number as $ FEATURE, $ INTERIM. $ UPDATE. $ PATCH and plan to use it in the following way:
• Every six months, the development team will publish a new resource version and increase the $ FEATURE part of the version number.
• The release published in March 2018 will be called JDK 10 and the September release of JDK 11. The development team declares in JEP 223 that they expect to send at least one to two significant resources at each resource launch.
• The $ INTERIM number is maintained for flexibility and will not be used in the currently planned 6-month accounting model. So, for now, it will always be 0.
• Updates will be released between resource postings and not include any incompatible changes. One month after the release of a resource and after every three months, the $ UPDATE part of the version number will be increased.

Complete GC parallel in G1

For most developers, this is one of the smallest changes. Depending on your application, you may not recognize it.
The G1 has become the standard garbage collector in JDK 9. Its design attempts to avoid complete garbage collections, but that does not mean they never occur. Unfortunately, the G1 uses only a single-threaded mark-sweep-compact algorithm to execute a complete collection. This can result in a decrease in performance compared to the parallel collector previously used.

JEP 307 addresses this problem by providing a multi-threaded implementation of the algorithm. Starting with JDK 10, you will use the same number of threads for complete collections, as applied to new and mixed collections.
Therefore, if your application forces the garbage collector to complete collections, the JDK 10 can improve its performance.

Plans for JDK 11

The JDK 10 has not yet been released, and there are only seven months left until the launch of JDK 11. So, it is not surprising that there is already a small set of PEC planned for the second release of the resource in 2018.

In addition to the removal of obsolete Java EE and CORBA modules (JEP 320) and a new garbage collector (JEP 318), JDK 11 will likely present dynamic class file constants (JEP 309) and support the keyword var implicitly. typified lambda expressions (JEP 323).

The current scope of JDK 11 shows the benefits of shorter launch cycles. JEP 309 and 318 introduce new functionality, while the other two JEPs use an iterative approach to develop existing resources.

With the launch of JDK 9 in September 2017, the Java EE and CORBA modules became obsolete. A year later, with the release of JDK 11, JEP 320 removes them from JDK. So, instead of keeping them for several years, they will be removed in a timely and predictable manner.

And JEP 323 is a logical next step after JEP 286 introduced type inference for local variables in JDK 10. You should expect to see this approach more frequently in the future. Short launch cycles make it much easier to send a huge resource in several logical stages distributed in one or more resource releases.

Interested in learning Java? Join now:” java training in chennai “

Short support cycles require rapid adoption

Along with the new release model, Oracle also changed its support model. The new model differentiates between short and long-term launches.
Short-term versions, such as Java 9 and 10, will only receive public updates until the next release of resources is published. Thus, support for Java 9 ends in March 2018, and Java 10 will not receive public updates after September 2018.

Java 11 will be the first long-term release. Oracle wants to support these releases for a longer period. But so far, they have not announced how long they will provide public updates for Java 11.
As an application developer, you will have to decide if you want to update your Java version every six months or if you prefer a long-term release every few years. In addition, Oracle encourages everyone to migrate to the Java SE Advanced product. Includes at least five years of support for all long-term releases.

Interested in learning Java? Join now:” java training in bangalore “

Summary
In the past, many developers complained about the slow evolution of the Java language. This will no longer be the case in 2018. The new 6-month launch cycle and adapted support model will impose faster updates on existing applications and introduce new features on a regular basis. In combination with the evolution of existing structures, such as Java EE or Spring, this will add a new dynamic to the Java world. And it will also require a change of mentality in all the companies that are used to update their applications every few years.




From Java 8 to Java 11

Switching from Java 8 to Java 11 is more complicated than most updates. Here are some of my notes on the process. Modules Java 9 i...