feat: benchmark init [SKIP CI]

This commit is contained in:
hadestructhor 2025-01-09 08:55:19 +01:00
parent eae6b8a7c2
commit 0fdf4c6c4a
8 changed files with 112 additions and 1 deletions

View file

@ -289,6 +289,20 @@ This is the biggest optimization in image size to date! A 1 998,2 MB less than
I personally love distroless images. I've seen people say that you can debug them less, and not having basic tools like a shell is contraining, but I personally think it's not needed. I personally love distroless images. I've seen people say that you can debug them less, and not having basic tools like a shell is contraining, but I personally think it's not needed.
You can simply build both a distroless and alpine image of your same code, then when there's a need to debug, scitch the container image for the alpine version. Or even better, use distroless images in production environments and alpines in development environments. You can simply build both a distroless and alpine image of your same code, then when there's a need to debug, scitch the container image for the alpine version. Or even better, use distroless images in production environments and alpines in development environments.
### Benchmark of build times using docker build --no-cache
Here's the link to the result of the benchmark made to recreate the image 100 times for each branch that contains each optimization:
[benchmark.md](./benchmark.md)
The nushell script used to generate this benchmark is [benchmark.nu](./benchmark.nu).
You can execute the following command to run the build 100 times on each branch:
```shell
nu benchmark.nu 100
```
By default the script runs 5 builds.
# Français # Français
@ -578,4 +592,18 @@ Et voici la taille des images juste ici :
C'est la plus grosse optimisation de taille jusqu'à présent ! Une différence de 1 998,2 MB de moins que l'image original, c'est 63,83 fois plus petit!!! C'est une réduction folle de 98,43% ! Et le meilleur dans tout ça? L'application est beaucoup plus sécurisé !!!!! C'est la plus grosse optimisation de taille jusqu'à présent ! Une différence de 1 998,2 MB de moins que l'image original, c'est 63,83 fois plus petit!!! C'est une réduction folle de 98,43% ! Et le meilleur dans tout ça? L'application est beaucoup plus sécurisé !!!!!
Personnellement j'adore les images distroless. J'ai vu certaines personnes dire qu'elles sont moins débuggable en n'ayant aucun outil basique comme un bash mais je pense que ce n'est pas nécessaire. Personnellement j'adore les images distroless. J'ai vu certaines personnes dire qu'elles sont moins débuggable en n'ayant aucun outil basique comme un bash mais je pense que ce n'est pas nécessaire.
Vous pouvez tout simplement construire une image alpine et distroless de votre application, puis remplacer votre image distroless par l'alpine pour débugger en cas de bug. Ou encore mieux et ce que je fais personnelelement, utiliser une image alpine en environnement de développement et distroless en production. Vous pouvez tout simplement construire une image alpine et distroless de votre application, puis remplacer votre image distroless par l'alpine pour débugger en cas de bug. Ou encore mieux et ce que je fais personnelelement, utiliser une image alpine en environnement de développement et distroless en production.
## Benchmark temps de build avec docker build --no-cache
Voici le lien du benchmark réalisé pour chaque branche en lançant la construction des conteneurs 100 fois:
[benchmark.md](./benchmark.md)
Le script nushell pour générer ce benchmark se trouve dans [benchmark.nu](./benchmark.nu)
Vous pouvez l'exécuter en lançant la commande suivante, pour lancer 100 build de chaque docker:
```shell
nu benchmark.nu 100
```
Par défaut le script lance 5 build de chaque image.

4
benchmark.md Normal file
View file

@ -0,0 +1,4 @@
| tag | image | image size | median_time | max_time | min_time | benchmark_size |
| --------------------------- | ---------------------- | ---------- | ------------------------ | ------------------------ | ------------------------ | -------------- |
| bun-rspack-dockerfile | react-bun-rspack | 66.5MB | 29sec 166ms 270µs 300ns | 29sec 166ms 270µs 300ns | 29sec 166ms 270µs 300ns | 1 |
| nginx-distroless-dockerfile | react-nginx-distroless | 31.8MB | 10sec 81ms 405µs | 10sec 81ms 405µs | 10sec 81ms 405µs | 1 |

71
benchmark.nu Normal file
View file

@ -0,0 +1,71 @@
def main [benchmark_size:int=5] -> table {
let date = date now | format date '%F_%H-%M-%S'
echo $'build_results_($date)'
mkdir $'build_results_($date)'
let bench = [
['tag', 'image'];
# ['simple-dockerfile', 'react-simple],
# ['multi-stage-dockerfile', 'react-multistage'],
# ['node-alpine-dockerfile', 'react-multistage-alpine'],
# ['nginx-dockerfile', 'react-nginx'],
# ['nginx-alpine-dockerfile', 'react-nginx-alpine'],
['bun-rspack-dockerfile', 'react-bun-rspack'],
['nginx-distroless-dockerfile', 'react-nginx-distroless']
]
let images = [
'node:18',
'node:18-alpine'
'nginx',
'nginx:stable-alpine',
'oven/bun',
'cgr.dev/chainguard/nginx'
]
echo 'Pulling all docker images in advance'
echo ''
for entry in $images {
docker pull $entry
echo ''
}
echo ''
mut benchmark: table<tag: string, image: string, 'image size': string, median_time: duration, max_time: duration, min_time: duration, benchmark_size: int> = []
for entry: record<tag: string, image:string> in $bench {
echo $'Switching to branch ($entry.tag)'
echo ''
git checkout $entry.tag
mut sum = 0ns
mut max = 0ns
mut min = 0ns
mut json_result = []
for i in 1..$benchmark_size {
let time = $'(timeit {docker build --no-cache -t $entry.image .})' | into duration
$sum += $time
if $max == 0ns or $time >= $max {
$max = $time
}
if $min == 0ns or $time <= $min {
$min = $time
}
$json_result = ($json_result ++ [['tag', 'image', 'time']; [$entry.tag, $entry.image, $time]])
}
let row table<tag: string, image: string, 'image size': string, median_time: duration, max_time: duration, min_time: duration, benchmark_size: int> = [
['tag', 'image', 'image size', 'median_time', 'max_time', 'min_time', 'benchmark_size'];
[$'($entry.tag)', $'($entry.image)', $"(docker image ls $entry.image | from ssv | get 0 | get SIZE)", ($sum / $benchmark_size), $max, $min, $benchmark_size]
]
$benchmark = ($benchmark ++ $row)
echo $json_result
$json_result | to csv | save -f $'./build_results_($date)/($entry.tag).csv'
}
git checkout main
$benchmark | to md --pretty | save -f benchmark.md
cp -r $'build_results_($date)/. build_results'
# git commit -m $"updated README for benchmarks (date now | format date '%+') [CI SKIP]"
# git push
return $benchmark
}

View file

@ -0,0 +1,2 @@
tag,image,time
bun-rspack-dockerfile,react-bun-rspack,9sec 220ms 258µs 900ns
1 tag image time
2 bun-rspack-dockerfile react-bun-rspack 9sec 220ms 258µs 900ns

View file

@ -0,0 +1,2 @@
tag,image,time
nginx-distroless-dockerfile,react-nginx-distroless,9sec 221ms 865µs 600ns
1 tag image time
2 nginx-distroless-dockerfile react-nginx-distroless 9sec 221ms 865µs 600ns

View file

@ -0,0 +1,2 @@
tag,image,time
bun-rspack-dockerfile,react-bun-rspack,29sec 166ms 270µs 300ns
1 tag image time
2 bun-rspack-dockerfile react-bun-rspack 29sec 166ms 270µs 300ns

View file

@ -0,0 +1,2 @@
tag,image,time
nginx-distroless-dockerfile,react-nginx-distroless,10sec 81ms 405µs
1 tag image time
2 nginx-distroless-dockerfile react-nginx-distroless 10sec 81ms 405µs

BIN
bun.lockb Normal file

Binary file not shown.