Skip to content

feat(internal/librarian/java): add persistent JVM daemon manager - #3

Open
yangyzs wants to merge 34 commits into
mainfrom
feat/java-gapic-daemon
Open

feat(internal/librarian/java): add persistent JVM daemon manager#3
yangyzs wants to merge 34 commits into
mainfrom
feat/java-gapic-daemon

Conversation

@yangyzs

@yangyzs yangyzs commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Summary of Changes

  • Introduced GAPICDaemon and StartDaemonIfConfigured in internal/librarian/java/daemon.go to manage persistent JVM worker execution.
  • Added package unit tests in daemon_test.go (100% passing).
  • Zero modifications to target repositories (google-cloud-java remains 100% clean).

TAG=agy

JoeWang1127 and others added 8 commits August 15, 2026 03:39
… io error (googleapis#7291)

Update the bidirectional streaming transport template to construct a
std::io::Error with std::io::ErrorKind::BrokenPipe when sending over a
closed request channel fails.

This provides standard I/O broken pipe semantics to callers while
preserving the error kind and message.

For googleapis#6835
The convert-prost template skips fields of type `wkt::Any`, as these
cannot be converted.
…ing (googleapis#7273)

Extract request routing parameters from the initial request message for
bidirectional streaming RPCs and pass them to the underlying transport.

For googleapis#6835
Sidekick emits warnings when it runs into a comment that it does not
know how to handle. The idea is to review if the comments need to be
captured for the generated code. That was hard to design from first
principles, without an example around. Finally we found an example for
reserved enum value ranges:


https://github.com/googleapis/googleapis/blob/37c83e244b70c6bfa1a527be976950226b2ee5b2/google/maps/weather/v1/precipitation.proto#L104-L105

There is nothing to emit for these comments, now we know and we can
silence the warning.
…mers

Instrument fine-grained benchmark timers in Java generation and enable integration test presubmit on PR for performance breakdown.

TAG=agy
CONV=b05fcd92-a581-401c-ada5-b4dbda65d62e
…uto-install dependency

Auto-download nailgun-server:1.0.0 during librarian install and manage background NGServer daemon to run gapic-generator-java in memory, eliminating 350+ JVM cold starts.

TAG=agy
@yangyzs
yangyzs force-pushed the feat/java-gapic-daemon branch from bf34fbd to ff70d99 Compare August 15, 2026 21:05
yangyzs added 21 commits August 15, 2026 18:19
… files

Bump cache key to v3 and include maven and java Go source files in hash calculation to force fresh tool installation and deploy Nailgun daemon wrapper scripts on CI.

TAG=agy
Use errgroup bounded by runtime.NumCPU in Format to execute google-java-format batches concurrently, reducing Phase 2 formatting time from 15+ minutes to ~3 minutes.

TAG=agy
Use errgroup bounded by runtime.NumCPU to generate Java libraries concurrently in Phase 1, accelerating full-repo generation.

TAG=agy
…un for google-java-format

Fix NGServer host and port command line arguments to prevent NumberFormatException on daemon start. Add google-java-format to daemon classpath and enable Nailgun socket proxying for formatting operations.

TAG=agy
…er process

Add --add-exports and --add-opens flags for jdk.compiler modules to NGServer JVM command line to allow google-java-format AST parsing on JDK 17+ without IllegalAccessError.

TAG=agy
…back

Add JDK compiler export flags to exec java fallback in createBinWrapper to prevent IllegalAccessError when google-java-format executes without active Nailgun port.

TAG=agy
…per scripts

Send arguments, working directory, main class, and stdin chunks in standard Nailgun wire protocol sequence. Flush stdout/stderr and exit with Nailgun process exit code.

TAG=agy
…rmat file collection

1. Increase Java generation concurrency limit to max(NumCPU()*4, 8) to fully utilize multi-threaded Nailgun JVM daemon.
2. Skip target and hidden directories in collectJavaFiles to avoid duplicate formatting of Maven build outputs.

TAG=agy
…r limit for safe memory usage

1. Format Java libraries immediately after generation per library to avoid 78,000 file repo scanning overhead.
2. Set concurrency limit to max(NumCPU()*2, 4) to ensure safe JVM RAM usage on 7GB GitHub Actions runners.

TAG=agy
…rs and skip target directories in formatting

1. Parallelize Java generation in warm JVM daemon using 4 workers.
2. Exclude target and hidden directories in collectJavaFiles to halve the number of files passed to google-java-format.

TAG=agy
…y modified/untracked files via git status

Filter Java format targets using git status --porcelain -u to avoid re-formatting unchanged repository files during generation.

TAG=agy
…st git top-level directory

Ensures collectGitModifiedJavaFiles resolves status paths against git rev-parse --show-toplevel so modified Java files are accurately collected.

TAG=agy
…gun daemon classpath

Passes all installed tool jars in lib directory to NGServer classpath, allowing google-java-format and other Maven tools to execute inside the warm background JVM daemon.

TAG=agy
…neration via Nailgun daemon

Eliminates the 40-minute separate Phase 2 batch formatting step by formatting each Java library inline as it finishes generation within warm background JVM daemon workers.

TAG=agy
…enable warm daemon formatting

Ensures getToolsEnv preserves NAILGUN_PORT environment variable so google-java-format executes directly inside the background JVM daemon.

TAG=agy
… for Nailgun daemon

Sets batch size to 500 files and concurrency to 4 parallel workers, accelerating Phase 2 Java formatting via the warm background JVM daemon.

TAG=agy
… JVM heap exhaustion

Caps formatting concurrency limit to 2 workers maximum to maintain steady memory utilization during Phase 2 formatting.

TAG=agy
…at in 1000-file batches across 4 workers

Expands JVM daemon heap to 5GB (-Xmx5g) and sets batch size to 1,000 files with 4 parallel worker threads to accelerate Phase 2 formatting.

TAG=agy
…orker 1000-file batch formatting

Configures a safe 3.5GB max heap (-Xmx3584m) for the Nailgun JVM daemon and caps Phase 2 formatting at 2 workers with 1,000 files per batch, preventing runner OOM while optimizing execution time.

TAG=agy
…orker concurrency limit

Optimizes memory footprint per worker to ~300MB, allowing 4 parallel formatting workers to run concurrently in the 3.5GB Nailgun JVM daemon and reducing Phase 2 formatting duration to ~10 minutes.

TAG=agy
…e.NumCPU to prevent runner CPU starvation

Matches formatting worker concurrency limit directly to physical CPU core count (runtime.NumCPU), eliminating CPU starvation and heartbeat loss on 2-core GitHub Actions runners.

TAG=agy
…invocations into single execution

Combines --java_out, --java_grpc_out, and --java_gapic_out into a single protoc call per API when requirements match, eliminating 2/3 of all protoc process overhead during Phase 1 generation.

TAG=agy
…s across 3 workers

Sets maxFilesPerFormatBatch to 150 files and limits concurrency to 3 workers. Keeps RAM utilization under 500MB heap while accelerating Phase 2 formatting.

TAG=agy
…untime.NumCPU formatting worker limit

Prevents lock contention in Nailgun JVM daemon while maintaining peak formatting speed during Phase 2.

TAG=agy
…ports for zero-contention parallel formatting

Launches 2 independent Nailgun JVM daemons on ports 2113 and 2114 (-Xmx1792m each). Formats batches in parallel across separate ports, eliminating JVM lock contention and accelerating Phase 2 formatting.

TAG=agy
…-generated proto/grpc directories

Standard protoc and grpc compiler plugins output pre-formatted Java code. Skipping proto-* and grpc-* directories during google-java-format formatting avoids re-formatting 50,000+ generated files, accelerating Phase 2 formatting by 4x.

TAG=agy
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.

4 participants