Wednesday, October 28, 2026
HomeBig DataUse Amazon CodeGuru Profiler to watch and optimize efficiency in Amazon Kinesis...

Use Amazon CodeGuru Profiler to watch and optimize efficiency in Amazon Kinesis Knowledge Analytics purposes for Apache Flink

[ad_1]

Amazon Kinesis Knowledge Analytics makes it simple to rework and analyze streaming information and acquire actionable insights in actual time with Apache Flink. Apache Flink is an open-source framework and engine for processing information streams in actual time. Kinesis Knowledge Analytics reduces the complexity of constructing and managing Apache Flink purposes utilizing open-source libraries and integrating with different AWS providers.

Kinesis Knowledge Analytics is a totally managed service that takes care of every part required to run real-time streaming purposes repeatedly and scale routinely to match the quantity and throughput of your incoming information.

As you begin constructing and deploying business-critical, extremely scalable, real-time streaming purposes, it’s vital that you simply repeatedly monitor purposes for well being and efficiency, and optimize the applying to fulfill the calls for of your corporation.

With Amazon CodeGuru Profiler, builders and operations groups can monitor the next:

You need to use CodeGuru Profiler to research the applying’s efficiency traits and bottlenecks within the software code by capturing metrics resembling CPU and reminiscence utilization. You need to use these metrics and insights to determine the most costly traces of code; optimize for efficiency; enhance stability, latency, and throughput; and cut back operational value.

On this put up, we talk about among the challenges of working streaming purposes and the way you need to use Amazon Kinesis Knowledge Analytics for Apache Flink to construct dependable, scalable, and extremely out there streaming purposes. We additionally show methods to arrange and use CodeGuru Profiler to watch an software’s well being and seize vital metrics to optimize the efficiency of Kinesis Knowledge Analytics for Apache Flink purposes.

Challenges

Streaming purposes are notably complicated in nature. The information is repeatedly generated from a wide range of sources with various quantities of throughput. It’s crucial that the applying infrastructure scales up and down in accordance with these various calls for with out turning into overloaded, and never run into operational points which may lead to downtime.

As such, it’s essential to continuously monitor the applying for well being, and determine and troubleshoot the bottlenecks within the software configuration and software code to optimize the applying and the underlying infrastructure to fulfill the calls for whereas additionally lowering the operational prices.

What Kinesis Knowledge Analytics for Apache Flink and CodeGuru Profiler do for you

With Kinesis Knowledge Analytics for Apache Flink, you need to use Java, Scala, and Python to course of and analyze real-time streaming information utilizing open-source libraries primarily based on Apache Flink. Kinesis Knowledge Analytics offers the underlying infrastructure to your Apache Flink purposes. It handles core capabilities resembling provisioning compute assets, parallel computation, computerized scaling, and software backups (applied as checkpoints and snapshots) to quickly create, check, deploy, and scale real-time information streaming purposes utilizing greatest practices. This enables builders to focus extra on software growth and fewer on Apache Flink infrastructure administration.

With CodeGuru Profiler, you may rapidly and simply monitor Kinesis Knowledge Analytics for Apache Flink purposes to:

  • Establish and troubleshoot CPU and reminiscence points utilizing CPU and reminiscence (heap abstract) utilization metrics
  • Establish bottlenecks and the applying’s most costly traces of code
  • Optimize software efficiency (latency, throughput) and cut back infrastructure and operational prices

Answer overview

On this put up, we use a pattern Java software deployed as a Kinesis Knowledge Analytics software for Apache Flink, which consumes the information from Amazon Kinesis Knowledge Streams and makes use of Apache Flink operators to generate real-time actionable insights. We use this pattern to know and show methods to combine with CodeGuru Profiler to watch the well being and efficiency of your Kinesis Knowledge Analytics purposes.

The next diagram exhibits the answer elements.

Use Amazon CodeGuru Profiler to watch and optimize efficiency in Amazon Kinesis Knowledge Analytics purposes for Apache Flink

At a excessive degree, the answer covers the next steps:

  1. Arrange, configure, and deploy a pattern Apache Flink Java software on Kinesis Knowledge Analytics.
  2. Arrange CodeGuru Profiler.
  3. Combine the pattern Apache Flink Java software with CodeGuru Profiler.
  4. Use CodeGuru Profiler to research, monitor, and optimize software efficiency.

Arrange a pattern Apache Flink Java software on Kinesis Knowledge Analytics

Observe the directions within the GitHub repo and deploy the pattern software that features supply code in addition to AWS CloudFormation templates to deploy the Kinesis Knowledge Analytics for Apache Flink software.

For this put up, I deploy the stack within the us-east-1 Area.

After you deploy the pattern software, you may check the applying by working the next instructions, and offering the proper parameters for the Kinesis information stream and Area.

The Java software has already been downloaded to an EC2 occasion that has been provisioned by AWS CloudFormation; you simply want to connect with the occasion and run the JAR file to begin ingesting occasions into the stream.

$ ssh ec2-user@«Replay occasion DNS title»

$ java -jar amazon-kinesis-replay-*.jar -streamName «Kinesis information stream title» -streamRegion «AWS area» -speedup 3600

