Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9bd155e
docstore: duplicating awsdynamodb as base for V2 implementation
Maldris Feb 10, 2025
9048729
docstore: updating codec tests for v2 decoder types
Maldris Feb 10, 2025
bcdacd3
docstore: rewriting aws dynamodb codec to use the types from v2 aws sdk
Maldris Feb 10, 2025
6220866
docstore: updating modules based on update progress
Maldris Feb 10, 2025
fcc9797
docstore: re-introducing codecTester
Maldris Feb 10, 2025
699d1ba
docstore: updating url opener parsing to use aws sdk v2 initializatio…
Maldris Feb 10, 2025
f159208
docstore: updating query planner and builder behaviors with aws sdk v…
Maldris Feb 11, 2025
8a26452
docstore: converting main dynamodb docstore logic to use aws sdk v2
Maldris Feb 11, 2025
698c7b1
docstore: updating example and dynamodb docstore benchmark and exampl…
Maldris Feb 11, 2025
7c55cb2
docstore: updating comment to point to v2 documentation of aws sessio…
Maldris Feb 11, 2025
8a91326
docstore: removing commented out v1 code used as reference
Maldris Feb 11, 2025
6945028
docstore: explicitly handle document encoding error (should never hap…
Maldris Feb 11, 2025
6026fb9
docstore: docstore/awsdynamodb's encodeDocKeyFields always returns ma…
Maldris Feb 11, 2025
f32c823
docstore: reviewed todos against v1 behavior and added explanatory co…
Maldris Feb 11, 2025
8785d1c
docstore: grouping encoder tests by type
Maldris Feb 11, 2025
9ca2692
docstore: adding tests for boolean false, multi-char and space contai…
Maldris Feb 11, 2025
778c153
docstore: centralizing attribute value ignore unexported definition
Maldris Feb 11, 2025
12aad2a
docstore: adding decoder tests
Maldris Feb 11, 2025
a79a608
docstore: fixing removed import label from merge
Maldris Feb 11, 2025
1887351
docstore: logging the test that fails for easier debug
Maldris Feb 11, 2025
3ef67d3
docstore: tests specify region, setup script does not, adding to make…
Maldris Feb 11, 2025
7c00fc8
docstore: fixing error as to asset the correct type
Maldris Feb 11, 2025
288d217
docstore: updating error code lookup using new error as behavior from…
Maldris Feb 11, 2025
ac4a182
docstore: fixing logic error in missing field key check
Maldris Feb 11, 2025
13954f2
docstore: fixing different map behavior in aws dynamodb v2 not matchi…
Maldris Feb 11, 2025
75e787b
docstore: updating error decoding to use correct type
Maldris Feb 11, 2025
e3fe7bf
docstore: clarifying errors with comments
Maldris Feb 11, 2025
339e9df
docstore/awsdynamodb moving V2 implementation to V2 folder
Maldris Mar 17, 2025
fa5c50b
fixing changed import path after moving driver folder
Maldris Mar 17, 2025
f2768e8
Merge remote-tracking branch 'origin' into aws/v2/docstore
Maldris Mar 31, 2025
35738c0
adding SupportsAtomicWrites to docstore/awsdynamodb/v2 test harness t…
Maldris Mar 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions docstore/awsdynamodb/v2/benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright 2019 The Go Cloud Development Kit Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package awsdynamodb

import (
"context"
"fmt"
"strconv"
"testing"

awsv2cfg "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
dyn2Types "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)

var benchmarkTableName = collectionName3

func BenchmarkPutVSTransact(b *testing.B) {
// This benchmark compares two ways to replace N items and retrieve their previous values.
// The first way makes N calls to PutItem with ReturnValues set to ALL_OLD.
// The second way calls BatchGetItem followed by TransactWriteItem.
//
// The results show that separate PutItems are faster for up to two items.
cfg, err := awsv2cfg.LoadDefaultConfig(context.Background())
if err != nil {
b.Fatal("Error initializing aws session for benchmark: ", err)
}
db := dynamodb.NewFromConfig(cfg)

for nItems := 1; nItems <= 5; nItems++ {
b.Run(fmt.Sprintf("%d-Items", nItems), func(b *testing.B) {
var items []map[string]dyn2Types.AttributeValue
for i := 0; i < nItems; i++ {
items = append(items, map[string]dyn2Types.AttributeValue{
"name": &dyn2Types.AttributeValueMemberS{Value: fmt.Sprintf("pt-vs-transact-%d", i)},
"x": &dyn2Types.AttributeValueMemberN{Value: strconv.Itoa(i)},
"rev": &dyn2Types.AttributeValueMemberN{Value: "1"},
})
}
for _, item := range items {
_, err := db.PutItem(context.Background(), &dynamodb.PutItemInput{
TableName: &benchmarkTableName,
Item: item,
})
if err != nil {
b.Fatal(err)
}
}
b.Run("PutItem", func(b *testing.B) {
for n := 0; n < b.N; n++ {
putItems(b, db, items)
}
})
b.Run("TransactWrite", func(b *testing.B) {
for n := 0; n < b.N; n++ {
batchGetTransactWrite(b, db, items)
}
})
})
}
}

func putItems(b *testing.B, db *dynamodb.Client, items []map[string]dyn2Types.AttributeValue) {
b.Helper()

for i, item := range items {
item["x"] = &dyn2Types.AttributeValueMemberN{Value: strconv.Itoa(i + 1)}
in := &dynamodb.PutItemInput{
TableName: &benchmarkTableName,
Item: item,
ReturnValues: dyn2Types.ReturnValueAllOld,
}
ce, err := expression.NewBuilder().
WithCondition(expression.Name("rev").Equal(expression.Value(1))).
Build()
if err != nil {
b.Fatal(err)
}
in.ExpressionAttributeNames = ce.Names()
in.ExpressionAttributeValues = ce.Values()
in.ConditionExpression = ce.Condition()
out, err := db.PutItem(context.Background(), in)
if err != nil {
b.Fatal(err)
}
if got, want := len(out.Attributes), 3; got != want {
b.Fatalf("got %d attributes, want %d", got, want)
}
}
}

func batchGetTransactWrite(b *testing.B, db *dynamodb.Client, items []map[string]dyn2Types.AttributeValue) {
b.Helper()

keys := make([]map[string]dyn2Types.AttributeValue, len(items))
tws := make([]dyn2Types.TransactWriteItem, len(items))
for i, item := range items {
keys[i] = map[string]dyn2Types.AttributeValue{"name": items[i]["name"]}
item["x"] = &dyn2Types.AttributeValueMemberN{Value: strconv.Itoa(i + 2)}
put := &dyn2Types.Put{TableName: &benchmarkTableName, Item: items[i]}
ce, err := expression.NewBuilder().
WithCondition(expression.Name("rev").Equal(expression.Value(1))).
Build()
if err != nil {
b.Fatal(err)
}
put.ExpressionAttributeNames = ce.Names()
put.ExpressionAttributeValues = ce.Values()
put.ConditionExpression = ce.Condition()
tws[i] = dyn2Types.TransactWriteItem{Put: put}
}
_, err := db.BatchGetItem(context.Background(), &dynamodb.BatchGetItemInput{
RequestItems: map[string]dyn2Types.KeysAndAttributes{
benchmarkTableName: {Keys: keys},
},
})
if err != nil {
b.Fatal(err)
}
_, err = db.TransactWriteItems(context.Background(), &dynamodb.TransactWriteItemsInput{TransactItems: tws})
if err != nil {
b.Fatal(err)
}
}
Loading
Loading