Skip to content

Commit

Permalink
feat: add tachnymeter
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent efe6b67 commit 50468a3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion test/performance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/performance/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 10 additions & 12 deletions test/performance/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/performance/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 50468a3

Please sign in to comment.