-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flush rules to be cognizant of in-memory database size (#89)
- Loading branch information
Showing
13 changed files
with
375 additions
and
38 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,56 @@ | ||
package optimization | ||
|
||
import ( | ||
"fmt" | ||
"github.com/artie-labs/transfer/lib/kafkalib" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func BenchmarkTableData_ApproxSize_TallTable(b *testing.B) { | ||
td := NewTableData(nil, nil, kafkalib.TopicConfig{}) | ||
for n := 0; n < b.N; n++ { | ||
td.InsertRow(fmt.Sprint(n), map[string]interface{}{ | ||
"id": n, | ||
"name": "Robin", | ||
"dog": "dusty the mini aussie", | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkTableData_ApproxSize_WideTable(b *testing.B) { | ||
td := NewTableData(nil, nil, kafkalib.TopicConfig{}) | ||
for n := 0; n < b.N; n++ { | ||
td.InsertRow(fmt.Sprint(n), map[string]interface{}{ | ||
"id": n, | ||
"name": "Robin", | ||
"dog": "dusty the mini aussie", | ||
"favorite_fruits": []string{"strawberry", "kiwi", "oranges"}, | ||
"random": false, | ||
"team": []string{"charlie", "jacqueline"}, | ||
"email": "[email protected]", | ||
"favorite_languages": []string{"go", "sql"}, | ||
"favorite_databases": []string{"postgres", "bigtable"}, | ||
"created_at": time.Now(), | ||
"updated_at": time.Now(), | ||
"negative_number": -500, | ||
"nestedObject": map[string]interface{}{ | ||
"foo": "bar", | ||
"abc": "def", | ||
}, | ||
"array_of_objects": []map[string]interface{}{ | ||
{ | ||
"foo": "bar", | ||
}, | ||
{ | ||
"foo_nested": map[string]interface{}{ | ||
"foo_foo": "bar_bar", | ||
}, | ||
}, | ||
}, | ||
"is_deleted": false, | ||
"lorem_ipsum": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elementum aliquet mi at efficitur. Praesent at erat ac elit faucibus convallis. Donec fermentum tellus eu nunc ornare, non convallis justo facilisis. In hac habitasse platea dictumst. Praesent eu ante vitae erat semper finibus eget ac mauris. Duis gravida cursus enim, nec sagittis arcu placerat sed. Integer semper orci justo, nec rhoncus libero convallis sed.", | ||
"lorem_ipsum2": "Fusce vitae elementum tortor. Vestibulum consectetur ante id nibh ullamcorper, quis sodales turpis tempor. Duis pellentesque suscipit nibh porta posuere. In libero massa, efficitur at ultricies sit amet, vulputate ac ante. In euismod erat eget nulla blandit pretium. Ut tempor ante vel congue venenatis. Vestibulum at metus nec nibh iaculis consequat suscipit ac leo. Maecenas vitae rutrum nulla, quis ultrices justo. Aliquam ipsum ex, luctus ac diam eget, tempor tempor risus.", | ||
}) | ||
} | ||
} |
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,84 @@ | ||
package optimization | ||
|
||
import ( | ||
"fmt" | ||
"github.com/artie-labs/transfer/lib/kafkalib" | ||
"github.com/artie-labs/transfer/lib/size" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestTableData_InsertRow(t *testing.T) { | ||
td := NewTableData(nil, nil, kafkalib.TopicConfig{}) | ||
assert.Equal(t, 0, int(td.Rows())) | ||
|
||
// See if we can add rows to the private method. | ||
td.RowsData()["foo"] = map[string]interface{}{ | ||
"foo": "bar", | ||
} | ||
|
||
assert.Equal(t, 0, int(td.Rows())) | ||
|
||
// Now insert the right way. | ||
td.InsertRow("foo", map[string]interface{}{ | ||
"foo": "bar", | ||
}) | ||
|
||
assert.Equal(t, 1, int(td.Rows())) | ||
} | ||
|
||
func TestTableData_InsertRowApproxSize(t *testing.T) { | ||
// In this test, we'll insert 1000 rows, update X and then delete Y | ||
// Does the size then match up? We will iterate over a map to take advantage of the in-deterministic ordering of a map | ||
// So we can test multiple updates, deletes, etc. | ||
td := NewTableData(nil, nil, kafkalib.TopicConfig{}) | ||
numInsertRows := 1000 | ||
numUpdateRows := 420 | ||
numDeleteRows := 250 | ||
|
||
for i := 0; i < numInsertRows; i ++ { | ||
td.InsertRow(fmt.Sprint(i), map[string]interface{}{ | ||
"foo": "bar", | ||
"array": []int{1, 2, 3, 4, 5}, | ||
"boolean": true, | ||
"nested_object": map[string]interface{}{ | ||
"nested": map[string]interface{}{ | ||
"foo": "bar", | ||
"true": false, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var updateCount int | ||
for updateKey := range td.RowsData() { | ||
updateCount += 1 | ||
td.InsertRow(updateKey, map[string]interface{}{ | ||
"foo": "foo", | ||
"bar": "bar", | ||
}) | ||
|
||
if updateCount > numUpdateRows { | ||
break | ||
} | ||
} | ||
|
||
var deleteCount int | ||
for deleteKey := range td.RowsData() { | ||
deleteCount += 1 | ||
td.InsertRow(deleteKey, map[string]interface{}{ | ||
"__artie_deleted": true, | ||
}) | ||
|
||
if deleteCount > numDeleteRows { | ||
break | ||
} | ||
} | ||
|
||
var actualSize int | ||
for _, rowData := range td.RowsData() { | ||
actualSize += size.GetApproxSize(rowData) | ||
} | ||
|
||
assert.Equal(t, td.approxSize, actualSize) | ||
} |
Oops, something went wrong.