-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1288 from tejal29/benchmark-snapshot
benchmark FileSystem snapshot project added
- Loading branch information
Showing
7 changed files
with
219 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
out/ | ||
.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM bash:4.4 | ||
|
||
ARG NUM | ||
COPY context.txt . | ||
COPY make.sh . | ||
SHELL ["/usr/local/bin/bash", "-c"] | ||
RUN ./make.sh $NUM | ||
RUN ls -al /workdir | wc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/local/bin/bash | ||
|
||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
mkdir /workdir | ||
|
||
i=1 | ||
while [ $i -le $1 ] | ||
do | ||
cat context.txt > /workdir/somefile$i | ||
i=$(( $i + 1 )) | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"sync" | ||
"testing" | ||
"time" | ||
) | ||
|
||
type result struct { | ||
totalBuildTime float64 | ||
resolvingFiles float64 | ||
walkingFiles float64 | ||
} | ||
|
||
func TestSnapshotBenchmark(t *testing.T) { | ||
if b, err := strconv.ParseBool(os.Getenv("BENCHMARK")); err != nil || !b { | ||
t.SkipNow() | ||
} | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
contextDir := filepath.Join(cwd, "benchmark_fs") | ||
|
||
nums := []int{10000, 50000, 100000, 200000, 300000, 500000, 700000, 800000} | ||
|
||
var timeMap sync.Map | ||
var wg sync.WaitGroup | ||
for _, num := range nums { | ||
t.Run(fmt.Sprintf("test_benchmark_%d", num), func(t *testing.T) { | ||
wg.Add(1) | ||
var err error | ||
go func(num int, err *error) { | ||
dockerfile := "Dockerfile_fs_benchmark" | ||
kanikoImage := fmt.Sprintf("%s_%d", GetKanikoImage(config.imageRepo, dockerfile), num) | ||
buildArgs := []string{"--build-arg", fmt.Sprintf("NUM=%d", num)} | ||
var benchmarkDir string | ||
benchmarkDir, *err = buildKanikoImage("", dockerfile, | ||
buildArgs, []string{}, kanikoImage, contextDir, config.gcsBucket, | ||
config.serviceAccount, false) | ||
if *err != nil { | ||
return | ||
} | ||
r := newResult(t, filepath.Join(benchmarkDir, dockerfile)) | ||
timeMap.Store(num, r) | ||
wg.Done() | ||
defer os.Remove(benchmarkDir) | ||
}(num, &err) | ||
if err != nil { | ||
t.Errorf("could not run benchmark results for num %d due to %s", num, err) | ||
} | ||
}) | ||
} | ||
wg.Wait() | ||
|
||
fmt.Println("Number of Files,Total Build Time,Walking Filesystem, Resolving Files") | ||
timeMap.Range(func(key interface{}, value interface{}) bool { | ||
d, _ := key.(int) | ||
v, _ := value.(result) | ||
fmt.Println(fmt.Sprintf("%d,%f,%f,%f", d, v.totalBuildTime, v.walkingFiles, v.resolvingFiles)) | ||
return true | ||
}) | ||
|
||
} | ||
|
||
func newResult(t *testing.T, f string) result { | ||
var current map[string]time.Duration | ||
jsonFile, err := os.Open(f) | ||
defer jsonFile.Close() | ||
if err != nil { | ||
t.Errorf("could not read benchmark file %s", f) | ||
} | ||
byteValue, _ := ioutil.ReadAll(jsonFile) | ||
if err := json.Unmarshal(byteValue, ¤t); err != nil { | ||
t.Errorf("could not unmarshal benchmark file") | ||
} | ||
r := result{} | ||
if c, ok := current["Resolving Paths"]; ok { | ||
r.resolvingFiles = c.Seconds() | ||
} | ||
if c, ok := current["Walking filesystem"]; ok { | ||
r.walkingFiles = c.Seconds() | ||
} | ||
if c, ok := current["Total Build Time"]; ok { | ||
r.totalBuildTime = c.Seconds() | ||
} | ||
return r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters