-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GODT-2522): Select Fetch benchmark
- Loading branch information
1 parent
f43eebd
commit fecbe0c
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters