Compare commits

...

7 Commits

16 changed files with 58 additions and 137 deletions

View File

@@ -15,18 +15,6 @@ namespace TCC.Controllers
this.ImageService = imageService; 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")] [HttpPost("save-big-image")]
public async Task<IActionResult> SaveBigImage() public async Task<IActionResult> SaveBigImage()
{ {

View File

@@ -12,10 +12,10 @@ RUN dotnet restore
RUN dotnet build -c Release -o out RUN dotnet build -c Release -o out
RUN cd out && \ RUN cd out && \
wget https://files.ivanch.me/api/public/dl/a8pf5HZL/small-image.png && \ wget https://files.ivanch.me/api/public/dl/ch3NV0P8/small-image.png && \
wget https://files.ivanch.me/api/public/dl/ZoZDck7M/big-image.png && \ wget https://files.ivanch.me/api/public/dl/jNlXYMLR/big-image.png && \
wget https://files.ivanch.me/api/public/dl/URuFVrtX/video.mp4 && \ wget https://files.ivanch.me/api/public/dl/QdKvaeQI/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/aeZqpr_F/nginx.html && \ wget https://files.ivanch.me/api/public/dl/YD4vmSsO/nginx.html && \
rm -rf runtimes && \ rm -rf runtimes && \
mkdir -p ./static && \ mkdir -p ./static && \
mv small-image.png ./static && \ mv small-image.png ./static && \

View File

@@ -10,15 +10,5 @@
fileStream.CopyToAsync(file); fileStream.CopyToAsync(file);
file.Close(); 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,23 +1,22 @@
FROM rust:latest FROM rust:1.77-buster as builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bullseye-slim
WORKDIR /app WORKDIR /app
RUN apt-get update && apt-get -y install wget && \ RUN apt-get update && apt-get -y install wget && \
wget https://files.ivanch.me/api/public/dl/a8pf5HZL/small-image.png && \ wget https://files.ivanch.me/api/public/dl/ch3NV0P8/small-image.png && \
wget https://files.ivanch.me/api/public/dl/ZoZDck7M/big-image.png && \ wget https://files.ivanch.me/api/public/dl/jNlXYMLR/big-image.png && \
wget https://files.ivanch.me/api/public/dl/URuFVrtX/video.mp4 && \ wget https://files.ivanch.me/api/public/dl/QdKvaeQI/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/aeZqpr_F/nginx.html wget https://files.ivanch.me/api/public/dl/YD4vmSsO/nginx.html && \
mkdir -p ./static && \
COPY . .
RUN cargo build --release && \
cp ./target/release/ActixAPI . && \
mv small-image.png ./static && \ mv small-image.png ./static && \
mv big-image.png ./static && \ mv big-image.png ./static && \
mv video.mp4 ./static && \ mv video.mp4 ./static && \
mv nginx.html ./static && \ mv nginx.html ./static
ldconfig /usr/local/lib
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) 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")] #[post("/image/save-big-image")]
async fn save_big_image(image_data: web::Bytes) -> Result<HttpResponse> { async fn save_big_image(image_data: web::Bytes) -> Result<HttpResponse> {
// Write bytes to file
std::fs::write("image.png", &image_data).unwrap(); std::fs::write("image.png", &image_data).unwrap();
// Return the blurred image bytes
Ok(HttpResponse::Ok() Ok(HttpResponse::Ok()
.content_type("application/json") .content_type("application/json")
.body("{\"status\": 200}")) .body("{\"status\": 200}"))
@@ -97,8 +81,6 @@ async fn main() -> std::io::Result<()> {
App::new() App::new()
.route("/static/{filename:.*}", web::get().to(static_serve)) .route("/static/{filename:.*}", web::get().to(static_serve))
.service(hello) .service(hello)
.service(load_small_image)
.service(load_big_image)
.service(save_big_image) .service(save_big_image)
.service(simulation_harmonic_progression) .service(simulation_harmonic_progression)
.service(simulation_json) .service(simulation_json)

Submodule Express updated: 9916a85a0a...930a322dfa

View File

@@ -13,10 +13,10 @@ RUN apt-get update && \
mv bin/protoc /usr/local/bin/ && \ mv bin/protoc /usr/local/bin/ && \
rm -rf protoc-25.0-linux-x86_64.zip bin include readme.txt rm -rf protoc-25.0-linux-x86_64.zip bin include readme.txt
RUN wget https://files.ivanch.me/api/public/dl/a8pf5HZL/small-image.png && \ RUN wget https://files.ivanch.me/api/public/dl/ch3NV0P8/small-image.png && \
wget https://files.ivanch.me/api/public/dl/ZoZDck7M/big-image.png && \ wget https://files.ivanch.me/api/public/dl/jNlXYMLR/big-image.png && \
wget https://files.ivanch.me/api/public/dl/URuFVrtX/video.mp4 && \ wget https://files.ivanch.me/api/public/dl/QdKvaeQI/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/aeZqpr_F/nginx.html && \ wget https://files.ivanch.me/api/public/dl/YD4vmSsO/nginx.html && \
rm -rf runtimes && \ rm -rf runtimes && \
mkdir -p ./static && \ mkdir -p ./static && \
mv small-image.png ./static && \ mv small-image.png ./static && \

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -5,22 +5,6 @@ from flask import request, Response, Blueprint, jsonify, send_file
image_blueprint = Blueprint('image_blueprint', __name__) image_blueprint = Blueprint('image_blueprint', __name__)
image_service = ImageService() 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']) @image_blueprint.route('/image/save-big-image', methods=['POST'])
def save_image(): def save_image():
image_service.save_image(request.get_data()) image_service.save_image(request.get_data())

View File

@@ -4,4 +4,4 @@ status_blueprint = Blueprint('status_blueprint', __name__)
@status_blueprint.route('/status/ok', methods=['GET']) @status_blueprint.route('/status/ok', methods=['GET'])
def return_ok(): def return_ok():
return 200 return '', 200

View File

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

2
Spring

Submodule Spring updated: dedb3c1a24...1c28f5c8e3

View File

@@ -1,3 +1,4 @@
import json
import person_pb2 import person_pb2
person_proto = person_pb2.Person() person_proto = person_pb2.Person()
@@ -15,14 +16,14 @@ person_json = {
"email": "john.doe@email.com", "email": "john.doe@email.com",
"phone": "123-456-7890" "phone": "123-456-7890"
} }
person_json = str(person_json).encode('utf-8') person_json = json.dumps(person_json)
FRAMEWORKS = [ FRAMEWORKS = [
('Actix', 'tcc-actix', 'orange'), ('Actix', 'tcc-actix', 'orange'),
('ASP.NET', 'tcc-aspnet', 'blue'), ('ASP.NET', 'tcc-aspnet', 'blue'),
('Flask', 'tcc-flask', 'grey'), ('Flask', 'tcc-flask', 'grey'),
# ('Express', 'tcc-express', 'red'), ('Express', 'tcc-express', 'red'),
# ('Spring', 'tcc-spring', 'green'), ('Spring', 'tcc-spring', 'green'),
] ]
ENDPOINTS = { ENDPOINTS = {
@@ -33,17 +34,14 @@ ENDPOINTS = {
'Spring': 'http://localhost:9085', 'Spring': 'http://localhost:9085',
} }
AVG_RUNS = 5 AVG_RUNS = 30
API_REQUESTS = [ API_REQUESTS = [
# ('/status/ok', 'GET', range(0, 30_000, 5000), None), ('/status/ok', 'GET', range(0, 30_000, 5000), None),
# ('/simulation/harmonic-progression?n=100000', '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")),
# ('/image/save-big-image', 'POST', range(0, 500, 50), (open('big-image.png', 'rb').read(), "image/png")), ('/simulation/protobuf', 'POST', range(0, 30_000, 5000), (person_proto, "application/protobuf")),
# ('/image/load-small-image', 'GET', range(0, 30_000, 5000), None), ('/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/small-image.png', 'GET', range(0, 30_000, 5000), None),
# ('/image/load-big-image', 'GET', range(0, 500, 50), None), ('/static/big-image.png', 'GET', range(0, 500, 50), None),
# ('/static/big-image.png', 'GET', range(0, 500, 50), None),
# ('/static/nginx.html', 'GET', range(0, 30_000, 5000), None),
('/simulation/protobuf', 'POST', range(0, 30_000, 5000), (person_proto.SerializeToString(), "application/protobuf")),
] ]

View File

@@ -10,19 +10,20 @@ FRAMEWORKS = [f for f, _, _ in FRAMEWORKS]
def setBoxColors(bp): def setBoxColors(bp):
for i, box in enumerate(bp['boxes']): for i, box in enumerate(bp['boxes']):
box.set(color=FRAMEWORKS_COLORS[i]) box.set(color=FRAMEWORKS_COLORS[i])
for i, median in enumerate(bp['medians']): box.set(facecolor=FRAMEWORKS_COLORS[i])
# median.set(color=FRAMEWORKS_COLORS[i])
median.set(color='white')
for i in range(len(FRAMEWORKS)): for i in range(len(FRAMEWORKS)):
bp['whiskers'][i*2].set(color=FRAMEWORKS_COLORS[i]) bp['whiskers'][i*2].set(color=FRAMEWORKS_COLORS[i])
bp['whiskers'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i]) bp['whiskers'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i])
for i in range(len(FRAMEWORKS)): for i in range(len(FRAMEWORKS)):
bp['caps'][i*2].set(color=FRAMEWORKS_COLORS[i]) bp['caps'][i*2].set(color=FRAMEWORKS_COLORS[i])
bp['caps'][i*2 + 1].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): def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
print(filename)
old_x_data = x_data old_x_data = x_data
old_y_data = y_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)): for f in range(len(FRAMEWORKS)):
y_data[-1][f].append(old_y_data[f][i]) y_data[-1][f].append(old_y_data[f][i])
fig = figure() fig, axes = plt.subplots(ncols=len(x_data), sharey=True)
ax = axes()
all_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))])
print(filename) ax.set(xlabel=x_data[j], xticklabels=['' for _ in range(len(FRAMEWORKS))])
# print(y_data) ax.margins(0.05)
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)
setBoxColors(bp) setBoxColors(bp)
if j % 2 == 1:
ax.set_facecolor('#f2f2f2')
for i in range(len(FRAMEWORKS)): # set title
medians = [] fig.suptitle(title)
for j in range(len(x_data)): fig.supxlabel(x_label)
medians.append(np.median(y_data[j][i])) fig.supylabel(y_label)
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)
if y_lim: if y_lim:
plt.ylim(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.legend()
plt.tight_layout() plt.tight_layout()
fig.subplots_adjust(hspace=0, wspace=0)
plt.savefig(f'{filename}.png') plt.savefig(f'{filename}.png')
plt.clf() plt.clf()

View File

@@ -15,8 +15,8 @@ def download_file(url):
def init(): def init():
if not os.path.exists('small-image.png'): if not os.path.exists('small-image.png'):
download_file('https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png') download_file('https://files.ivanch.me/api/public/dl/ch3NV0P8/small-image.png')
if not os.path.exists('big-image.png'): if not os.path.exists('big-image.png'):
download_file('https://files.ivanch.me/api/public/dl/iFuXSNhw/big-image.png') download_file('https://files.ivanch.me/api/public/dl/jNlXYMLR/big-image.png')
init() init()

View File

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