Arrange CodeGuru Profiler

Arrange and configure CodeGuru Profiler utilizing the AWS Administration Console. For directions, see Arrange within the CodeGuru Profiler console.

For this put up, I create a profiling group referred to as flinkappdemo within the us-east-1 Area.

Within the subsequent part, I show methods to combine the pattern Kinesis Knowledge Analytics software with the profiling group.

Combine the pattern Apache Flink Java software with CodeGuru Profiler

Obtain the supply code that you simply deployed earlier and full the next steps to combine CodeGuru Profiler to the Java software:

  1. Embrace the CodeGuru Profiler agent in your software by including the next dependencies to your pom.xml file:
    <challenge xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ...
        <repositories>
            <repository>
                <id>codeguru-profiler</id>
                <title>codeguru-profiler</title>
                <url>https://d1osg35nybn3tt.cloudfront.internet</url>
            </repository>
        </repositories>
        ... 
        <dependencies>
            <dependency>
                <groupId>com.amazonaws</groupId>
                <artifactId>codeguru-profiler-java-agent</artifactId>
                <model>1.2.1</model>
            </dependency>
        </dependencies>
    ...
    </challenge> 

  2. Add the CodeGuru Profiler agent configuration code to the Apache Flink Operators (capabilities), as proven within the following code.

As a result of a number of operators and operator situations can run on the identical TaskManager JVM, and since one occasion of the profiler can seize all occasions in a JVM, you simply have to allow the profiler on an operator that’s assured to be current on all TaskManager JVMs. For this, you may choose the operator with the very best parallelism. As well as, you would instantiate the profiler as a singleton such that there’s one occasion per JVM.

public class CountByGeoHash implements WindowFunction<TripGeoHash, PickupCount, String, TimeWindow> {

  static {
    new Profiler.Builder()
            .profilingGroupName("flinkappdemo")
            .withHeapSummary(false) // optionally available - to begin with out heap profiling set to false or take away line
            .construct()
            .begin();
  }
  .....
}
public class TripDurationToAverageTripDuration implements WindowFunction<TripDuration, AverageTripDuration, Tuple2<String, String>, TimeWindow> {

  static {
    new Profiler.Builder()
            .profilingGroupName("flinkappdemo")
            .withHeapSummary(false) // optionally available - to begin with out heap profiling set to false or take away line
            .construct()
            .begin();
  }
  .....
}

  1. Construct the applying utilizing the next command:

The previous command packages the applying right into a JAR file.

  1. Copy and change the JAR file within the Amazon Easy Storage Service (Amazon S3) bucket that was created as a part of the CloudFormation stack.
  2. Select Save modifications to replace the applying.

This step permits the applying to make use of the most recent JAR file that comprises the CodeGuru Profiler code to begin profiling the applying.

Use CodeGuru Profiler to research, monitor, and optimize software efficiency

Now that the applying has been configured to make use of CodeGuru Profiler, you need to use the metrics and visualizations to discover profiling information collected from the applying.

Run the next instructions from once you arrange your software to begin ingesting information into the Kinesis information stream and allow CodeGuru Profiler to profile the applying and collect metrics:

$ ssh ec2-user@«Replay occasion DNS title»

$ java -jar amazon-kinesis-replay-*.jar -streamName «Kinesis information stream title» -streamRegion «AWS area» -speedup 3600

On the CodeGuru console, navigate to flinkappdemo on the Profiling teams web page.

The abstract web page shows the standing of your profiling group in addition to the related metrics gathered whereas profiling the applying.

Within the following sections, we talk about the metrics and studies on this web page in additional element.

CPU abstract

Use this abstract and the related metrics CPU utilization and Time spent executing code to know how a lot of the occasion’s CPU assets are consumed by the applying and the way ceaselessly the applying’s JVM threads had been within the RUNNABLE state. This helps you measure the applying’s time spent working operations on the CPU so you may tune your software code and configuration.

With the CPU utilization metric, a low worth (resembling lower than 10%) signifies your software doesn’t eat a considerable amount of the system CPU capability. This implies there could possibly be a possibility to scale within the software parallelism to scale back value. A excessive worth (over 90%) signifies your software is consuming a considerable amount of system CPU capability. This implies there may be seemingly worth in taking a look at your CPU profiles and suggestions for areas of optimization.

When inspecting the time spent working code, a excessive proportion (over 90%) signifies most of your software’s time is spent working operations on the CPU. A really low proportion (underneath 1%) signifies that almost all of your software was spent in different thread states (resembling BLOCKED or WAITING) and there could also be extra worth in trying on the latency visualization, which shows all non-idle thread states, as a substitute of the CPU visualization.

For extra data on understanding the CPU abstract, see CPU abstract.

Latency abstract

Use this abstract and the metrics Time spent blocked and Time spent ready to know what sections of the code are inflicting threads to dam and threads which are ready to tune your software code and configuration. For extra data, see Latency abstract.

The CPU abstract and latency visualization can assist you analyze the thread blocking and wait operations to additional determine bottlenecks and tune your software’s efficiency and configuration.

Heap utilization

