1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
package bench
import (
"os"
"os/exec"
"testing"
"github.com/containerd/continuity"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/reexec"
)
func init() {
reexec.Init()
}
func benchmarkInitialCopy(b *testing.B, fn func(string, string) error, size int) {
baseDir := os.Getenv("BENCH_BASE_DIR")
verify := os.Getenv("BENCH_VERIFY") == "1"
for i := 0; i < b.N; i++ {
b.StopTimer()
tmpdir, err := createTestDir(size)
if err != nil {
b.Error(err)
}
destdir, err := os.MkdirTemp(baseDir, "destdir")
if err != nil {
os.RemoveAll(tmpdir)
b.Error(err)
}
var m *continuity.Manifest
if verify {
ctx, err := continuity.NewContext(tmpdir)
if err != nil {
b.Error(err)
}
m, err = continuity.BuildManifest(ctx)
if err != nil {
b.Error(err)
}
}
b.StartTimer()
err = fn(tmpdir, destdir)
if err != nil {
b.Error(err)
}
b.StopTimer()
if verify {
ctx2, err := continuity.NewContext(destdir)
if err != nil {
b.Fatal(err)
}
err = continuity.VerifyManifest(ctx2, m)
if err != nil {
b.Error(err)
}
}
os.RemoveAll(tmpdir)
os.RemoveAll(destdir)
}
}
func benchmarkIncrementalCopy(b *testing.B, fn func(string, string) error, size int) {
b.StopTimer()
baseDir := os.Getenv("BENCH_BASE_DIR")
verify := os.Getenv("BENCH_VERIFY") == "1"
tmpdir, err := createTestDir(size)
if err != nil {
b.Error(err)
}
destdir, err := os.MkdirTemp(baseDir, "destdir")
if err != nil {
os.RemoveAll(tmpdir)
b.Error(err)
}
err = fn(tmpdir, destdir)
if err != nil {
b.Error(err)
}
defer os.RemoveAll(tmpdir)
defer os.RemoveAll(destdir)
for i := 0; i < b.N; i++ {
if err := mutate(tmpdir, 2); err != nil {
b.Error(err)
}
var m *continuity.Manifest
if verify {
ctx, err := continuity.NewContext(tmpdir)
if err != nil {
b.Error(err)
}
m, err = continuity.BuildManifest(ctx)
if err != nil {
b.Error(err)
}
}
b.StartTimer()
err = fn(tmpdir, destdir)
if err != nil {
b.Error(err)
}
b.StopTimer()
if verify {
ctx2, err := continuity.NewContext(destdir)
if err != nil {
b.Fatal(err)
}
err = continuity.VerifyManifest(ctx2, m)
if err != nil {
b.Error(err)
}
}
}
}
func copyWithTar(src, dest string) error {
return archive.NewDefaultArchiver().CopyWithTar(src, dest)
}
func cpa(src, dest string) error {
cmd := exec.Command("cp", "-a", src+"/.", dest)
return cmd.Run()
}
func rsync(src, dest string) error {
cmd := exec.Command("rsync", "-a", "--del", src+"/.", dest)
return cmd.Run()
}
func gnutar(src, dest string) error {
tar := exec.Command("tar", "-cf", "-", "-C", src, ".")
unpack := exec.Command("tar", "xf", "-", "-C", dest)
stdout, err := tar.StdoutPipe()
if err != nil {
return err
}
unpack.Stdin = stdout
go tar.Run()
return unpack.Run()
}
func BenchmarkCopyWithTar10(b *testing.B) {
benchmarkInitialCopy(b, copyWithTar, 10)
}
func BenchmarkCopyWithTar50(b *testing.B) {
benchmarkInitialCopy(b, copyWithTar, 50)
}
func BenchmarkCopyWithTar200(b *testing.B) {
benchmarkInitialCopy(b, copyWithTar, 200)
}
func BenchmarkCopyWithTar1000(b *testing.B) {
benchmarkInitialCopy(b, copyWithTar, 1000)
}
// func chrootCopyWithTar(src, dest string) error {
// return chrootarchive.NewArchiver(nil).CopyWithTar(src, dest)
// }
// func BenchmarkChrootCopyWithTar10(b *testing.B) {
// benchmarkInitialCopy(b, chrootCopyWithTar, 10)
// }
//
// func BenchmarkChrootCopyWithTar50(b *testing.B) {
// benchmarkInitialCopy(b, chrootCopyWithTar, 50)
// }
//
// func BenchmarkChrootCopyWithTar200(b *testing.B) {
// benchmarkInitialCopy(b, chrootCopyWithTar, 200)
// }
//
// func BenchmarkChrootCopyWithTar1000(b *testing.B) {
// benchmarkInitialCopy(b, chrootCopyWithTar, 1000)
// }
func BenchmarkCPA10(b *testing.B) {
benchmarkInitialCopy(b, cpa, 10)
}
func BenchmarkCPA50(b *testing.B) {
benchmarkInitialCopy(b, cpa, 50)
}
func BenchmarkCPA200(b *testing.B) {
benchmarkInitialCopy(b, cpa, 200)
}
func BenchmarkCPA1000(b *testing.B) {
benchmarkInitialCopy(b, cpa, 1000)
}
func BenchmarkDiffCopy10(b *testing.B) {
benchmarkInitialCopy(b, diffCopyReg, 10)
}
func BenchmarkDiffCopy50(b *testing.B) {
benchmarkInitialCopy(b, diffCopyReg, 50)
}
func BenchmarkDiffCopy200(b *testing.B) {
benchmarkInitialCopy(b, diffCopyReg, 200)
}
func BenchmarkDiffCopy1000(b *testing.B) {
benchmarkInitialCopy(b, diffCopyReg, 1000)
}
func BenchmarkDiffCopyProto10(b *testing.B) {
benchmarkInitialCopy(b, diffCopyProto, 10)
}
func BenchmarkDiffCopyProto50(b *testing.B) {
benchmarkInitialCopy(b, diffCopyProto, 50)
}
func BenchmarkDiffCopyProto200(b *testing.B) {
benchmarkInitialCopy(b, diffCopyProto, 200)
}
func BenchmarkDiffCopyProto1000(b *testing.B) {
benchmarkInitialCopy(b, diffCopyProto, 1000)
}
func BenchmarkIncrementalDiffCopy10(b *testing.B) {
benchmarkIncrementalCopy(b, diffCopyReg, 10)
}
func BenchmarkIncrementalDiffCopy50(b *testing.B) {
benchmarkIncrementalCopy(b, diffCopyReg, 50)
}
func BenchmarkIncrementalDiffCopy200(b *testing.B) {
benchmarkIncrementalCopy(b, diffCopyReg, 200)
}
func BenchmarkIncrementalDiffCopy1000(b *testing.B) {
benchmarkIncrementalCopy(b, diffCopyReg, 1000)
}
func BenchmarkIncrementalDiffCopy5000(b *testing.B) {
benchmarkIncrementalCopy(b, diffCopyReg, 5000)
}
func BenchmarkIncrementalDiffCopy10000(b *testing.B) {
benchmarkIncrementalCopy(b, diffCopyReg, 10000)
}
func BenchmarkIncrementalCopyWithTar10(b *testing.B) {
benchmarkIncrementalCopy(b, copyWithTar, 10)
}
func BenchmarkIncrementalCopyWithTar50(b *testing.B) {
benchmarkIncrementalCopy(b, copyWithTar, 50)
}
func BenchmarkIncrementalCopyWithTar200(b *testing.B) {
benchmarkIncrementalCopy(b, copyWithTar, 200)
}
func BenchmarkIncrementalCopyWithTar1000(b *testing.B) {
benchmarkIncrementalCopy(b, copyWithTar, 1000)
}
func BenchmarkIncrementalRsync10(b *testing.B) {
benchmarkIncrementalCopy(b, rsync, 10)
}
func BenchmarkIncrementalRsync50(b *testing.B) {
benchmarkIncrementalCopy(b, rsync, 50)
}
func BenchmarkIncrementalRsync200(b *testing.B) {
benchmarkIncrementalCopy(b, rsync, 200)
}
func BenchmarkIncrementalRsync1000(b *testing.B) {
benchmarkIncrementalCopy(b, rsync, 1000)
}
func BenchmarkIncrementalRsync5000(b *testing.B) {
benchmarkIncrementalCopy(b, rsync, 5000)
}
func BenchmarkIncrementalRsync10000(b *testing.B) {
benchmarkIncrementalCopy(b, rsync, 10000)
}
func BenchmarkRsync10(b *testing.B) {
benchmarkInitialCopy(b, rsync, 10)
}
func BenchmarkRsync50(b *testing.B) {
benchmarkInitialCopy(b, rsync, 50)
}
func BenchmarkRsync200(b *testing.B) {
benchmarkInitialCopy(b, rsync, 200)
}
func BenchmarkRsync1000(b *testing.B) {
benchmarkInitialCopy(b, rsync, 1000)
}
func BenchmarkGnuTar10(b *testing.B) {
benchmarkInitialCopy(b, gnutar, 10)
}
func BenchmarkGnuTar50(b *testing.B) {
benchmarkInitialCopy(b, gnutar, 50)
}
func BenchmarkGnuTar200(b *testing.B) {
benchmarkInitialCopy(b, gnutar, 200)
}
func BenchmarkGnuTar1000(b *testing.B) {
benchmarkInitialCopy(b, gnutar, 1000)
}
|