Skip to content

Commit 3520644

Browse files
committed
Add required changes from PR222 to enable benchmarking of java codes.
1 parent a14d0a0 commit 3520644

File tree

5 files changed

+92
-49
lines changed

5 files changed

+92
-49
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,6 @@ cache
182182
# IntelliJ IDEA files
183183
.idea
184184
*.iml
185+
186+
# Visual Studio Code files
187+
.vscode/

benchmarks/wrappers/openwhisk/java/Main.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import faas.App;
2+
import com.google.gson.Gson;
13
import com.google.gson.JsonObject;
2-
import com.example.project.App ;
4+
import util.SessionBlob;
5+
import util.ShaSecurityProvider;
36
import java.time.Instant;
47
import java.time.Duration;
58
import java.io.File;
69
import java.io.IOException;
10+
//import jakarta.ws.rs.core.Response;
711

812

913
public class Main {
@@ -15,12 +19,17 @@ public static JsonObject main(JsonObject args) {
1519
Gson gson = new Gson();
1620
App function = new App();
1721

22+
long start_nano = System.nanoTime();
23+
1824
Instant begin = Instant.now();
1925
JsonObject result = function.handler(args);
2026
Instant end = Instant.now();
2127

22-
long computeTime = Duration.between(begin, end).toNanos() / 1000; // Convert nanoseconds to microseconds
28+
long end_nano = System.nanoTime();
29+
30+
// long computeTime = Duration.between(begin, end).toNanos() / 1000; // Convert nanoseconds to microseconds
2331

32+
long computeTime = end_nano - start_nano;
2433
boolean isCold = false;
2534
String fileName = "/cold_run";
2635

@@ -41,15 +50,13 @@ public static JsonObject main(JsonObject args) {
4150
String requestId = System.getenv("__OW_ACTIVATION_ID");
4251

4352
JsonObject jsonResult = new JsonObject();
44-
jsonObject.put("begin", formattedBegin);
45-
jsonObject.put("end", formattedEnd);
46-
jsonObject.put("request_id", "requestId");
47-
jsonObject.put("compute_time", computeTime);
48-
jsonObject.put("is_cold", isCold);
49-
jsonObject.put("result", result);
53+
jsonResult.addProperty("begin", formattedBegin);
54+
jsonResult.addProperty("end", formattedEnd);
55+
jsonResult.addProperty("request_id", requestId);
56+
jsonResult.addProperty("compute_time", computeTime);
57+
jsonResult.addProperty("is_cold", isCold);
58+
jsonResult.addProperty("result", result.toString());
5059
return jsonResult;
5160
}
52-
}
5361

54-
55-
62+
}

dockerfiles/openwhisk/java/Dockerfile.function

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG BASE_IMAGE
22
FROM $BASE_IMAGE
33
COPY . /function/
44

5-
RUN apt-get update && apt-get install -y maven
5+
# RUN apt-get update && apt-get install -y maven
66

7-
# Check if pom.xml exists before running Maven
8-
RUN if [ -f ./pom.xml ]; then mvn clean install; else echo "pom.xml not found, aborting build." && exit 1; fi
7+
# # Check if pom.xml exists before running Maven
8+
# RUN if [ -f ./pom.xml ]; then mvn clean install; else echo "pom.xml not found, aborting build." && exit 1; fi

sebs/benchmark.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import glob
22
import hashlib
33
import json
4+
import subprocess
45
import os
56
import shutil
67
import subprocess
@@ -200,8 +201,9 @@ def hash_directory(directory: str, deployment: str, language: str):
200201
FILES = {
201202
"python": ["*.py", "requirements.txt*"],
202203
"nodejs": ["*.js", "package.json"],
204+
"java": ["*.java", "pom.xml"],
203205
}
204-
WRAPPERS = {"python": "*.py", "nodejs": "*.js"}
206+
WRAPPERS = {"python": "*.py", "nodejs": "*.js", "java": "*.java"}
205207
NON_LANG_FILES = ["*.sh", "*.json"]
206208
selected_files = FILES[language] + NON_LANG_FILES
207209
for file_type in selected_files:
@@ -273,6 +275,28 @@ def copy_code(self, output_dir):
273275
if os.path.exists(nodejs_package_json):
274276
shutil.copy2(nodejs_package_json, os.path.join(output_dir, "package.json"))
275277

