diff --git a/benchmarks/gluon_bench/imap_benchmarks/select_fetch.go b/benchmarks/gluon_bench/imap_benchmarks/select_fetch.go new file mode 100644 index 00000000..b2348992 --- /dev/null +++ b/benchmarks/gluon_bench/imap_benchmarks/select_fetch.go @@ -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()) +} diff --git a/benchmarks/gluon_bench/utils/messages.go b/benchmarks/gluon_bench/utils/messages.go index dd37940e..ed573277 100644 --- a/benchmarks/gluon_bench/utils/messages.go +++ b/benchmarks/gluon_bench/utils/messages.go @@ -65,6 +65,7 @@ dGhpcyBpcyBteSBhdHRhY2htZW50Cg== const MessageAfterNoonMeeting = `Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) From: Fred Foobar Subject: afternoon meeting +Date: Fri, 26 Mar 2021 20:01:23 +0100 To: mooch@owatagu.siam.edu Message-Id: MIME-Version: 1.0 @@ -77,6 +78,7 @@ const MessageEmbedded = `From: Nathaniel Borenstein To: Ned Freed 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