|
| 1 | +package imap_benchmarks |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "flag" |
| 6 | + "github.com/emersion/go-imap" |
| 7 | + "net" |
| 8 | + |
| 9 | + "github.com/ProtonMail/gluon/benchmarks/gluon_bench/benchmark" |
| 10 | + "github.com/bradenaw/juniper/xslices" |
| 11 | + "github.com/emersion/go-imap/client" |
| 12 | +) |
| 13 | + |
| 14 | +var ( |
| 15 | + selectFetchRepetitionsFlag = flag.Uint("imap-select-fetch-repeat", 50, "Number of times to repeat the request.") |
| 16 | +) |
| 17 | + |
| 18 | +type SelectFetch struct { |
| 19 | + *stateTracker |
| 20 | + mboxInfo []MailboxInfo |
| 21 | +} |
| 22 | + |
| 23 | +func NewSelectFetch() benchmark.Benchmark { |
| 24 | + return NewIMAPBenchmarkRunner(&SelectFetch{stateTracker: newStateTracker()}) |
| 25 | +} |
| 26 | + |
| 27 | +func (*SelectFetch) Name() string { |
| 28 | + return "imap-select-fetch" |
| 29 | +} |
| 30 | + |
| 31 | +func (e *SelectFetch) Setup(ctx context.Context, addr net.Addr) error { |
| 32 | + return WithClient(addr, func(cl *client.Client) error { |
| 33 | + for i := uint(0); i < *selectFetchRepetitionsFlag; i++ { |
| 34 | + if _, err := e.createAndFillRandomMBox(cl); err != nil { |
| 35 | + return err |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + e.mboxInfo = xslices.Map(e.MBoxes, func(m string) MailboxInfo { |
| 40 | + return MailboxInfo{Name: m, ReadOnly: false} |
| 41 | + }) |
| 42 | + return nil |
| 43 | + }) |
| 44 | +} |
| 45 | + |
| 46 | +func (e *SelectFetch) TearDown(ctx context.Context, addr net.Addr) error { |
| 47 | + return e.cleanupWithAddr(addr) |
| 48 | +} |
| 49 | + |
| 50 | +func (e *SelectFetch) Run(ctx context.Context, addr net.Addr) error { |
| 51 | + RunParallelClients(addr, func(cl *client.Client, u uint) { |
| 52 | + for i := uint(0); i < *selectFetchRepetitionsFlag; i++ { |
| 53 | + if _, err := cl.Select(e.mboxInfo[i].Name, e.mboxInfo[i].ReadOnly); err != nil { |
| 54 | + panic(err) |
| 55 | + } |
| 56 | + |
| 57 | + if err := FetchMessage(cl, NewSequenceSetAll(), imap.FetchUid, imap.FetchFlags); err != nil { |
| 58 | + panic(err) |
| 59 | + } |
| 60 | + |
| 61 | + if err := cl.Unselect(); err != nil { |
| 62 | + panic(err) |
| 63 | + } |
| 64 | + } |
| 65 | + }) |
| 66 | + |
| 67 | + return nil |
| 68 | +} |
| 69 | + |
| 70 | +func init() { |
| 71 | + benchmark.RegisterBenchmark(NewSelectFetch()) |
| 72 | +} |
0 commit comments