feat: benchmark init [SKIP CI]
This commit is contained in:
parent
eae6b8a7c2
commit
386e660591
6 changed files with 122 additions and 1 deletions
38
README.md
38
README.md
|
@ -289,6 +289,24 @@ 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.
|
||||
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 10 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.
|
||||
|
||||
The build results can be found in the folder `build_results` in csv format.
|
||||
|
||||
Each branch that was benchmarked has a file associated named like `simple-dockerfile.csv` for the `simple-dockerfile` branch.
|
||||
|
||||
# Français
|
||||
|
||||
|
||||
|
@ -578,4 +596,22 @@ 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é !!!!!
|
||||
|
||||
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 10 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.
|
||||
|
||||
Les résultats de build peuvent être trouvé dans le dossier `build_results` sous le format csv.
|
||||
|
||||
Chaque branche qui a été benchmarké possède un fichier associé sous nommé par exemple `simple-dockerfile.csv` pour la branche `simple-dockerfile`.
|
||||
|
|
4
benchmark.md
Normal file
4
benchmark.md
Normal 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 |
|
77
benchmark.nu
Normal file
77
benchmark.nu
Normal file
|
@ -0,0 +1,77 @@
|
|||
def main [benchmark_size:int=5] -> table {
|
||||
let date = date now | format date '%F_%H-%M-%S'
|
||||
let res_dir = $'build_results_($date)'
|
||||
mkdir $res_dir
|
||||
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 csv_results = []
|
||||
for i in 1..$benchmark_size {
|
||||
echo $'Build ($i) out of ($benchmarck_size) for branch ($entry.tag)'
|
||||
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
|
||||
}
|
||||
$csv_results = ($csv_results ++ [['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]
|
||||
]
|
||||
echo $'Finieshed building ($benchmark_size) images'
|
||||
echo $'Results for branch ($entry.tag):'
|
||||
echo $csv_results
|
||||
$benchmark = ($benchmark ++ $row)
|
||||
$csv_results | to csv | save -f $'./($res_dir)/($entry.tag).csv'
|
||||
|
||||
echo ''
|
||||
}
|
||||
|
||||
git checkout main
|
||||
$benchmark | to md --pretty | save -f benchmark.md
|
||||
cp -rf $'./($res_dir)' $'./build_results'
|
||||
rm -rf $'./($res_dir)'
|
||||
git commit -m $"updated README for benchmarks (date now | format date '%+') [CI SKIP]"
|
||||
git push
|
||||
return $benchmark
|
||||
}
|
2
build_results/bun-rspack-dockerfile.csv
Normal file
2
build_results/bun-rspack-dockerfile.csv
Normal file
|
@ -0,0 +1,2 @@
|
|||
tag,image,time
|
||||
bun-rspack-dockerfile,react-bun-rspack,9sec 220ms 258µs 900ns
|
|
2
build_results/nginx-distroless-dockerfile.csv
Normal file
2
build_results/nginx-distroless-dockerfile.csv
Normal file
|
@ -0,0 +1,2 @@
|
|||
tag,image,time
|
||||
nginx-distroless-dockerfile,react-nginx-distroless,9sec 221ms 865µs 600ns
|
|
BIN
bun.lockb
Normal file
BIN
bun.lockb
Normal file
Binary file not shown.
Loading…
Reference in a new issue