Compare commits

...

3 Commits

11 changed files with 35 additions and 112 deletions

View File

@ -15,18 +15,6 @@ namespace TCC.Controllers
this.ImageService = imageService;
}
[HttpGet("load-small-image")]
public async Task<IActionResult> GetSimpleImage()
{
return File(ImageService.GetSimpleImage(), "image/png");
}
[HttpGet("load-big-image")]
public async Task<IActionResult> GetBigImage()
{
return File(ImageService.GetBigImage(), "image/png");
}
[HttpPost("save-big-image")]
public async Task<IActionResult> SaveBigImage()
{

View File

@ -10,15 +10,5 @@
fileStream.CopyToAsync(file);
file.Close();
}
public byte[] GetSimpleImage()
{
return File.ReadAllBytes("static/small-image.png");
}
public byte[] GetBigImage()
{
return File.ReadAllBytes("static/big-image.png");
}
}
}

View File

@ -1,5 +1,9 @@
FROM rust:latest
FROM rust:1.77-buster as builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bullseye-slim
WORKDIR /app
RUN apt-get update && apt-get -y install wget && \
@ -7,17 +11,12 @@ RUN apt-get update && apt-get -y install wget && \
wget https://files.ivanch.me/api/public/dl/jNlXYMLR/big-image.png && \
wget https://files.ivanch.me/api/public/dl/QdKvaeQI/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/YD4vmSsO/nginx.html && \
COPY . .
RUN cargo build --release && \
cp ./target/release/ActixAPI . && \
mkdir -p ./static && \
mv small-image.png ./static && \
mv big-image.png ./static && \
mv video.mp4 ./static && \
mv nginx.html ./static && \
ldconfig /usr/local/lib
mv nginx.html ./static
ENV LD_LIBRARY_PATH=/usr/local/lib
COPY --from=builder /app/target/release/ActixAPI .
ENTRYPOINT ["./ActixAPI"]
CMD ["./ActixAPI"]

View File

