Skip to content

Commit

Permalink
feat: Add Select benchmark
Browse files Browse the repository at this point in the history
The append is currently slow because it takes a lot of time to load data
from the mailbox. The select benchmark can be use to check this specific
issue later once the append has been fixed.
  • Loading branch information
LBeernaertProton committed Sep 8, 2022
1 parent 70c0cb9 commit 25d69e3
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions benchmarks/gluon_bench/imap_benchmarks/select.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package imap_benchmarks

import (
"context"
"flag"
"net"

"github.com/ProtonMail/gluon/benchmarks/gluon_bench/benchmark"
"github.com/emersion/go-imap/client"
)

var selectReadOnlyFlag = flag.Bool("imap-select-readonly", false, "If set to true, perform a read only select (examine).")

type Select struct {
*stateTracker
}

func NewSelect() benchmark.Benchmark {
return NewIMAPBenchmarkRunner(&Select{stateTracker: newStateTracker()})
}

func (*Select) Name() string {
return "imap-select"
}

func (s *Select) Setup(ctx context.Context, addr net.Addr) error {
return WithClient(addr, func(cl *client.Client) error {
if _, err := s.createAndFillRandomMBox(cl); err != nil {
return err
}

return nil
})
}

func (s *Select) TearDown(ctx context.Context, addr net.Addr) error {
return s.cleanupWithAddr(addr)
}

func (s *Select) Run(ctx context.Context, addr net.Addr) error {
RunParallelClientsWithMailbox(addr, s.MBoxes[0], *fetchReadOnly, func(cl *client.Client, index uint) {
_, err := cl.Select(s.MBoxes[0], *selectReadOnlyFlag)
if err != nil {
panic(err)
}
})

return nil
}

func init() {
benchmark.RegisterBenchmark(NewSelect())
}

0 comments on commit 25d69e3

Please sign in to comment.