-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DC-1780] Add clustering and mixed insert/update mode (#27)
This PR adds the following functionality: - Specify number of distinct cluster values to test clustered collections via `NUM_CLUSTERS` - Specify percentage of documents hitting a specific cluster to simulate hot clustering via `HOT_CLUSTER_PERCENTAGE` - Add a mode that mixes inserts and updates randomly via `mixed` mode, `UPDATE_PERCENTAGE`, and `MAX_DOCS` Mixed mode only works well if there's one kubernetes replica doing the work. The max doc id, n, is tracked locally so that any docs with doc id 0 to n will be updates and n+1 will be an insert. The alternative that would work for multiple replicas is to use a uuid on inserts and for updates choose from 0 to n. This means the collection would need to be populated with docs from 0 to n first, and any newly inserted docs with uuids would never be updated.
- Loading branch information
1 parent
3cf72f2
commit 51fc3f0
Showing
4 changed files
with
118 additions
and
18 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 |
---|---|---|
|
@@ -10,6 +10,17 @@ import ( | |
guuid "github.com/google/uuid" | ||
) | ||
|
||
type DocumentSpec struct { | ||
Destination string | ||
GeneratorIdentifier string | ||
BatchSize int | ||
Mode string | ||
IdMode string | ||
UpdatePercentage int | ||
NumClusters int | ||
HotClusterPercentage int | ||
} | ||
|
||
type DocStruct struct { | ||
Guid string | ||
IsActive bool | ||
|
@@ -59,8 +70,9 @@ type FriendDetailsStruct struct { | |
} | ||
|
||
var doc_id = 0 | ||
var max_doc_id = 0 | ||
|
||
func GenerateDoc(destination, identifier string, idMode string) (interface{}, error) { | ||
func GenerateDoc(spec DocumentSpec) (interface{}, error) { | ||
docStruct := DocStruct{} | ||
err := faker.FakeData(&docStruct) | ||
if err != nil { | ||
|
@@ -74,43 +86,69 @@ func GenerateDoc(destination, identifier string, idMode string) (interface{}, er | |
return nil, fmt.Errorf("failed to unmarshal document: %w", err) | ||
} | ||
|
||
if destination == "rockset" { | ||
if idMode == "uuid" { | ||
if spec.Destination == "rockset" { | ||
if spec.Mode == "mixed" { | ||
// Randomly choose a number to decide whether to generate a doc with an existing doc id | ||
if rand.Intn(100) < spec.UpdatePercentage { | ||
// Choose random id from one already existing doc id | ||
doc["_id"] = formatDocId(rand.Intn(getMaxDoc())) | ||
} else { | ||
doc["_id"] = formatDocId(getMaxDoc()) | ||
SetMaxDoc(getMaxDoc()+1) | ||
} | ||
doc_id = doc_id + 1 | ||
// All other modes | ||
} else if spec.IdMode == "uuid" { | ||
doc["_id"] = guuid.New().String() | ||
} else { | ||
} else if spec.IdMode == "sequential"{ | ||
doc["_id"] = formatDocId(doc_id) | ||
doc_id = doc_id + 1 | ||
} else { | ||
panic(fmt.Sprintf("Unsupported generateDoc case: %s", spec.IdMode)) | ||
} | ||
} | ||
|
||
if spec.NumClusters > 0 { | ||
doc["cluster1"] = getClusterKey(spec.NumClusters, spec.HotClusterPercentage) | ||
} | ||
|
||
doc["_event_time"] = CurrentTimeMicros() | ||
// Set _ts as _event_time is not mutable | ||
doc["_ts"] = CurrentTimeMicros() | ||
doc["generator_identifier"] = identifier | ||
doc["generator_identifier"] = spec.GeneratorIdentifier | ||
|
||
return doc, nil | ||
} | ||
|
||
func getClusterKey(numClusters int, hotClusterPercentage int) string { | ||
if hotClusterPercentage > 0 && rand.Intn(100) < hotClusterPercentage { | ||
return "[email protected]" | ||
} else { | ||
return fmt.Sprintf("%[email protected]", rand.Intn(numClusters)) | ||
} | ||
} | ||
|
||
func getMaxDoc() int { | ||
// doc_ids are left padded monotonic integers, | ||
//this returns the highest exclusive doc id for purposes of issuing patches. | ||
return doc_id | ||
return max_doc_id | ||
} | ||
|
||
func SetMaxDoc(maxDocId int) { | ||
doc_id = maxDocId | ||
// doc_id = maxDocId | ||
max_doc_id = maxDocId | ||
} | ||
|
||
func CurrentTimeMicros() int64 { | ||
t := time.Now() | ||
return int64(time.Nanosecond) * t.UnixNano() / int64(time.Microsecond) | ||
} | ||
|
||
func GenerateDocs(batchSize int, destination, identifier string, idMode string) ([]interface{}, error) { | ||
var docs = make([]interface{}, batchSize, batchSize) | ||
func GenerateDocs(spec DocumentSpec) ([]interface{}, error) { | ||
var docs = make([]interface{}, spec.BatchSize, spec.BatchSize) | ||
|
||
for i := 0; i < batchSize; i++ { | ||
doc, err := GenerateDoc(destination, identifier, idMode) | ||
for i := 0; i < spec.BatchSize; i++ { | ||
doc, err := GenerateDoc(spec) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -262,7 +300,7 @@ func genUniqueInRange(limit int, count int) []int { | |
|
||
ids := make([]int, count) | ||
i := 0 | ||
for k, _ := range ids_to_patch { | ||
for k := range ids_to_patch { | ||
ids[i] = k | ||
i++ | ||
} | ||
|
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