adding protobuf

This commit is contained in:
José Henrique Ivanchechen 2023-11-02 19:14:16 -03:00
parent 2965293bfb
commit ac8bff31f2
12 changed files with 324 additions and 449 deletions

View File

@ -15,23 +15,6 @@ namespace TCC.Controllers
this.ImageService = imageService;
}
[HttpPost("blur")]
public async Task<IActionResult> BlurImage([FromQuery] int radius)
{
MemoryStream mstream = new MemoryStream();
await HttpContext.Request.Body.CopyToAsync(mstream);
mstream.Position = 0;
var result = ImageService.BoxBlurImage(mstream, radius);
mstream.Close();
var blurredImageStream = new MemoryStream();
result.Write(blurredImageStream);
blurredImageStream.Position = 0;
return File(blurredImageStream, "image/png");
}
[HttpGet("load-small-image")]
public async Task<IActionResult> GetSimpleImage()
{

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using TCC.Services;
using ProtoBuf;
using System.IO;
namespace TCC.Controllers
{
@ -14,7 +15,7 @@ namespace TCC.Controllers
[HttpGet("harmonic-progression")]
public async Task<IActionResult> GetHarmonicProgression([FromQuery] int n)
{
float sum = 0;
double sum = 0;
for (int i = 1; i <= n; i++)
{
sum += 1.0f / i;
@ -28,5 +29,33 @@ namespace TCC.Controllers
{
return Ok(new { message = "Hello World!" });
}
[HttpPost("protobuf")]
public async Task<IActionResult> PostProtobuf()
{
HelloWorld cliente;
byte[] response;
using (var stream = Request.BodyReader.AsStream())
{
cliente = ProtoBuf.Serializer.Deserialize<HelloWorld>(stream);
}
using (var stream = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(stream, cliente);
response = stream.ToArray();
}
await Response.Body.WriteAsync(response, 0, response.Length);
return new EmptyResult();
}
}
[ProtoContract()]
public class HelloWorld
{
[ProtoMember(1)]
public string Message { get; set; }
}
}

View File

@ -1,61 +1,9 @@
using ImageMagick;
namespace TCC.Services
namespace TCC.Services
{
public class ImageService
{
public ImageService() { }
public MagickImage BoxBlurImage(Stream imageStream, int radius)
{
var image = new MagickImage(imageStream);
image.GaussianBlur(radius, radius);
return image;
//var blurredImage = new MagickImage(image);
//blurredImage = BoxBlurImageSeparable(image, blurredImage, radius, 0);
//blurredImage = BoxBlurImageSeparable(blurredImage, blurredImage, 0, radius);
//return blurredImage;
}
private MagickImage BoxBlurImageSeparable(MagickImage image, MagickImage blurredImage, int radiusX, int radiusY)
{
var pixels = image.GetPixels();
var blurredPixels = blurredImage.GetPixelsUnsafe();
foreach (var pixel in pixels)
{
int x = pixel.X,
y = pixel.Y;
long rTotal = 0, gTotal = 0, bTotal = 0;
int pixelCount = 0;
for (int offsetY = -radiusY; offsetY <= radiusY; offsetY++)
{
for (int offsetX = -radiusX; offsetX <= radiusX; offsetX++)
{
int newX = x + offsetX;
int newY = y + offsetY;
if (newX >= 0 && newX < image.Width && newY >= 0 && newY < image.Height)
{
var pixelColor = pixels[newX, newY];
rTotal += pixelColor.GetChannel(0);
gTotal += pixelColor.GetChannel(1);
bTotal += pixelColor.GetChannel(2);
pixelCount++;
}
}
}
blurredPixels[x, y].SetChannel(0, Convert.ToUInt16(rTotal / pixelCount));
blurredPixels[x, y].SetChannel(1, Convert.ToUInt16(gTotal / pixelCount));
blurredPixels[x, y].SetChannel(2, Convert.ToUInt16(bTotal / pixelCount));
}
return blurredImage;
}
public void SaveImage(Stream fileStream)
{
var file = File.Create("image.png");

View File

@ -11,8 +11,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.2.0" />
<PackageReference Include="Magick.NET.Core" Version="13.2.0" />
<PackageReference Include="protobuf-net" Version="3.2.26" />
</ItemGroup>
<ItemGroup>

496
ActixAPI/Cargo.lock generated
View File

@ -7,9 +7,10 @@ name = "ActixAPI"
version = "0.1.0"
dependencies = [
"actix-files",
"actix-protobuf",
"actix-web",
"futures",
"magick_rust",
"prost",
"qstring",
"serde",
"serde_json",
@ -67,7 +68,7 @@ dependencies = [
"actix-utils",
"ahash",
"base64",
"bitflags 2.4.0",
"bitflags 2.4.1",
"brotli",
"bytes",
"bytestring",
@ -101,7 +102,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb"
dependencies = [
"quote",
"syn 2.0.32",
"syn 2.0.38",
]
[[package]]
name = "actix-protobuf"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a14dd296f850b814ca6f21d9a8ab92232887c07be2082562b5f3e33286f5b24d"
dependencies = [
"actix-web",
"derive_more",
"futures-util",
"prost",
]
[[package]]
@ -214,7 +227,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
"syn 2.0.32",
"syn 2.0.38",
]
[[package]]
@ -234,21 +247,22 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ahash"
version = "0.8.3"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
dependencies = [
"cfg-if",
"getrandom",
"once_cell",
"version_check",
"zerocopy",
]
[[package]]
name = "aho-corasick"
version = "1.0.5"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
@ -268,6 +282,12 @@ dependencies = [
"alloc-no-stdlib",
]
[[package]]
name = "anyhow"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "askama_escape"
version = "0.10.3"
@ -297,32 +317,9 @@ dependencies = [
[[package]]
name = "base64"
version = "0.21.4"
version = "0.21.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2"
[[package]]
name = "bindgen"
version = "0.68.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078"
dependencies = [
"bitflags 2.4.0",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"prettyplease",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn 2.0.32",
"which",
]
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
[[package]]
name = "bitflags"
@ -332,9 +329,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.0"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "block-buffer"
@ -347,9 +344,9 @@ dependencies = [
[[package]]
name = "brotli"
version = "3.3.4"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68"
checksum = "516074a47ef4bce09577a3b379392300159ce5b1ba2e501ff1c819950066100f"
dependencies = [
"alloc-no-stdlib",
"alloc-stdlib",
@ -358,9 +355,9 @@ dependencies = [
[[package]]
name = "brotli-decompressor"
version = "2.3.4"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b6561fd3f895a11e8f72af2cb7d22e08366bebc2b6b57f7744c4bda27034744"
checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f"
dependencies = [
"alloc-no-stdlib",
"alloc-stdlib",
@ -374,9 +371,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]]
name = "bytestring"
version = "1.3.0"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "238e4886760d98c4f899360c834fa93e62cf7f721ac3c2da375cbdf4b8679aae"
checksum = "74d80203ea6b29df88012294f62733de21cfeab47f17b41af3a38bc30a03ee72"
dependencies = [
"bytes",
]
@ -391,32 +388,12 @@ dependencies = [
"libc",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clang-sys"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "convert_case"
version = "0.4.0"
@ -436,9 +413,9 @@ dependencies = [
[[package]]
name = "cpufeatures"
version = "0.2.9"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0"
dependencies = [
"libc",
]
@ -464,9 +441,12 @@ dependencies = [
[[package]]
name = "deranged"
version = "0.3.8"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946"
checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
dependencies = [
"powerfmt",
]
[[package]]
name = "derive_more"
@ -506,32 +486,11 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "errno"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd"
dependencies = [
"errno-dragonfly",
"libc",
"windows-sys",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "flate2"
version = "1.0.27"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010"
checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e"
dependencies = [
"crc32fast",
"miniz_oxide",
@ -554,9 +513,9 @@ dependencies = [
[[package]]
name = "futures"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335"
dependencies = [
"futures-channel",
"futures-core",
@ -569,9 +528,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
dependencies = [
"futures-core",
"futures-sink",
@ -579,15 +538,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
[[package]]
name = "futures-executor"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc"
dependencies = [
"futures-core",
"futures-task",
@ -602,32 +561,32 @@ checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
[[package]]
name = "futures-macro"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.32",
"syn 2.0.38",
]
[[package]]
name = "futures-sink"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
[[package]]
name = "futures-task"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
[[package]]
name = "futures-util"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
dependencies = [
"futures-channel",
"futures-core",
@ -668,12 +627,6 @@ version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "h2"
version = "0.3.21"
@ -699,15 +652,6 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "home"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb"
dependencies = [
"windows-sys",
]
[[package]]
name = "http"
version = "0.2.9"
@ -757,6 +701,15 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.9"
@ -765,9 +718,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "jobserver"
version = "0.1.26"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2"
checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d"
dependencies = [
"libc",
]
@ -778,63 +731,34 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.147"
version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
name = "libloading"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "linux-raw-sys"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "local-channel"
version = "0.1.3"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f303ec0e94c6c54447f84f3b0ef7af769858a9c4ef56ef2a986d3dcd4c3fc9c"
checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8"
dependencies = [
"futures-core",
"futures-sink",
"futures-util",
"local-waker",
]
[[package]]
name = "local-waker"
version = "0.1.3"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e34f76eb3611940e0e7d53a9aaa4e6a3151f69541a282fd0dad5571420c53ff1"
checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487"
[[package]]
name = "lock_api"
version = "0.4.10"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
@ -846,22 +770,11 @@ version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "magick_rust"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c912b69250bcd5d024852a1a75c567d3b5d881871a55b741018741632a921bf8"
dependencies = [
"bindgen",
"libc",
"pkg-config",
]
[[package]]
name = "memchr"
version = "2.6.3"
version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "mime"
@ -879,12 +792,6 @@ dependencies = [
"unicase",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.7.1"
@ -896,9 +803,9 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.8"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
dependencies = [
"libc",
"log",
@ -906,16 +813,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "object"
version = "0.32.1"
@ -943,9 +840,9 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.9.8"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
@ -960,12 +857,6 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "percent-encoding"
version = "2.3.0"
@ -990,6 +881,12 @@ version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@ -997,22 +894,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "prettyplease"
version = "0.2.15"
name = "proc-macro2"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"proc-macro2",
"syn 2.0.32",
"unicode-ident",
]
[[package]]
name = "proc-macro2"
version = "1.0.66"
name = "prost"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d"
dependencies = [
"unicode-ident",
"bytes",
"prost-derive",
]
[[package]]
name = "prost-derive"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32"
dependencies = [
"anyhow",
"itertools",
"proc-macro2",
"quote",
"syn 2.0.38",
]
[[package]]
@ -1065,18 +975,18 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.3.5"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "regex"
version = "1.9.5"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47"
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick",
"memchr",
@ -1086,9 +996,9 @@ dependencies = [
[[package]]
name = "regex-automata"
version = "0.3.8"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick",
"memchr",
@ -1097,9 +1007,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.7.5"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "rustc-demangle"
@ -1107,12 +1017,6 @@ version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.4.0"
@ -1122,19 +1026,6 @@ dependencies = [
"semver",
]
[[package]]
name = "rustix"
version = "0.38.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662"
dependencies = [
"bitflags 2.4.0",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "ryu"
version = "1.0.15"
@ -1149,35 +1040,35 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "semver"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.32",
"syn 2.0.38",
]
[[package]]
name = "serde_json"
version = "1.0.106"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -1198,21 +1089,15 @@ dependencies = [
[[package]]
name = "sha1"
version = "0.10.5"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3"
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "shlex"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
@ -1233,15 +1118,15 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "socket2"
version = "0.5.4"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
dependencies = [
"libc",
"windows-sys",
@ -1260,9 +1145,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.32"
version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
@ -1271,12 +1156,13 @@ dependencies = [
[[package]]
name = "time"
version = "0.3.28"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48"
checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
dependencies = [
"deranged",
"itoa",
"powerfmt",
"serde",
"time-core",
"time-macros",
@ -1284,15 +1170,15 @@ dependencies = [
[[package]]
name = "time-core"
version = "0.1.1"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb"
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572"
checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
dependencies = [
"time-core",
]
@ -1314,9 +1200,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.32.0"
version = "1.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653"
dependencies = [
"backtrace",
"bytes",
@ -1331,9 +1217,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.8"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d"
checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
dependencies = [
"bytes",
"futures-core",
@ -1345,11 +1231,10 @@ dependencies = [
[[package]]
name = "tracing"
version = "0.1.37"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"cfg-if",
"log",
"pin-project-lite",
"tracing-core",
@ -1357,18 +1242,18 @@ dependencies = [
[[package]]
name = "tracing-core"
version = "0.1.31"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
]
[[package]]
name = "typenum"
version = "1.16.0"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicase"
@ -1387,9 +1272,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
[[package]]
name = "unicode-ident"
version = "1.0.11"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
@ -1423,40 +1308,6 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "which"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
dependencies = [
"either",
"home",
"once_cell",
"rustix",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.48.0"
@ -1523,6 +1374,26 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "zerocopy"
version = "0.7.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e50cbb27c30666a6108abd6bc7577556265b44f243e2be89a8bc4e07a528c107"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a25f293fe55f0a48e7010d65552bb63704f6ceb55a1a385da10d41d8f78e4a3d"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
]
[[package]]
name = "zstd"
version = "0.12.4"
@ -1544,11 +1415,10 @@ dependencies = [
[[package]]
name = "zstd-sys"
version = "2.0.8+zstd.1.5.5"
version = "2.0.9+zstd.1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c"
checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656"
dependencies = [
"cc",
"libc",
"pkg-config",
]

View File

@ -8,8 +8,9 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-files = "0.6.2"
magick_rust = "0.19.1"
qstring = "0.7.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
futures = "0.3"
actix-protobuf = "0.10.0"
prost = { version = "0.12", features = ["prost-derive"] }

View File

@ -1,22 +1,9 @@
FROM rust:latest
ENV MAGICK_VERSION 7.1
RUN apt-get update \
&& apt-get -y install wget curl build-essential clang pkg-config libjpeg-turbo-progs libpng-dev
RUN apt update && apt install curl -y \
&& curl https://imagemagick.org/archive/ImageMagick.tar.gz | tar xz \
&& cd ImageMagick-${MAGICK_VERSION}* \
&& ./configure --with-magick-plus-plus=no --with-perl=no \
&& make \
&& make install \
&& cd .. \
&& rm -r ImageMagick-${MAGICK_VERSION}*
WORKDIR /app
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
RUN RUN apt-get update && apt-get -y install wget && \
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/nAndfAjK/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html

View File

@ -1,7 +1,15 @@
use qstring::QString;
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, HttpRequest, Result};
use actix_files::NamedFile;
use magick_rust::MagickWand;
// use actix_protobuf::{ProtoBuf, ProtoBufResponseBuilder as _};
use actix_protobuf::*;
use prost::Message;
#[derive(Clone, PartialEq, Eq, Message)]
pub struct HelloWorld {
#[prost(string, tag = "1")]
pub message: String
}
#[get("/status/ok")]
async fn hello() -> impl Responder {
@ -31,7 +39,6 @@ async fn simulation_harmonic_progression(req: HttpRequest) -> impl Responder {
#[get("/simulation/json")]
async fn simulation_json() -> impl Responder {
// body = {"message": "Hello World"}
let body = serde_json::json!({
"message": "Hello World!"
});
@ -40,6 +47,13 @@ async fn simulation_json() -> impl Responder {
.json(body)
}
#[post("/simulation/protobuf")]
async fn simulation_protobuf(msg: ProtoBuf<HelloWorld>) -> impl Responder {
println!("model: {:?}", 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";
@ -65,28 +79,6 @@ async fn save_big_image(image_data: web::Bytes) -> Result<HttpResponse> {
.body("{\"status\": 200}"))
}
#[post("/image/blur")]
async fn blur_image(image_data: web::Bytes, req: HttpRequest) -> Result<HttpResponse> {
// Load the image from the incoming bytes
let mut wand = MagickWand::new();
wand.read_image_blob(&image_data).unwrap();
let query_str = req.query_string();
let qs = QString::from(query_str);
let radius = qs.get("radius").unwrap_or("5").parse::<f64>().unwrap_or(5.0);
// Blur the image
wand.blur_image(radius, radius).unwrap();
// Convert the image back to bytes
let blurred_image_bytes = wand.write_image_blob("png").unwrap();
// Return the blurred image bytes
Ok(HttpResponse::Ok()
.content_type("image/png")
.body(blurred_image_bytes))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Hello, world!");
@ -98,9 +90,9 @@ async fn main() -> std::io::Result<()> {
.service(load_small_image)
.service(load_big_image)
.service(save_big_image)
.service(blur_image)
.service(simulation_harmonic_progression)
.service(simulation_json)
.service(simulation_protobuf)
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024))
})
.bind(("0.0.0.0", 5000))?

View File

@ -1,9 +1,14 @@
import helloworld_pb2
helloworld = helloworld_pb2.MyObj()
helloworld.message = "Hello World!"
FRAMEWORKS = [
('Actix', 'tcc-actix', 'orange'),
('ASP.NET', 'tcc-aspnet', 'blue'),
('Flask', 'tcc-flask', 'green'),
('Flask', 'tcc-flask', 'grey'),
('Express', 'tcc-express', 'red'),
('Spring', 'tcc-spring', 'pink'),
('Spring', 'tcc-spring', 'green'),
]
ENDPOINTS = {
@ -15,15 +20,16 @@ ENDPOINTS = {
}
AVG_RUNS = 5
helloworld_pb2
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', 'GET', range(0, 30_000, 5000), None),
('/image/save-big-image', 'POST', range(0, 500, 50), open('big-image.png', 'rb').read()),
('/image/load-small-image', '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/nginx.html', 'GET', range(0, 30_000, 5000), None),
# ('/simulation/harmonic-progression?n=100000', 'GET', range(0, 30_000, 5000), None),
# ('/simulation/json', 'GET', range(0, 30_000, 5000), None),
# ('/image/save-big-image', 'POST', range(0, 500, 50), open('big-image.png', 'rb').read()),
# ('/image/load-small-image', '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/nginx.html', 'GET', range(0, 30_000, 5000), None),
('/simulation/protobuf', 'POST', range(0, 30_000, 5000), helloworld.SerializeToString()),
]

View File

@ -10,6 +10,17 @@ 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')
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])
def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
old_x_data = x_data
@ -22,10 +33,10 @@ def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
if old_x_data[i] not in x_data:
x_data.append(old_x_data[i])
y_data.append([])
for f in range(2):
for f in range(len(FRAMEWORKS)):
y_data[-1].append([])
for f in range(2):
for f in range(len(FRAMEWORKS)):
y_data[-1][f].append(old_y_data[f][i])
fig = figure()
@ -33,15 +44,28 @@ def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
all_positions = []
print(filename)
# print(y_data)
for j in range(len(x_data)):
positions = [len(FRAMEWORKS)*j + i + 1 for i in range(len(FRAMEWORKS))]
bp = boxplot(y_data[j], positions = positions, widths = 0.6)
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)
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_positions.append(np.average(positions))
avg = np.average(positions)
avg_positions.append(avg)
ax.set_xticks(avg_positions)
ax.set_xticklabels([str(x) for x in x_data])
@ -53,11 +77,14 @@ def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
if y_lim:
plt.ylim(y_lim)
if filename.startswith('req'):
for i, framework in enumerate(FRAMEWORKS):
h, = plt.plot([], c=FRAMEWORKS_COLORS[i], label=framework)
h, = plt.plot([], c=FRAMEWORKS_COLORS[i], label=framework, marker='.', linestyle='--')
# h.set_visible(False)
plt.legend()
plt.tight_layout()
plt.savefig(f'{filename}.png')
plt.clf()
@ -134,6 +161,8 @@ if __name__ == '__main__':
framework_name = 'ASP.NET'
endpoint_file = endpoint_name.replace('/', '')
endpoint_name = '/' + endpoint_name.split('/')[-1]
filename = f'data/resource_ASP.NET_{endpoint_file}.csv'
filename = filename.replace("?", "_")
generate_resource_graph(filename, framework_name, endpoint_name)

5
scripts/helloworld.proto Normal file
View File

@ -0,0 +1,5 @@
syntax = "proto3";
message MyObj {
string message = 1;
}

26
scripts/helloworld_pb2.py Normal file
View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: helloworld.proto
# Protobuf Python Version: 4.25.0
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10helloworld.proto\"\x18\n\x05MyObj\x12\x0f\n\x07message\x18\x01 \x01(\tb\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'helloworld_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
_globals['_MYOBJ']._serialized_start=20
_globals['_MYOBJ']._serialized_end=44
# @@protoc_insertion_point(module_scope)