diff --git a/go.mod b/go.mod index ee214dd31..124a74566 100644 --- a/go.mod +++ b/go.mod @@ -111,6 +111,7 @@ require ( github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/jamiealquiza/tachymeter v2.0.0+incompatible // indirect github.com/jcmturner/aescts/v2 v2.0.0 // indirect github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect github.com/jcmturner/gofork v1.7.6 // indirect diff --git a/go.sum b/go.sum index f760ea3b1..7a52cc1a9 100644 --- a/go.sum +++ b/go.sum @@ -188,6 +188,8 @@ github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs= github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jamiealquiza/tachymeter v2.0.0+incompatible h1:mGiF1DGo8l6vnGT8FXNNcIXht/YmjzfraiUprXYwJ6g= +github.com/jamiealquiza/tachymeter v2.0.0+incompatible/go.mod h1:Ayf6zPZKEnLsc3winWEXJRkTBhdHo58HODAu1oFJkYU= github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= diff --git a/test/performance/README.md b/test/performance/README.md index 27ce4cd2a..426aa17f7 100644 --- a/test/performance/README.md +++ b/test/performance/README.md @@ -43,7 +43,7 @@ go test -bench=Write/testserver -run ^$ -tags it -report.dir . The exported file is a csv. You can use the [provided plot script](./plot/features_comparison.gp) to generate a bar chart for tps: ```shell -gnuplot -c plot/features_comparison.gp +gnuplot -c plot/features_comparison_tps.gp ``` Each feature is tested against a test script involving a transaction from a source to a destination. diff --git a/test/performance/benchmark_test.go b/test/performance/benchmark_test.go index 86fd170d0..4bd56b285 100644 --- a/test/performance/benchmark_test.go +++ b/test/performance/benchmark_test.go @@ -80,7 +80,7 @@ func (benchmark *Benchmark) Run(ctx context.Context) map[string][]Report { require.NoError(benchmark.b, env.Stop(stopContext)) }) - if report.TransactionsCount > 0 { + if report.Tachymeter.Count > 0 { reports[scriptName] = append(reports[scriptName], report) } } diff --git a/test/performance/plot/features_comparison.gp b/test/performance/plot/features_comparison_tps.gp similarity index 61% rename from test/performance/plot/features_comparison.gp rename to test/performance/plot/features_comparison_tps.gp index 71677c7cd..873594bf7 100644 --- a/test/performance/plot/features_comparison.gp +++ b/test/performance/plot/features_comparison_tps.gp @@ -2,11 +2,11 @@ set terminal cgm width 10/2.54*72 set term png -set output "features_comparison.png" +set output "features_comparison_tps.png" set boxwidth 0.9 relative set style data histograms set style histogram cluster set style fill solid 1.0 border lt -1 set xtics rotate by 90 right -plot for [COL=2:5] 'features_comparison.csv' using COL:xticlabels(1) title col +plot for [COL=2:5] 'features_comparison_tps.csv' using COL:xticlabels(1) title col diff --git a/test/performance/report_test.go b/test/performance/report_test.go index b949d7745..c10af76d4 100644 --- a/test/performance/report_test.go +++ b/test/performance/report_test.go @@ -3,44 +3,39 @@ package performance_test import ( - "sync" - "sync/atomic" - "github.com/formancehq/go-libs/time" + "github.com/jamiealquiza/tachymeter" + "sync" ) type Report struct { mu *sync.Mutex - Start time.Time End time.Time - TotalLatency *atomic.Int64 - TransactionsCount int + Tachymeter *tachymeter.Tachymeter + Name string Configuration configuration } func (r *Report) TPS() float64 { - return (float64(time.Duration(r.TransactionsCount)) / float64(r.End.Sub(r.Start))) * float64(time.Second) + return (float64(time.Duration(r.Tachymeter.Count)) / float64(r.End.Sub(r.Start))) * float64(time.Second) } func (r *Report) AverageDuration() time.Duration { - return time.Duration(r.TotalLatency.Load()) * time.Millisecond / time.Duration(r.TransactionsCount) + return r.Tachymeter.Calc().Time.Avg } func (r *Report) registerTransactionLatency(latency time.Duration) { r.mu.Lock() defer r.mu.Unlock() - r.TransactionsCount++ - r.TotalLatency.Add(latency.Milliseconds()) + r.Tachymeter.AddTime(latency) } func (r *Report) reset() { - r.TotalLatency = &atomic.Int64{} - r.TransactionsCount = 0 r.Start = time.Now() } @@ -49,6 +44,9 @@ func newReport(configuration configuration, name string) Report { Name: name, Configuration: configuration, mu: &sync.Mutex{}, + Tachymeter: tachymeter.New(&tachymeter.Config{ + Size: 10000, + }), } ret.reset() return ret diff --git a/test/performance/write_test.go b/test/performance/write_test.go index 93e5437fa..99c6e1930 100644 --- a/test/performance/write_test.go +++ b/test/performance/write_test.go @@ -82,7 +82,7 @@ func BenchmarkWrite(b *testing.B) { if reportDir != "" { require.NoError(b, os.MkdirAll(reportDir, 0755)) - featureComparisonCSVLocation := filepath.Join(reportDir, "features_comparison.csv") + featureComparisonCSVLocation := filepath.Join(reportDir, "features_comparison_tps.csv") featureComparisonCSVFile, err := os.Create(featureComparisonCSVLocation) require.NoError(b, err)