2014-11-16 20:13:20 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 19:43:32 +00:00
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-09-27 18:09:36 +00:00
|
|
|
|
2021-08-17 08:10:41 +00:00
|
|
|
//go:build integration && benchmark
|
2014-12-17 11:31:03 +00:00
|
|
|
// +build integration,benchmark
|
2014-09-27 18:09:36 +00:00
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
package integration
|
2014-09-27 18:09:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2020-07-28 09:13:15 +00:00
|
|
|
"math/rand"
|
2015-05-25 09:05:12 +00:00
|
|
|
"os"
|
2014-09-27 18:09:36 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
2020-07-28 09:13:15 +00:00
|
|
|
|
|
|
|
"github.com/syncthing/syncthing/lib/rc"
|
2014-09-27 18:09:36 +00:00
|
|
|
)
|
|
|
|
|
2015-04-05 13:34:15 +00:00
|
|
|
func TestBenchmarkTransferManyFiles(t *testing.T) {
|
2020-07-28 09:13:15 +00:00
|
|
|
setupAndBenchmarkTransfer(t, 10000, 15)
|
2015-04-05 13:34:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 09:05:12 +00:00
|
|
|
func TestBenchmarkTransferLargeFile1G(t *testing.T) {
|
2020-07-28 09:13:15 +00:00
|
|
|
setupAndBenchmarkTransfer(t, 1, 30)
|
2015-05-25 09:05:12 +00:00
|
|
|
}
|
2024-11-19 10:32:56 +00:00
|
|
|
|
2015-05-25 09:05:12 +00:00
|
|
|
func TestBenchmarkTransferLargeFile2G(t *testing.T) {
|
2020-07-28 09:13:15 +00:00
|
|
|
setupAndBenchmarkTransfer(t, 1, 31)
|
2015-05-25 09:05:12 +00:00
|
|
|
}
|
2024-11-19 10:32:56 +00:00
|
|
|
|
2015-05-25 09:05:12 +00:00
|
|
|
func TestBenchmarkTransferLargeFile4G(t *testing.T) {
|
2020-07-28 09:13:15 +00:00
|
|
|
setupAndBenchmarkTransfer(t, 1, 32)
|
2015-05-25 09:05:12 +00:00
|
|
|
}
|
2024-11-19 10:32:56 +00:00
|
|
|
|
2015-05-25 09:05:12 +00:00
|
|
|
func TestBenchmarkTransferLargeFile8G(t *testing.T) {
|
2020-07-28 09:13:15 +00:00
|
|
|
setupAndBenchmarkTransfer(t, 1, 33)
|
2015-05-25 09:05:12 +00:00
|
|
|
}
|
2024-11-19 10:32:56 +00:00
|
|
|
|
2015-05-25 09:05:12 +00:00
|
|
|
func TestBenchmarkTransferLargeFile16G(t *testing.T) {
|
2020-07-28 09:13:15 +00:00
|
|
|
setupAndBenchmarkTransfer(t, 1, 34)
|
2015-05-25 09:05:12 +00:00
|
|
|
}
|
2024-11-19 10:32:56 +00:00
|
|
|
|
2015-05-25 09:05:12 +00:00
|
|
|
func TestBenchmarkTransferLargeFile32G(t *testing.T) {
|
2020-07-28 09:13:15 +00:00
|
|
|
setupAndBenchmarkTransfer(t, 1, 35)
|
2015-04-05 13:34:15 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 09:13:15 +00:00
|
|
|
func setupAndBenchmarkTransfer(t *testing.T, files, sizeExp int) {
|
|
|
|
cleanBenchmarkTransfer(t)
|
2014-09-27 18:09:36 +00:00
|
|
|
|
|
|
|
log.Println("Generating files...")
|
2020-07-28 09:13:15 +00:00
|
|
|
var err error
|
2015-05-25 09:05:12 +00:00
|
|
|
if files == 1 {
|
|
|
|
// Special case. Generate one file with the specified size exactly.
|
2016-07-15 14:23:20 +00:00
|
|
|
var fd *os.File
|
|
|
|
fd, err = os.Open("../LICENSE")
|
2015-05-25 09:05:12 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2024-11-19 10:32:56 +00:00
|
|
|
err = os.MkdirAll("s1", 0o755)
|
2015-05-25 09:05:12 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-07-28 09:13:15 +00:00
|
|
|
err = generateOneFile(fd, "s1/onefile", 1<<uint(sizeExp), time.Now())
|
2015-05-25 09:05:12 +00:00
|
|
|
} else {
|
|
|
|
err = generateFiles("s1", files, sizeExp, "../LICENSE")
|
|
|
|
}
|
2014-09-27 18:09:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-07-28 09:13:15 +00:00
|
|
|
|
|
|
|
benchmarkTransfer(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestBenchmarkTransferSameFiles doesn't actually transfer anything, but tests
|
|
|
|
// how fast two devicees get in sync if they have the same data locally.
|
|
|
|
func TestBenchmarkTransferSameFiles(t *testing.T) {
|
|
|
|
cleanBenchmarkTransfer(t)
|
|
|
|
|
|
|
|
t0 := time.Now()
|
|
|
|
rand.Seed(0)
|
|
|
|
log.Println("Generating files in s1...")
|
|
|
|
if err := generateFilesWithTime("s1", 10000, 10, "../LICENSE", t0); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rand.Seed(0)
|
|
|
|
log.Println("Generating same files in s2...")
|
|
|
|
if err := generateFilesWithTime("s2", 10000, 10, "../LICENSE", t0); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
benchmarkTransfer(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkTransfer(t *testing.T) {
|
2015-02-19 11:15:51 +00:00
|
|
|
expected, err := directoryContents("s1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-05-25 09:05:12 +00:00
|
|
|
var total int64
|
|
|
|
var nfiles int
|
|
|
|
for _, f := range expected {
|
|
|
|
total += f.size
|
|
|
|
if f.mode.IsRegular() {
|
|
|
|
nfiles++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Printf("Total %.01f MiB in %d files", float64(total)/1024/1024, nfiles)
|
2014-09-27 18:09:36 +00:00
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
sender := startInstance(t, 1)
|
|
|
|
defer checkedStop(t, sender)
|
|
|
|
receiver := startInstance(t, 2)
|
|
|
|
defer checkedStop(t, receiver)
|
2014-09-27 18:09:36 +00:00
|
|
|
|
2017-11-12 22:28:45 +00:00
|
|
|
sender.ResumeAll()
|
|
|
|
receiver.ResumeAll()
|
|
|
|
|
2020-07-28 09:13:15 +00:00
|
|
|
t0 := time.Now()
|
|
|
|
var t1 time.Time
|
2015-06-18 13:22:45 +00:00
|
|
|
lastEvent := 0
|
2018-02-03 09:28:37 +00:00
|
|
|
|
2014-09-27 18:09:36 +00:00
|
|
|
loop:
|
|
|
|
for {
|
2015-06-18 13:22:45 +00:00
|
|
|
evs, err := receiver.Events(lastEvent)
|
2014-09-27 18:09:36 +00:00
|
|
|
if err != nil {
|
2014-12-17 11:31:03 +00:00
|
|
|
if isTimeout(err) {
|
2014-09-27 18:09:36 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ev := range evs {
|
2018-02-03 09:28:37 +00:00
|
|
|
lastEvent = ev.ID
|
|
|
|
|
|
|
|
switch ev.Type {
|
|
|
|
case "ItemFinished":
|
2020-07-28 09:13:15 +00:00
|
|
|
break loop
|
2014-09-27 18:09:36 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 08:44:46 +00:00
|
|
|
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
2014-09-27 18:09:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 09:13:15 +00:00
|
|
|
processes := []*rc.Process{sender, receiver}
|
|
|
|
for {
|
|
|
|
if rc.InSync("default", processes...) {
|
|
|
|
t1 = time.Now()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
sendProc, err := sender.Stop()
|
2015-05-25 09:05:12 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-06-18 13:22:45 +00:00
|
|
|
recvProc, err := receiver.Stop()
|
2015-04-30 06:43:57 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-12-17 11:31:03 +00:00
|
|
|
|
|
|
|
log.Println("Verifying...")
|
|
|
|
|
2015-02-19 11:15:51 +00:00
|
|
|
actual, err := directoryContents("s2")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-12-17 11:31:03 +00:00
|
|
|
err = compareDirectoryContents(actual, expected)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-05-18 06:46:08 +00:00
|
|
|
log.Printf("Result: Wall time: %v / MiB", t1.Sub(t0)/time.Duration(total/1024/1024))
|
|
|
|
log.Printf("Result: %.3g KiB/s synced", float64(total)/1024/t1.Sub(t0).Seconds())
|
2015-05-25 09:05:12 +00:00
|
|
|
|
2019-05-18 06:46:08 +00:00
|
|
|
printUsage("Receiver", recvProc, total)
|
|
|
|
printUsage("Sender", sendProc, total)
|
2020-07-28 09:13:15 +00:00
|
|
|
|
|
|
|
cleanBenchmarkTransfer(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func cleanBenchmarkTransfer(t *testing.T) {
|
|
|
|
log.Println("Cleaning...")
|
|
|
|
err := removeAll("s1", "s2", "h1/index*", "h2/index*")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-09-27 18:09:36 +00:00
|
|
|
}
|