mirror of https://github.com/ivanch/tcc.git
Compare commits
2 Commits
bba35341fb
...
d5d2ab4956
Author | SHA1 | Date |
---|---|---|
José Henrique | d5d2ab4956 | |
José Henrique | 2e71c4e8ed |
|
@ -0,0 +1,26 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using TCC.Services;
|
||||||
|
|
||||||
|
namespace TCC.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("simulation")]
|
||||||
|
public class SimulationController : ControllerBase
|
||||||
|
{
|
||||||
|
public SimulationController()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("harmonic-progression")]
|
||||||
|
public async Task<IActionResult> GetHarmonicProgression([FromQuery] int n)
|
||||||
|
{
|
||||||
|
float sum = 0;
|
||||||
|
for (int i = 1; i <= n; i++)
|
||||||
|
{
|
||||||
|
sum += 1.0f / i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,11 +15,13 @@ RUN cd out && \
|
||||||
wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
|
wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
|
||||||
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
|
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
|
||||||
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
|
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
|
||||||
|
wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html && \
|
||||||
rm -rf runtimes && \
|
rm -rf runtimes && \
|
||||||
mkdir -p ./static && \
|
mkdir -p ./static && \
|
||||||
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
|
||||||
|
|
||||||
# Build runtime image
|
# Build runtime image
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim
|
||||||
|
|
|
@ -18,7 +18,8 @@ WORKDIR /app
|
||||||
|
|
||||||
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
|
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
|
||||||
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
|
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
|
||||||
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4
|
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
|
||||||
|
wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ RUN cargo build --release && \
|
||||||
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 && \
|
||||||
ldconfig /usr/local/lib
|
ldconfig /usr/local/lib
|
||||||
|
|
||||||
ENV LD_LIBRARY_PATH=/usr/local/lib
|
ENV LD_LIBRARY_PATH=/usr/local/lib
|
||||||
|
|
|
@ -15,6 +15,20 @@ async fn static_serve(req: HttpRequest) -> Result<NamedFile> {
|
||||||
Ok(NamedFile::open(real_path)?)
|
Ok(NamedFile::open(real_path)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/simulation/harmonic-progression")]
|
||||||
|
async fn simulation_harmonic_progression(req: HttpRequest) -> impl Responder {
|
||||||
|
let query_str = req.query_string();
|
||||||
|
let qs = QString::from(query_str);
|
||||||
|
let radius = qs.get("n").unwrap_or("1").parse::<f64>().unwrap_or(1.0);
|
||||||
|
|
||||||
|
let mut sum = 0.0;
|
||||||
|
for i in 1..=radius as i32 {
|
||||||
|
sum += 1.0 / i as f64;
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse::Ok().body(format!("{}", sum))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/image/load-small-image")]
|
#[get("/image/load-small-image")]
|
||||||
async fn load_small_image() -> Result<NamedFile> {
|
async fn load_small_image() -> Result<NamedFile> {
|
||||||
let real_path = "static/small-image.png";
|
let real_path = "static/small-image.png";
|
||||||
|
@ -74,6 +88,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.service(load_big_image)
|
.service(load_big_image)
|
||||||
.service(save_big_image)
|
.service(save_big_image)
|
||||||
.service(blur_image)
|
.service(blur_image)
|
||||||
|
.service(simulation_harmonic_progression)
|
||||||
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024))
|
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024))
|
||||||
})
|
})
|
||||||
.bind(("0.0.0.0", 5000))?
|
.bind(("0.0.0.0", 5000))?
|
||||||
|
|
|
@ -11,11 +11,13 @@ RUN apt-get update && apt-get install -y imagemagick && apt-get install -y wget
|
||||||
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
|
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
|
||||||
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
|
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
|
||||||
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
|
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
|
||||||
|
wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html && \
|
||||||
rm -rf runtimes && \
|
rm -rf runtimes && \
|
||||||
mkdir -p ./static && \
|
mkdir -p ./static && \
|
||||||
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
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from controllers.status import status_blueprint
|
from controllers.status import status_blueprint
|
||||||
|
from controllers.simulation import simulation_blueprint
|
||||||
from controllers.image import image_blueprint
|
from controllers.image import image_blueprint
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
#
|
#
|
||||||
app.register_blueprint(status_blueprint)
|
app.register_blueprint(status_blueprint)
|
||||||
|
app.register_blueprint(simulation_blueprint)
|
||||||
app.register_blueprint(image_blueprint)
|
app.register_blueprint(image_blueprint)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
from flask import request, Blueprint
|
||||||
|
|
||||||
|
simulation_blueprint = Blueprint('simulation_blueprint', __name__)
|
||||||
|
|
||||||
|
class SimulationController:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def harmonic_progression(self, n):
|
||||||
|
sum = 0
|
||||||
|
for i in range(1, n):
|
||||||
|
sum += 1/i
|
||||||
|
|
||||||
|
return sum
|
||||||
|
|
||||||
|
simulation_controller = SimulationController()
|
||||||
|
|
||||||
|
@simulation_blueprint.route('/simulation/harmonic-progression', methods=['GET'])
|
||||||
|
def return_ok():
|
||||||
|
n = int(request.args.get('n'))
|
||||||
|
sum = simulation_controller.harmonic_progression(n)
|
||||||
|
|
||||||
|
return str(sum), 200
|
|
@ -17,11 +17,13 @@ AVG_RUNS = 3
|
||||||
|
|
||||||
API_REQUESTS = [
|
API_REQUESTS = [
|
||||||
('/status/ok', 'GET', range(0, 30_000, 5000), None),
|
('/status/ok', 'GET', range(0, 30_000, 5000), None),
|
||||||
('/image/save-big-image', 'POST', range(0, 10_000, 1_000), open('big-image.png', 'rb').read()),
|
('/simulation/harmonic-progression?n=100000', 'GET', range(0, 30_000, 5000), None),
|
||||||
(f'/image/blur?radius={BLUR_RADIUS}', 'POST', range(0, 1_000, 50), open('small-image.png', 'rb').read()),
|
('/image/save-big-image', 'POST', range(0, 500, 50), open('big-image.png', 'rb').read()),
|
||||||
|
# (f'/image/blur?radius={BLUR_RADIUS}', 'POST', range(0, 500, 50), open('small-image.png', 'rb').read()),
|
||||||
('/image/load-small-image', 'GET', range(0, 30_000, 5000), None),
|
('/image/load-small-image', 'GET', range(0, 30_000, 5000), None),
|
||||||
('/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),
|
('/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/video.mp4', 'GET', range(0, 10_000, 1_000), None),
|
('/static/video.mp4', 'GET', range(0, 10_000, 1_000), None),
|
||||||
|
('/static/nginx.html', 'GET', range(0, 30_000, 5000), None),
|
||||||
]
|
]
|
|
@ -126,7 +126,9 @@ if __name__ == '__main__':
|
||||||
endpoint_file = endpoint_name.replace('/', '')
|
endpoint_file = endpoint_name.replace('/', '')
|
||||||
|
|
||||||
filename = f'data/resource_ASP.NET_{endpoint_file}.csv'
|
filename = f'data/resource_ASP.NET_{endpoint_file}.csv'
|
||||||
|
filename = filename.replace("?", "_")
|
||||||
generate_resource_graph(filename, framework_name, endpoint_name)
|
generate_resource_graph(filename, framework_name, endpoint_name)
|
||||||
|
|
||||||
filename = f'data/req_ASP.NET_{endpoint_file}.csv'
|
filename = f'data/req_ASP.NET_{endpoint_file}.csv'
|
||||||
|
filename = filename.replace("?", "_")
|
||||||
generate_req_graph(filename, framework_name, endpoint_name)
|
generate_req_graph(filename, framework_name, endpoint_name)
|
||||||
|
|
Loading…
Reference in New Issue