Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions java/com/engflow/binaryinput/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")

NUM_FILES = 100

# Generates a number of java files based on the value of NUM_FILES
# Each file is named HelloX.java where X is the number of the file
# Each file contains a class with a greetNum method that prints "Hello" + the number of the file
[genrule(
name = "Hello" + str(x),
outs = ["Hello" + str(x) + ".java"],
cmd_bash = "echo 'package com.engflow.binaryinput;" + "\n" +
"public class Hello" + str(x) +
" { public static void greetNum() { System.out.println(\"Hello " + str(x) + "\"); } }' > $@",
) for x in range(1,NUM_FILES+1)]

# Generates a java library that contains all the generated java files
[java_library(
name = "genbinary" + str(x),
srcs = [":Hello" + str(x) + ".java" for x in range(1,NUM_FILES+1)],
visibility = ["//visibility:public"],
) for x in range(1,NUM_FILES+1)]

# Main class
java_binary(
name = "main",
srcs = ["Main.java"],
main_class = "com.engflow.binaryinput.Main",
deps = [
":genbinary" + str(x) for x in range(1,NUM_FILES+1)
],
args = [str(NUM_FILES)],
)
21 changes: 21 additions & 0 deletions java/com/engflow/binaryinput/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.engflow.binaryinput;

import java.lang.reflect.InvocationTargetException;

public class Main {
public static void main(String[] args) {
try {
// args[0] is the number of files to read
int numFiles = Integer.parseInt(args[0]);

// Load and run the greetNum method from each class
for(int i = 1; i <= numFiles; i++){
Class<?> clazz = Class.forName("com.engflow.binaryinput.Hello" + i);
clazz.getMethod("greetNum").invoke(null);
}

} catch (ClassNotFoundException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}
52 changes: 52 additions & 0 deletions java/com/engflow/binaryinput/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Multiple Binary Input Example

## Overview

The goal of this example project is to test the performance of Engflow's remote execution and caching service based on the number of input binary files in the dependency graph. The project contains a `genrule` that generates a specified number of Java binaries for the `genbinary` Java library, which are then listed as dependencies in the main binary. The `Main.java` file loops through each generated class and calls its `greetNum` method.

## Project Structure

- `java/com/engflow/binaryinput/Main.java`: Main class that dynamically loads and invokes methods from generated classes.
- `java/com/engflow/binaryinput/BUILD`: Bazel build file for the `main` java binary and the `genbinary` library.

## Usage

To generate the test files, build the `genbinary` library using the `genrule`:
```sh
bazel build //java/com/engflow/binaryinput:genbinary
```

Then, the program can be run with the following command:
```sh
bazel run //java/com/engflow/binaryinput:main
```

## How It Works

1. **Generation of Java Binaries:**
- The `genrule` in the `BUILD` file generates a specified number of Java classes (`Hello1.java`, `Hello2.java`, ..., `HelloN.java`).
- Each generated class contains a `greetNum` method that prints a unique message.

2. **Main Class Execution:**
- The `Main.java` file in `binaryinput` dynamically loads each generated class using reflection.
- It then invokes the `greetNum` method of each class, printing the corresponding message.

## Configuration

The number of generated files is controlled by the `NUM_FILES` variable in the `BUILD` file of the `binaryinput` package. Modify this variable to change the number of generated classes and observe the performance impact on Engflow's remote execution and caching service.

## Example

To generate and run the program with 10 input binary files:

1. Set `NUM_FILES` to 10 in `java/com/engflow/binaryinput/BUILD`.
2. Build the `genbinary` library:
```sh
bazel build //java/com/engflow/binaryinput:genbinary
```
3. Run the `main` binary:
```sh
bazel run //java/com/engflow/binaryinput:main
```

This will generate 10 Java classes, build the `genbinary` library, and run the `main` binary, which will print messages from each generated class.
Loading