Skip to content

Commit

Permalink
periodically dump stats in the file
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Jul 18, 2023
1 parent 98b1f72 commit 73e7cc3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/cel-shed/eds_store_stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var edsStoreStress = &cobra.Command{
EDSSize: edsSize,
EDSWrites: edsWrites,
EnableLog: !disableLog,
LogFilePath: path,
StatLogFreq: logFreq,
}

Expand Down
35 changes: 34 additions & 1 deletion libs/edssser/edssser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"sync"
"testing"
"time"
Expand All @@ -20,6 +21,7 @@ type Config struct {
EDSSize int
EDSWrites int
EnableLog bool
LogFilePath string
StatLogFreq int
}

Expand All @@ -29,6 +31,9 @@ type EDSsser struct {
datastore datastore.Batching
edsstoreMu sync.Mutex
edsstore *eds.Store

statsFileMu sync.Mutex
statsFile *os.File
}

func NewEDSsser(path string, datastore datastore.Batching, cfg Config) (*EDSsser, error) {
Expand Down Expand Up @@ -62,6 +67,10 @@ func (ss *EDSsser) Run(ctx context.Context) (stats Stats, err error) {
}
fmt.Printf("recovered %d EDSes\n\n", len(edsHashes))

defer func() {
err = errors.Join(err, ss.dumpStat(stats.Finalize()))
}()

t := &testing.T{}
for toWrite := ss.config.EDSWrites - len(edsHashes); ctx.Err() == nil && toWrite > 0; toWrite-- {
// divide by 2 to get ODS size as expected by RandEDS
Expand Down Expand Up @@ -90,14 +99,38 @@ func (ss *EDSsser) Run(ctx context.Context) (stats Stats, err error) {
fmt.Println("square written", "size", ss.config.EDSSize, "took", took)

if stats.TotalWritten%ss.config.StatLogFreq == 0 {
fmt.Println(stats.Finalize())
stats := stats.Finalize()
fmt.Println(stats)
go func() {
err := ss.dumpStat(stats)
if err != nil {
fmt.Printf("error dumping stats: %s\n", err.Error())
}
}()
}
}
}

return stats, nil
}

func (ss *EDSsser) dumpStat(stats Stats) (err error) {
ss.statsFileMu.Lock()
defer ss.statsFileMu.Unlock()

ss.statsFile, err = os.Create(ss.config.LogFilePath + "/edssser_stats.txt")
if err != nil {
return err
}

_, err = ss.statsFile.Write([]byte(stats.String()))
if err != nil {
return err
}

return ss.statsFile.Close()
}

type Stats struct {
TotalWritten int
TotalTime, MinTime, MaxTime, AvgTime time.Duration
Expand Down

0 comments on commit 73e7cc3

Please sign in to comment.