feat: benchmark init [SKIP CI]
This commit is contained in:
parent
eae6b8a7c2
commit
ed53f66bb0
8 changed files with 112 additions and 1 deletions
28
README.md
28
README.md
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -579,3 +593,17 @@ C'est la plus grosse optimisation de taille jusqu'à présent ! Une différence
|
||||||
|
|
||||||
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
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 |
|
71
benchmark.nu
Normal file
71
benchmark.nu
Normal 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 -rf $'(pwd)/build_results_($date) (pwd)/build_results'
|
||||||
|
# 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
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
tag,image,time
|
||||||
|
bun-rspack-dockerfile,react-bun-rspack,29sec 166ms 270µs 300ns
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
tag,image,time
|
||||||
|
nginx-distroless-dockerfile,react-nginx-distroless,10sec 81ms 405µs
|
|
BIN
bun.lockb
Normal file
BIN
bun.lockb
Normal file
Binary file not shown.
Loading…
Reference in a new issue