-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] java basic scenarios #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
r1viollet
wants to merge
4
commits into
main
Choose a base branch
from
r1viollet/java_basic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class CpuBurner { | ||
| public static void main(String[] args) { | ||
| int numThreads = 2; | ||
| ExecutorService executor = Executors.newFixedThreadPool(numThreads); | ||
|
|
||
| int executionTimeSec = Integer.parseInt(System.getenv().getOrDefault("EXECUTION_TIME_SEC", "60")); | ||
|
|
||
| System.out.println("Starting CPU intensive tasks on " + numThreads + " threads for " + executionTimeSec + " seconds..."); | ||
|
|
||
| for (int i = 0; i < numThreads; i++) { | ||
| executor.submit(() -> { | ||
| while (!Thread.currentThread().isInterrupted()) { | ||
| double value = Math.pow(Math.random(), Math.random()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| Thread.sleep(executionTimeSec * 1000L); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
|
|
||
| executor.shutdownNow(); | ||
| System.out.println("CPU intensive tasks stopped."); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Use Rocky Linux 9.3 as base image | ||
| FROM rockylinux:9.3 | ||
|
|
||
| # Install Temurin JDK 11.0.20.1+1 | ||
| RUN dnf install -y \ | ||
| glibc-langpack-en \ | ||
| && dnf clean all \ | ||
| && curl -LO https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.20.1%2B1/OpenJDK11U-jdk_x64_linux_hotspot_11.0.20.1_1.tar.gz \ | ||
| && tar -xzf OpenJDK11U-jdk_x64_linux_hotspot_11.0.20.1_1.tar.gz -C /opt/ \ | ||
| && rm OpenJDK11U-jdk_x64_linux_hotspot_11.0.20.1_1.tar.gz | ||
|
|
||
| # Set JAVA_HOME environment variable | ||
| ENV JAVA_HOME=/opt/jdk-11.0.20.1+1 | ||
| ENV PATH="${JAVA_HOME}/bin:${PATH}" | ||
|
|
||
| # Set environment variables for Datadog | ||
| ENV DD_SERVICE=cpu-burner-app | ||
| ENV DD_ENV=production | ||
| ENV DD_PROFILING_ENABLED=true | ||
| ENV DD_LOGS_INJECTION=true | ||
| ENV DD_TRACE_DEBUG=true | ||
| ENV DD_PROFILING_LOG_LEVEL=debug | ||
| ENV KEEP_JFRS=true | ||
|
|
||
| # Install Datadog Java agent | ||
| RUN curl -LO https://dtdg.co/latest-java-tracer && mv latest-java-tracer dd-java-agent.jar | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy Java application to the container | ||
| COPY ./scenarios/java_basic/CpuBurner.java . | ||
|
|
||
| # Compile Java application | ||
| RUN javac CpuBurner.java | ||
|
|
||
|
|
||
| ENV DD_PROFILING_DDPROF_ENABLED=true | ||
| # Run the application with Datadog profiler | ||
| CMD ["java", "-javaagent:/dd-java-agent.jar", "CpuBurner"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "test_name": "java_basic", | ||
| "scale_by_duration": true, | ||
| "stacks": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class CpuBurner { | ||
| public static void main(String[] args) { | ||
| int numThreads = 2; | ||
| ExecutorService executor = Executors.newFixedThreadPool(numThreads); | ||
|
|
||
| int executionTimeSec = Integer.parseInt(System.getenv().getOrDefault("EXECUTION_TIME_SEC", "60")); | ||
|
|
||
| System.out.println("Starting CPU intensive tasks on " + numThreads + " threads for " + executionTimeSec + " seconds..."); | ||
|
|
||
| for (int i = 0; i < numThreads; i++) { | ||
| executor.submit(() -> { | ||
| while (!Thread.currentThread().isInterrupted()) { | ||
| double value = Math.pow(Math.random(), Math.random()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| Thread.sleep(executionTimeSec * 1000L); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
|
|
||
| executor.shutdownNow(); | ||
| System.out.println("CPU intensive tasks stopped."); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Use Alpine latest as base image | ||
| FROM alpine:3.21.3 | ||
|
|
||
|
|
||
| # Install dependencies and Temurin JDK 21.0.6+7 | ||
| RUN apk add --no-cache \ | ||
| bash \ | ||
| curl \ | ||
| openjdk21 \ | ||
| && ln -sf /usr/lib/jvm/java-21-openjdk /opt/jdk-21.0.6+7 | ||
|
|
||
| # Set JAVA_HOME environment variable | ||
| ENV JAVA_HOME=/opt/jdk-21.0.6+7 | ||
| ENV PATH="${JAVA_HOME}/bin:${PATH}" | ||
|
|
||
| # Set environment variables for Datadog | ||
| ENV DD_SERVICE=cpu-burner-app | ||
| ENV DD_ENV=production | ||
| ENV DD_PROFILING_ENABLED=true | ||
| ENV DD_LOGS_INJECTION=true | ||
| ENV DD_TRACE_DEBUG=true | ||
| ENV DD_PROFILING_LOG_LEVEL=debug | ||
| ENV KEEP_JFRS=true | ||
|
|
||
| # Install Datadog Java agent | ||
| RUN curl -LO https://dtdg.co/latest-java-tracer && mv latest-java-tracer dd-java-agent.jar | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy Java application to the container | ||
| COPY ./scenarios/java_basic/CpuBurner.java . | ||
|
|
||
| # Compile Java application | ||
| RUN javac CpuBurner.java | ||
|
|
||
| # Run the application with Datadog profiler | ||
| CMD ["java", "-javaagent:/dd-java-agent.jar", "CpuBurner"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "test_name": "java_basic", | ||
| "scale_by_duration": true, | ||
| "stacks": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class CpuBurner { | ||
| public static void main(String[] args) { | ||
| // int numThreads = Runtime.getRuntime().availableProcessors(); | ||
| int numThreads = 2; // avoid overloading system | ||
| ExecutorService executor = Executors.newFixedThreadPool(numThreads); | ||
|
|
||
| int executionTimeSec = Integer.parseInt(System.getenv().getOrDefault("EXECUTION_TIME_SEC", "60")); | ||
|
|
||
| System.out.println("Starting CPU intensive tasks on " + numThreads + " threads for " + executionTimeSec + " seconds..."); | ||
|
|
||
| for (int i = 0; i < numThreads; i++) { | ||
| executor.submit(() -> { | ||
| while (!Thread.currentThread().isInterrupted()) { | ||
| double value = Math.pow(Math.random(), Math.random()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| Thread.sleep(executionTimeSec * 1000L); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
|
|
||
| executor.shutdownNow(); | ||
| System.out.println("CPU intensive tasks stopped."); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Use OpenJDK 18 as base image | ||
| FROM openjdk:18-jdk | ||
|
|
||
| # Set environment variables for Datadog | ||
| ENV DD_SERVICE=cpu-burner-app | ||
| ENV DD_ENV=production | ||
| ENV DD_PROFILING_ENABLED=true | ||
| ENV DD_LOGS_INJECTION=true | ||
| ENV DD_TRACE_DEBUG=true | ||
| ENV DD_PROFILING_LOG_LEVEL=debug | ||
| ENV KEEP_JFRS=true | ||
|
|
||
| # Install Datadog Java agent | ||
| RUN curl -LO https://dtdg.co/latest-java-tracer && mv latest-java-tracer dd-java-agent.jar | ||
|
|
||
| # Copy Java application to the container | ||
| WORKDIR /app | ||
| COPY ./scenarios/java_basic/CpuBurner.java . | ||
|
|
||
| # Compile Java application | ||
| RUN javac CpuBurner.java | ||
|
|
||
| # Run the application with Datadog profiler | ||
| CMD ["java", "-javaagent:/dd-java-agent.jar", "CpuBurner"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "test_name": "java_basic", | ||
| "scale_by_duration": true, | ||
| "stacks": [] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Code Vulnerability
Use of insecure random values (...read more)
Functions as
Math.random()and objects likejava.util.Random()do not provide strong enough randomness. Consider usingjava.security.SecureRandom()instead.