Skip to content

Cap JVM active processors at the pod CPU request - #135

Merged
lolgab merged 1 commit into
masterfrom
cap-active-processors
Dec 3, 2026
Merged

lolgab merged 1 commit into
masterfrom
cap-active-processors

Conversation

@lolgab

@lolgab lolgab commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

PMD pods have a memory limit but no CPU limit (codacy-tools PMD.scala: request 1500m / 4Gi, limit 4Gi), so cgroup cpu.max reads max and the JVM's availableProcessors() returns the node's core count. PMD 6.55.0 defaults PMDConfiguration.threads to availableProcessors() and the wrapper never sets it, so on a 16–64 core node PMD starts one analysis thread per core, each with its own copy of the rulesets, plus as many GC and JIT threads. With the heap at 90% of the limit, all of that shares the remaining ~400Mi.

  • The start script now passes -XX:ActiveProcessorCount=2 (the 1500m CPU request, rounded up) next to -XX:MaxRAMPercentage=90.0. That caps PMD's default thread count, the ForkJoin common pool, and the GC/JIT thread counts at once.
  • With two processors and 4Gi the JVM still picks G1, as today.

Same fix as codacy/codacy-opengrep#50.

  • Build the image and run the multiple-tests suite (CircleCI plugins_test)
  • After deploy, 7 days: PMD ToolOutOfMemory count vs before
  • After deploy, 7 days: p99 run time and timeouts vs before (fewer threads can be slower on idle nodes)

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@lolgab
lolgab marked this pull request as ready for review December 3, 2026 10:51
@lolgab
lolgab enabled auto-merge (squash) December 3, 2026 10:51

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

⚠️ Resolve issues before merging

A high-confidence issue remains in build.sbt: the fixed processor cap can underutilize larger pods and overstate processors in smaller pods because it is not derived from the pod CPU request.

Test suggestions

  • Verify the generated startup configuration includes both MaxRAMPercentage=90.0 and ActiveProcessorCount=2.
  • Verify the JVM reports two active processors when the image starts.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify the generated startup configuration includes both MaxRAMPercentage=90.0 and ActiveProcessorCount=2.
2. Verify the JVM reports two active processors when the image starts.

TIP Add review instructions in .codacy/instructions/review.md, or an AGENTS.md, so the reviewer knows your conventions.
TIP How was this review? Give us feedback

Comment thread build.sbt
}.value

Universal / javaOptions ++= Seq("-XX:MaxRAMPercentage=90.0")
Universal / javaOptions ++= Seq("-XX:MaxRAMPercentage=90.0", "-XX:ActiveProcessorCount=2")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

In pods requesting more than two CPUs, JVM-sized worker pools can underutilize the available CPUs and reduce throughput. Pods requesting fewer CPUs will instead have their processor count overstated. Consider setting this value from each pod's CPU request, with a suitable default for non-Kubernetes deployments.

TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.

@lolgab
lolgab merged commit 6fdf2ad into master Dec 3, 2026
4 checks passed
@lolgab
lolgab deleted the cap-active-processors branch December 3, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants