-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GODRIVER-115: multi document benchmarks
Change-Id: I0d73d3ae90bfd1286f2dfd158bea31e8873c5988
- Loading branch information
Sam Kleinman
committed
Jun 22, 2018
1 parent
59e0104
commit 75948c7
Showing
6 changed files
with
183 additions
and
9 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
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
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
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
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,137 @@ | ||
package benchmark | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/mongodb/mongo-go-driver/bson" | ||
) | ||
|
||
func MultiFindMany(ctx context.Context, tm TimerManager, iters int) error { | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
db, err := getClientDB(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
db = db.Client().Database("perftest") | ||
if err = db.Drop(ctx); err != nil { | ||
return err | ||
} | ||
|
||
doc, err := loadSourceDocument(getProjectRoot(), perfDataDir, singleAndMultiDataDir, tweetData) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
coll := db.Collection("corpus") | ||
|
||
for i := 0; i < iters; i++ { | ||
if _, err = coll.InsertOne(ctx, doc); err != nil { | ||
return err | ||
} | ||
|
||
// TODO: should be remove after resolving GODRIVER-468 | ||
_ = doc.Delete("_id") | ||
} | ||
|
||
tm.ResetTimer() | ||
|
||
cursor, err := coll.Find(ctx, bson.NewDocument()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
counter := 0 | ||
for cursor.Next(ctx) { | ||
err = cursor.Err() | ||
if err != nil { | ||
return err | ||
} | ||
r, err := cursor.DecodeBytes() | ||
if err != nil { | ||
return err | ||
} | ||
if len(r) == 0 { | ||
return errors.New("error retrieving document") | ||
} | ||
|
||
counter++ | ||
} | ||
|
||
if counter != iters { | ||
return errors.New("problem iterating cursors") | ||
|
||
} | ||
|
||
tm.StopTimer() | ||
|
||
if err = cursor.Close(ctx); err != nil { | ||
return err | ||
} | ||
|
||
if err = db.Drop(ctx); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func multiInsertCase(ctx context.Context, tm TimerManager, iters int, data string) error { | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
db, err := getClientDB(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
db = db.Client().Database("perftest") | ||
if err = db.Drop(ctx); err != nil { | ||
return err | ||
} | ||
|
||
doc, err := loadSourceDocument(getProjectRoot(), perfDataDir, singleAndMultiDataDir, data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = db.RunCommand(ctx, bson.NewDocument(bson.EC.String("create", "corpus"))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
payload := make([]interface{}, iters) | ||
for idx := range payload { | ||
payload[idx] = *doc | ||
} | ||
|
||
coll := db.Collection("corpus") | ||
|
||
tm.ResetTimer() | ||
res, err := coll.InsertMany(ctx, payload) | ||
if err != nil { | ||
return err | ||
} | ||
tm.StopTimer() | ||
|
||
if len(res.InsertedIDs) != iters { | ||
return errors.New("bulk operation did not complete") | ||
} | ||
|
||
if err = db.Drop(ctx); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func MultiInsertSmallDocument(ctx context.Context, tm TimerManager, iters int) error { | ||
return multiInsertCase(ctx, tm, iters, smallData) | ||
} | ||
|
||
func MultiInsertLargeDocument(ctx context.Context, tm TimerManager, iters int) error { | ||
return multiInsertCase(ctx, tm, iters, largeData) | ||
} |
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,7 @@ | ||
package benchmark | ||
|
||
import "testing" | ||
|
||
func BenchmarkMultiFindMany(b *testing.B) { WrapCase(MultiFindMany)(b) } | ||
func BenchmarkMultiInsertSmallDocument(b *testing.B) { WrapCase(MultiInsertSmallDocument)(b) } | ||
func BenchmarkMultiInsertLargeDocument(b *testing.B) { WrapCase(MultiInsertLargeDocument)(b) } |