278+
#This is for making jar file and add it to docker directory
279+
def add_java_output(self, code_dir):
280+
281+
if self.language_name == "java":
282+
283+
# Step 1: Move Main.java o src directory
284+
src_dir = os.path.join(code_dir, "src", "main", "java")
285+
if os.path.exists(code_dir):
286+
main_java_path = os.path.join(code_dir, "Main.java")
287+
if os.path.exists(main_java_path):
288+
shutil.move(main_java_path, src_dir)
289+
290+
# Step 2: Run mvn clean install
291+
try:
292+
# Navigate to the code directory where the pom.xml file is located
293+
subprocess.run(['mvn', 'clean', 'install'], cwd=code_dir, check=True, text=True, capture_output=True)
294+
print("Maven build successful!")
295+
except subprocess.CalledProcessError as e:
296+
print(f"Error during Maven build:\n{e.stdout}\n{e.stderr}")
297+
return
298+
299+
276300
def add_benchmark_data(self, output_dir):
277301
cmd = "/bin/bash {benchmark_path}/init.sh {output_dir} false"
278302
paths = [
@@ -522,6 +546,7 @@ def build(
522546
self.copy_code(self._output_dir)
523547
self.add_benchmark_data(self._output_dir)
524548
self.add_deployment_files(self._output_dir)
549+
self.add_java_output(self._output_dir)
525550
self.add_deployment_package(self._output_dir)
526551
self.install_dependencies(self._output_dir)
527552
self._code_location, self._code_size = deployment_build_step(

sebs/openwhisk/openwhisk.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def build_base_image(
168168
)
169169

170170
for fn in os.listdir(directory):
171-
if fn not in ("index.js", "__main__.py", "Main.java"):
171+
if fn not in ("index.js", "__main__.py"):
172172
file = os.path.join(directory, fn)
173173
shutil.move(file, build_dir)
174174

@@ -214,24 +214,27 @@ def package_code(
214214
# to allow registration of function with OpenWhisk
215215
self.build_base_image(directory, language_name, language_version, benchmark, is_cached)
216216

217-
# We deploy Minio config in code package since this depends on local
218-
# deployment - it cannnot be a part of Docker image
219-
CONFIG_FILES = {
220-
"python": ["__main__.py"],
221-
"nodejs": ["index.js"],
222-
"java": ["Main.java"],
223-
}
224-
package_config = CONFIG_FILES[language_name]
225-
226-
benchmark_archive = os.path.join(directory, f"{benchmark}.zip")
227-
subprocess.run(
228-
["zip", benchmark_archive] + package_config, stdout=subprocess.DEVNULL, cwd=directory
229-
)
230-
self.logging.info(f"Created {benchmark_archive} archive")
231-
bytes_size = os.path.getsize(benchmark_archive)
232-
self.logging.info("Zip archive size {:2f} MB".format(bytes_size / 1024.0 / 1024.0))
233-
return benchmark_archive, bytes_size
217+
if language_name != 'java':
218+
# We deploy Minio config in code package since this depends on local
219+
# deployment - it cannnot be a part of Docker image
220+
CONFIG_FILES = {
221+
"python": ["__main__.py"],
222+
"nodejs": ["index.js"],
223+
}
224+
package_config = CONFIG_FILES[language_name]
234225

226+
benchmark_archive = os.path.join(directory, f"{benchmark}.zip")
227+
subprocess.run(
228+
["zip", benchmark_archive] + package_config, stdout=subprocess.DEVNULL, cwd=directory
229+
)
230+
self.logging.info(f"Created {benchmark_archive} archive")
231+
bytes_size = os.path.getsize(benchmark_archive)
232+
self.logging.info("Zip archive size {:2f} MB".format(bytes_size / 1024.0 / 1024.0))
233+
return benchmark_archive, bytes_size
234+
benchmark_jar = os.path.join(directory, "docker", "target", "benchmark-1.jar")
235+
bytes_size = os.path.getsize(benchmark_jar)
236+
237+
return benchmark_jar, bytes_size
235238
def storage_arguments(self) -> List[str]:
236239
storage = cast(Minio, self.get_storage())
237240
return [
@@ -281,27 +284,32 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "OpenWhisk
281284
code_package.language_name,
282285
code_package.language_version,
283286
)
287+
run_arguments = [
288+
*self.get_wsk_cmd(),
289+
"action",
290+
"create",
291+
func_name,
292+
"--web",
293+
"true",
294+
"--docker",
295+
docker_image,
296+
"--memory",
297+
str(code_package.benchmark_config.memory),
298+
"--timeout",
299+
str(code_package.benchmark_config.timeout * 1000),
300+
*self.storage_arguments(),
301+
code_package.code_location,
302+
]
303+
if code_package.language_name == 'java':
304+
run_arguments.extend(["--main", "Main"])
305+
284306
subprocess.run(
285-
[
286-
*self.get_wsk_cmd(),
287-
"action",
288-
"create",
289-
func_name,
290-
"--web",
291-
"true",
292-
"--docker",
293-
docker_image,
294-
"--memory",
295-
str(code_package.benchmark_config.memory),
296-
"--timeout",
297-
str(code_package.benchmark_config.timeout * 1000),
298-
*self.storage_arguments(),
299-
code_package.code_location,
300-
],
307+
run_arguments,
301308
stderr=subprocess.PIPE,
302309
stdout=subprocess.PIPE,
303310
check=True,
304311
)
312+
305313
function_cfg.docker_image = docker_image
306314
res = OpenWhiskFunction(
307315
func_name, code_package.benchmark, code_package.hash, function_cfg

0 commit comments

Comments
 (0)