Skip to content

Commit 160ddcb

Browse files
committed
data api java app waverless inner data storage
1 parent e50ba03 commit 160ddcb

28 files changed

Lines changed: 972 additions & 291 deletions

__pycache__/pylib.cpython-36.pyc

-2.27 KB
Binary file not shown.

__pycache__/pylib.cpython-38.pyc

-2.37 KB
Binary file not shown.

bencher/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prepare_data

bencher/app_fn_entries.yaml

Lines changed: 118 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,120 @@
1-
simple_demo:
2-
name: "Simple Demo"
3-
description: "A simple demo function"
4-
language: "java"
5-
runtime: "java11"
6-
handler: "test.functions.Simple"
7-
memory: 256
8-
timeout: 30
9-
prepare_data: []
10-
prepare_scripts: []
11-
fns:
12-
simple:
13-
args: {}
14-
15-
# img_resize:
16-
# resize:
17-
# prepare_data: "image_${reqid}.jpg"
18-
# prepare_script: |
19-
# from PIL import Image, ImageDraw
20-
# import random
21-
22-
# def generate_random_image(width, height, output_path):
23-
# # 创建一个空白图像
24-
# image = Image.new('RGB', (width, height), 'white')
25-
# draw = ImageDraw.Draw(image)
26-
27-
# # 生成随机颜色的像素
28-
# for x in range(width):
29-
# for y in range(height):
30-
# r = random.randint(0, 255)
31-
# g = random.randint(0, 255)
32-
# b = random.randint(0, 255)
33-
# draw.point((x, y), fill=(r, g, b))
34-
35-
# # 保存图像
36-
# image.save(output_path)
37-
# print(f"Image saved to {output_path}")
38-
39-
# # 指定图片的宽度和高度
40-
# width = 800
41-
# height = 600
42-
# output_path = 'random_image.png'
43-
44-
# # 生成随机图片
45-
# generate_random_image(width, height, output_path)
46-
47-
# args:
48-
# image_s3_path: "image_${reqid}.jpg"
49-
# target_width: 50
50-
# target_height: 50
1+
minio:
2+
endpoint: "http://192.168.31.54:9009"
3+
access_key: "minioadmin"
4+
secret_key: "minioadmin123"
5+
compose_path: "../middlewares/minio/"
6+
7+
models:
8+
simple_demo:
9+
# name: "Simple Demo"
10+
# description: "A simple demo function"
11+
# language: "java"
12+
# runtime: "java11"
13+
# handler: "test.functions.Simple"
14+
# memory: 256
15+
# timeout: 30
16+
prepare_data: []
17+
prepare_scripts: []
18+
fns:
19+
simple:
20+
args: {}
21+
22+
img_resize:
23+
fns:
24+
resize:
25+
args:
26+
use_minio: true
27+
image_s3_path: "image_to_resize.png"
28+
target_width: 50
29+
target_height: 50
30+
prepare_data: ["image_to_resize.png"]
31+
prepare_scripts:
32+
- |
33+
from PIL import Image, ImageDraw
34+
import random
35+
36+
def generate_random_image(width, height, output_path):
37+
# 创建一个空白图像
38+
image = Image.new('RGB', (width, height), 'white')
39+
draw = ImageDraw.Draw(image)
40+
41+
# 生成随机颜色的像素
42+
for x in range(width):
43+
for y in range(height):
44+
r = random.randint(0, 255)
45+
g = random.randint(0, 255)
46+
b = random.randint(0, 255)
47+
draw.point((x, y), fill=(r, g, b))
48+
49+
# 保存图像
50+
image.save(output_path)
51+
print(f"Image saved to {output_path}")
52+
53+
# 指定图片的宽度和高度
54+
width = 800
55+
height = 600
56+
output_path = 'image_to_resize.png'
57+
58+
# 生成随机图片
59+
generate_random_image(width, height, output_path)
60+
61+
word_count:
62+
prepare_data:
63+
- large_text_file.txt
64+
prepare_scripts:
65+
- |
66+
import os
67+
68+
def generate_paragraph():
69+
paragraph = """
70+
In a far-off land, nestled among the mountains, lies a small village known for its unique culture and friendly inhabitants. Each spring, the villagers hold a grand festival to celebrate the arrival of the flowering season. Visitors from all corners gather to enjoy this beautiful moment. During the festival, people don traditional attire and dance joyfully, filling the village with laughter and cheer.
71+
"""
72+
return paragraph
73+
74+
def generate_large_text_file(file_path, target_size_gb):
75+
target_size_bytes = target_size_gb * 1024 * 1024 * 1024
76+
paragraph = generate_paragraph()
77+
paragraph_length = len(paragraph.encode('utf-8'))
78+
79+
with open(file_path, 'w') as file:
80+
while os.path.getsize(file_path) < target_size_bytes:
81+
file.write(paragraph)
82+
83+
final_size = os.path.getsize(file_path) / (1024 * 1024 * 1024)
84+
print(f"Generated file size: {final_size:.2f} GB")
85+
86+
# 生成一个 1 GB 大小的文件
87+
file_path = 'large_text_file.txt'
88+
target_size_gb = 1
89+
generate_large_text_file(file_path, target_size_gb)
90+
fns:
91+
count:
92+
args:
93+
text_s3_path: "large_text_file.txt"
94+
95+
# 函数配置项变体
96+
replicas: {}
97+
benchlist: {}
98+
# img_resize2: # 函数 和 是否使用minio排列组合,每种两个
99+
# source: img_resize
100+
101+
# img_resize3:
102+
# source: img_resize
103+
# args:
104+
# use_minio: false
105+
# img_resize4:
106+
# source: img_resize
107+
# args:
108+
# use_minio: false
109+
110+
111+
112+
# benchlist:
113+
# img_resize:
114+
# img_resize2:
115+
# img_resize3:
116+
# img_resize4:
117+
51118

52119
# parallel_composition:
53120
# parallel:
@@ -58,35 +125,7 @@ simple_demo:
58125
# args:
59126
# loopTime: 10000000
60127

61-
# word_count:
62-
# prepare_data:
63-
# - large_text_file.txt
64-
# prepare_scripts:
65-
# - |
66-
# import os
67-
68-
# def generate_paragraph():
69-
# paragraph = """
70-
# In a far-off land, nestled among the mountains, lies a small village known for its unique culture and friendly inhabitants. Each spring, the villagers hold a grand festival to celebrate the arrival of the flowering season. Visitors from all corners gather to enjoy this beautiful moment. During the festival, people don traditional attire and dance joyfully, filling the village with laughter and cheer.
71-
# """
72-
# return paragraph
73-
74-
# def generate_large_text_file(file_path, target_size_gb):
75-
# target_size_bytes = target_size_gb * 1024 * 1024 * 1024
76-
# paragraph = generate_paragraph()
77-
# paragraph_length = len(paragraph.encode('utf-8'))
78-
79-
# with open(file_path, 'w') as file:
80-
# while os.path.getsize(file_path) < target_size_bytes:
81-
# file.write(paragraph)
82-
83-
# final_size = os.path.getsize(file_path) / (1024 * 1024 * 1024)
84-
# print(f"Generated file size: {final_size:.2f} GB")
85-
86-
# # 生成一个 1 GB 大小的文件
87-
# file_path = 'large_text_file.txt'
88-
# target_size_gb = 1
89-
# generate_large_text_file(file_path, target_size_gb)
128+
90129

91130
# fns:
92131
# split:

bencher/src/_deperacated/demo_word_count.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,24 @@ impl SpecTarget for WordCount {
9797
receive_resp_time - start_call_ms
9898
);
9999

100+
// | cold start time
101+
// |
102+
// | fn_start_ms
103+
100104
println!("- req trans time: {}", req_arrive_time - start_call_ms);
101105
println!("- app verify time: {}", bf_exec_time - req_arrive_time);
102-
println!("- cold start time: {}", recover_begin_time - bf_exec_time);
103-
println!("- cold start time2: {}", fn_start_ms - recover_begin_time);
106+
println!(
107+
"- cold start time: {}",
108+
if bf_exec_time > recover_begin_time {
109+
recover_begin_time - bf_exec_time
110+
} else {
111+
0
112+
}
113+
);
114+
println!(
115+
"- cold start time2: {}",
116+
fn_start_ms - recover_begin_time.max(req_arrive_time)
117+
);
104118
println!("- exec time:{}", fn_end_ms - fn_start_ms);
105119
if fn_end_ms > receive_resp_time {
106120
println!(

bencher/src/common_prepare.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use std::{collections::HashMap, path::PathBuf, process::Stdio};
2+
3+
use tokio::{fs, process::Command};
4+
5+
use crate::config::Config;
6+
7+
/// return each app datas
8+
/// app->[data1,data2]
9+
pub async fn prepare_data(
10+
target_apps: Vec<String>,
11+
config: &Config,
12+
) -> HashMap<String, Vec<PathBuf>> {
13+
let mut prepare_data = HashMap::new();
14+
let model_apps: Vec<String> = target_apps
15+
.clone()
16+
.into_iter()
17+
.filter(|app| config.models.contains_key(app))
18+
.collect();
19+
20+
for app in model_apps {
21+
fs::create_dir_all(PathBuf::from("prepare_data").join(&app))
22+
.await
23+
.unwrap();
24+
let app_entry = config.models.get(&app).unwrap();
25+
for (i, script) in app_entry.prepare_scripts.iter().enumerate() {
26+
let script_path = PathBuf::from("prepare_data")
27+
.join(&app)
28+
.join(format!("prepare_{}.py", i));
29+
let script_dir = PathBuf::from("prepare_data").join(&app);
30+
let abs_script_dir = script_dir.canonicalize().unwrap();
31+
// let abs_script_path = script_path.canonicalize().unwrap();
32+
fs::write(&script_path, script).await.unwrap();
33+
34+
tracing::debug!(
35+
"prepare data for {} with script {}",
36+
app,
37+
script_path.to_str().unwrap()
38+
);
39+
let res = Command::new("python3")
40+
.args(&[script_path.file_name().unwrap().to_str().unwrap(), &*app])
41+
.stdout(Stdio::piped())
42+
.stderr(Stdio::piped())
43+
.current_dir(abs_script_dir)
44+
.spawn()
45+
.unwrap()
46+
.wait()
47+
.await
48+
.unwrap();
49+
if !res.success() {
50+
panic!(
51+
"prepare data for {} with script {} failed",
52+
app,
53+
script_path.to_str().unwrap()
54+
);
55+
}
56+
}
57+
58+
for data in app_entry.prepare_data.iter() {
59+
let data_path = PathBuf::from("prepare_data").join(&app).join(data);
60+
if !data_path.exists() {
61+
panic!("prepare data failed {:?}", data);
62+
}
63+
prepare_data
64+
.entry(app.to_owned())
65+
.or_insert(vec![])
66+
.push(data_path);
67+
}
68+
// for data in app_entry.prepare_data.iter() {
69+
// prepare_data.push(data.clone());
70+
// }
71+
}
72+
73+
prepare_data
74+
}

0 commit comments

Comments
 (0)