@ -64,26 +64,10 @@ async fn simulation_protobuf(msg: ProtoBuf<PersonProtobuf>) -> impl Responder {
HttpResponse::Ok().protobuf(msg.0)
}
#[get("/image/load-small-image")]
async fn load_small_image() -> Result<NamedFile> {
let real_path = "static/small-image.png";
Ok(NamedFile::open(real_path)?)
}
#[get("/image/load-big-image")]
async fn load_big_image() -> Result<NamedFile> {
let real_path = "static/big-image.png";
Ok(NamedFile::open(real_path)?)
}
#[post("/image/save-big-image")]
async fn save_big_image(image_data: web::Bytes) -> Result<HttpResponse> {
// Write bytes to file
std::fs::write("image.png", &image_data).unwrap();
// Return the blurred image bytes
Ok(HttpResponse::Ok()
.content_type("application/json")
.body("{\"status\": 200}"))
@ -97,8 +81,6 @@ async fn main() -> std::io::Result<()> {
App::new()
.route("/static/{filename:.*}", web::get().to(static_serve))
.service(hello)
.service(load_small_image)
.service(load_big_image)
.service(save_big_image)
.service(simulation_harmonic_progression)
.service(simulation_json)

@ -1 +1 @@
Subproject commit 3a54792794728b10b2f49bd47dbd7430da811bdd
Subproject commit 930a322dfac69d25aa2b91ed478c2c4d46bfc68d

View File

@ -5,22 +5,6 @@ from flask import request, Response, Blueprint, jsonify, send_file
image_blueprint = Blueprint('image_blueprint', __name__)
image_service = ImageService()
@image_blueprint.route('/image/load-small-image', methods=['GET'])
def get_simple_image():
return send_file(io.BytesIO(image_service.get_simple_image()),
mimetype='image/png',
as_attachment=True,
download_name='small-image.png')
@image_blueprint.route('/image/load-big-image', methods=['GET'])
def get_big_image():
return send_file(io.BytesIO(image_service.get_big_image()),
mimetype='image/png',
as_attachment=True,
download_name='big-image.png')
@image_blueprint.route('/image/save-big-image', methods=['POST'])
def save_image():
image_service.save_image(request.get_data())

View File

@ -1,3 +1,3 @@
Flask>=1.0
gunicorn>=19.9.0
protobuf>=4.25.0
Flask==3.0
gunicorn==19.9.0
protobuf==4.25.0

2
Spring

@ -1 +1 @@
Subproject commit 281dc597169d9934935d7aeed570434f63a3e358
Subproject commit 1c28f5c8e33c96d8389cda306442a8a25fc1e377

View File

@ -34,14 +34,14 @@ ENDPOINTS = {
'Spring': 'http://localhost:9085',
}
AVG_RUNS = 5
AVG_RUNS = 30
API_REQUESTS = [
('/status/ok', 'GET', range(0, 30_000, 5000), None),
('/simulation/harmonic-progression?n=100000', 'GET', range(0, 30_000, 5000), None),
# ('/simulation/json', 'POST', range(0, 30_000, 5000), (person_json, "application/json")),
('/simulation/json', 'POST', range(0, 30_000, 5000), (person_json, "application/json")),
('/simulation/protobuf', 'POST', range(0, 30_000, 5000), (person_proto, "application/protobuf")),
('/image/save-big-image', 'POST', range(0, 500, 50), (open('big-image.png', 'rb').read(), "image/png")),
('/static/small-image.png', 'GET', range(0, 30_000, 5000), None),
('/static/big-image.png', 'GET', range(0, 500, 50), None),
# ('/simulation/protobuf', 'POST', range(0, 30_000, 5000), (person_proto, "application/protobuf")),
]

View File

@ -10,19 +10,20 @@ FRAMEWORKS = [f for f, _, _ in FRAMEWORKS]
def setBoxColors(bp):
for i, box in enumerate(bp['boxes']):
box.set(color=FRAMEWORKS_COLORS[i])
for i, median in enumerate(bp['medians']):
# median.set(color=FRAMEWORKS_COLORS[i])
median.set(color='white')
box.set(facecolor=FRAMEWORKS_COLORS[i])
for i in range(len(FRAMEWORKS)):
bp['whiskers'][i*2].set(color=FRAMEWORKS_COLORS[i])
bp['whiskers'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i])
for i in range(len(FRAMEWORKS)):
bp['caps'][i*2].set(color=FRAMEWORKS_COLORS[i])
bp['caps'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i])
for i, median in enumerate(bp['medians']):
median.set(color='white')
def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
print(filename)
old_x_data = x_data
old_y_data = y_data
@ -39,40 +40,20 @@ def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
for f in range(len(FRAMEWORKS)):
y_data[-1][f].append(old_y_data[f][i])
fig = figure()
ax = axes()
fig, axes = plt.subplots(ncols=len(x_data), sharey=True)
all_positions = []
print(filename)
# print(y_data)
for j in range(len(x_data)):
positions = [len(FRAMEWORKS)*j + i + 2*j for i in range(len(FRAMEWORKS))]
bp = boxplot(y_data[j], positions = positions, widths = 0.6, showfliers=False,
patch_artist=True)
all_positions.append(positions)
for ax, j in zip(axes, [i for i in range(len(x_data))]):
bp = ax.boxplot(y_data[j], showfliers=False, patch_artist=True, positions=[i for i in range(len(FRAMEWORKS))])
ax.set(xlabel=x_data[j], xticklabels=['' for _ in range(len(FRAMEWORKS))])
ax.margins(0.05)
setBoxColors(bp)
if j % 2 == 1:
ax.set_facecolor('#f2f2f2')
for i in range(len(FRAMEWORKS)):
medians = []
for j in range(len(x_data)):
medians.append(np.median(y_data[j][i]))
positions = [all_positions[x][i] for x in range(len(x_data))]
plt.plot(positions, medians, color=FRAMEWORKS_COLORS[i], marker='.', linestyle='--', linewidth=0.3)
avg_positions = []
for positions in all_positions:
avg = np.average(positions)
avg_positions.append(avg)
ax.set_xticks(avg_positions)
ax.set_xticklabels([str(x) for x in x_data])
plt.title(title)
plt.xlabel(x_label)
plt.ylabel(y_label)
# set title
fig.suptitle(title)
fig.supxlabel(x_label)
fig.supylabel(y_label)
if y_lim:
plt.ylim(y_lim)
@ -85,6 +66,7 @@ def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
plt.legend()
plt.tight_layout()
fig.subplots_adjust(hspace=0, wspace=0)
plt.savefig(f'{filename}.png')
plt.clf()

View File

@ -76,8 +76,6 @@ def run_tests(endpoint, method, num_requests, metadata):
start_time = time.time()
futures = []
#with requests.Session() as session:
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
half = floor(num_request/2)
for i in range(num_request):
@ -104,7 +102,7 @@ def run_tests(endpoint, method, num_requests, metadata):
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
record_resource(files[1], num_request, cpu, ram)
time.sleep(3)
time.sleep(30)
def get_resource_usage():
if CONTAINER_NAME == "": return 0, 0