Skip to content

Commit

Permalink
feat(GODT-2522): Select Fetch benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton committed Jun 27, 2023
1 parent f43eebd commit fecbe0c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
72 changes: 72 additions & 0 deletions benchmarks/gluon_bench/imap_benchmarks/select_fetch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package imap_benchmarks

import (
"context"
"flag"
"github.com/emersion/go-imap"
"net"

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

var (
selectFetchRepetitionsFlag = flag.Uint("imap-select-fetch-repeat", 50, "Number of times to repeat the request.")
)

type SelectFetch struct {
*stateTracker
mboxInfo []MailboxInfo
}

func NewSelectFetch() benchmark.Benchmark {
return NewIMAPBenchmarkRunner(&SelectFetch{stateTracker: newStateTracker()})
}

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

func (e *SelectFetch) Setup(ctx context.Context, addr net.Addr) error {
return WithClient(addr, func(cl *client.Client) error {
for i := uint(0); i < *selectFetchRepetitionsFlag; i++ {
if _, err := e.createAndFillRandomMBox(cl); err != nil {
return err
}
}

e.mboxInfo = xslices.Map(e.MBoxes, func(m string) MailboxInfo {
return MailboxInfo{Name: m, ReadOnly: false}
})
return nil
})
}

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

func (e *SelectFetch) Run(ctx context.Context, addr net.Addr) error {
RunParallelClients(addr, func(cl *client.Client, u uint) {
for i := uint(0); i < *selectFetchRepetitionsFlag; i++ {
if _, err := cl.Select(e.mboxInfo[i].Name, e.mboxInfo[i].ReadOnly); err != nil {
panic(err)
}

if err := FetchMessage(cl, NewSequenceSetAll(), imap.FetchUid, imap.FetchFlags); err != nil {
panic(err)
}

if err := cl.Unselect(); err != nil {
panic(err)
}
}
})

return nil
}

func init() {
benchmark.RegisterBenchmark(NewSelectFetch())
}
2 changes: 2 additions & 0 deletions benchmarks/gluon_bench/utils/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dGhpcyBpcyBteSBhdHRhY2htZW50Cg==
const MessageAfterNoonMeeting = `Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
From: Fred Foobar <foobar@Blurdybloop.COM>
Subject: afternoon meeting
Date: Fri, 26 Mar 2021 20:01:23 +0100
To: mooch@owatagu.siam.edu
Message-Id: <B27397-0100000@Blurdybloop.COM>
MIME-Version: 1.0
Expand All @@ -77,6 +78,7 @@ const MessageEmbedded = `From: Nathaniel Borenstein <nsb@bellcore.com>
To: Ned Freed <ned@innosoft.com>
Subject: Sample message
MIME-Version: 1.0
Date: Fri, 26 Mar 2021 20:01:23 +0100
Content-type: multipart/mixed; boundary="simple boundary"
This is the preamble. It is to be ignored, though it
Expand Down

0 comments on commit fecbe0c

Please sign in to comment.