Use this abstract and the metrics Common heap utilization and Peak heap utilization to know how a lot of your software’s most heap capability is consumed by your software and to identify reminiscence leaks. If the graph grows repeatedly over time, that could possibly be a sign of a reminiscence leak.

With the common heap utilization metric, a excessive proportion (over 90%) may point out that your software is near working out of reminiscence more often than not. When you want to optimize this, the heap abstract visualization exhibits you the item sorts consuming probably the most area on the heap. A low proportion (lower than 10%) might point out that your JVM is being offered far more reminiscence than it really requires and value financial savings could also be out there by scaling within the software parallelism, though it is best to verify the height utilization too.

Peak heap utilization exhibits the very best proportion of reminiscence consumed by your software seen by the CodeGuru Profiler agent. That is primarily based on the identical dataset as seen within the heap abstract visualization. A excessive proportion (over 90%) may point out that your software has excessive spikes of reminiscence utilization, particularly in case your common heap utilization is low.

For extra data on the heap abstract, see Understanding the heap abstract.

Anomalies and suggestion studies

CodeGuru Profiler makes use of machine studying to detect and alert on anomalies in your software profile and code. Use this to determine elements of the code for efficiency optimization and potential financial savings.

The problems recognized throughout evaluation are included within the suggestions report. Use this report back to determine potential outages, latency, and different efficiency points. For extra data on methods to work with anomalies and suggestions, see Working with anomalies and suggestion studies.

Visualizations

You need to use visualizations related to the previous metrics to drill down additional to determine what elements of the applying configuration and software code are impacting the efficiency, and use these insights to enhance and optimize software efficiency.

CodeGuru Profiler helps three kinds of visualizations and a heap abstract to show profiling information collected from purposes:

Let’s discover the profiling information collected from the previous steps to watch and monitor software efficiency.

CPU utilization

The next screenshot exhibits the snapshot of the applying’s profiling information in a flame graph visualization. This view offers a bottom-up view of the applying’s profiling information, with the X-axis displaying the stack profile and the Y-axis displaying the stack depth. Every rectangle represents a stack body. This visualization can assist you determine particular name stacks that result in inefficient code by trying on the prime block perform on CPU. This will point out a possibility to optimize.

Advice report with alternatives to optimize the applying

Use the advice report back to determine and correlate the sections of the applying code that may be improved to optimize the applying efficiency. In our instance, we will enhance the applying code through the use of StringBuilder as a substitute of String.format and by reusing the loggers moderately than reinitializing them repetitively, and likewise by selectively making use of the debug/hint logging, as advisable within the following report.

Hotspot visualization

The hotspot visualization exhibits a top-down view of the applying’s profiling information. The capabilities that eat probably the most CPU time are on the prime of the visualization and have the widest block. You need to use this view to analyze capabilities which are computationally costly.

Latency visualization

On this mode, you may visualize frames with totally different thread states, which can assist you determine capabilities that spent lots of time being blocked on shared assets, or ready for I/O or sleeping. You need to use this view to determine threads which are ready or depending on different threads and use it to enhance latency on all or elements of your software.

You may examine a visualization to additional analyze any body by choosing a body after which selecting (right-click) the body and selecting Examine.

Heap abstract

This abstract view exhibits how a lot heap area your software requires to retailer all objects required in reminiscence after a rubbish assortment cycle. If this worth repeatedly grows over time till it reaches complete capability, that could possibly be a sign of a reminiscence leak. If this worth could be very low in comparison with complete capability, you might be able to lower your expenses by lowering your system’s reminiscence.

For extra data on methods to work and discover information with visualizations, confer with Working with visualizations and Exploring visualization information.

Clear up

To keep away from ongoing costs, delete the assets you created from the earlier steps.

  1. On the CodeGuru console, select Profiling teams within the navigation pane.
  2. Choose the flinkappdemo profiling group.
  3. On the Actions meu, select Delete profiling group.
  4. On the AWS CloudFormation console, select Stacks within the navigation pane.
  5. Choose the stack you deployed (kinesis-analytics-taxi-consumer) and select Delete.

Abstract

This put up defined methods to configure, construct, deploy, and monitor real-time streaming Java purposes utilizing Kinesis Knowledge Analytics purposes for Apache Flink and CodeGuru. We additionally defined how you need to use CodeGuru Profiler to gather runtime efficiency information and metrics that may assist you to monitor software well being and optimize your software efficiency.

For extra data, see Construct and run streaming purposes with Apache Flink and Amazon Kinesis Knowledge Analytics for Java Functions and the Amazon Kinesis Knowledge Analytics Developer Information.

A number of clients at the moment are utilizing CodeGuru Profiler to watch and enhance software efficiency, and you can also begin monitoring your purposes by following the directions within the product documentation. Head over to the CodeGuru console to get began as we speak!


In regards to the Creator

Praveen Panati is a Senior Options Architect at Amazon Net Providers. He’s enthusiastic about cloud computing and works with AWS enterprise clients to architect, construct, and scale cloud-based purposes to attain their enterprise targets. Praveen’s space of experience consists of cloud computing, huge information, streaming analytics, and software program engineering.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments