From 3b7bf42f30ac78d8d431eb19be42a888c2b84d74 Mon Sep 17 00:00:00 2001 From: Ivan Senic Date: Wed, 22 Sep 2021 15:46:05 +0200 Subject: [PATCH] added mongoDB CRUD scenarios --- .../http-docsapi-crud-basic.yaml | 16 +- .../http-docsapi-crud-dataset.yaml | 14 +- .../activities/mongodb-crud-basic.md | 14 ++ .../activities/mongodb-crud-basic.yaml | 183 ++++++++++++++++++ .../activities/mongodb-crud-dataset.md | 18 ++ .../activities/mongodb-crud-dataset.yaml | 114 +++++++++++ 6 files changed, 344 insertions(+), 15 deletions(-) create mode 100644 driver-mongodb/src/main/resources/activities/mongodb-crud-basic.md create mode 100644 driver-mongodb/src/main/resources/activities/mongodb-crud-basic.yaml create mode 100644 driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.md create mode 100644 driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.yaml diff --git a/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-basic.yaml b/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-basic.yaml index 1093ad4fb..933782e0a 100644 --- a/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-basic.yaml +++ b/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-basic.yaml @@ -7,11 +7,11 @@ description: | scenarios: default: - schema: run driver=http tags==phase:schema threads==1 cycles==UNDEF - write: run driver=http tags==phase:main,type:write cycles===TEMPLATE(write-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn - read: run driver=http tags==phase:main,type:read cycles===TEMPLATE(read-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn - update: run driver=http tags==phase:main,type:update cycles===TEMPLATE(update-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn - delete: run driver=http tags==phase:main,type:delete cycles===TEMPLATE(delete-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + schema: run driver=http tags==phase:schema threads==1 cycles==UNDEF + write: run driver=http tags==phase:main,type:write cycles===TEMPLATE(write-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + read: run driver=http tags==phase:main,type:read cycles===TEMPLATE(read-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + update: run driver=http tags==phase:main,type:update cycles===TEMPLATE(update-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + delete: run driver=http tags==phase:main,type:delete cycles===TEMPLATE(delete-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn bindings: # To enable an optional weighted set of hosts in place of a load balancer @@ -31,7 +31,7 @@ bindings: gender: WeightedStrings('M:10;F:10;O:1') full_name: FullNames() married: ModuloToBoolean() - city: CSVSampler('city','n/a','name','data/simplemaps/uszips.csv') + city: Cities() country_code: CountryCodes() lat: Uniform(-180d, 180d) lng: Hash() -> long; Uniform(-180d, 180d) @@ -129,7 +129,7 @@ blocks: phase: main type: update statements: - - write-document: PUT <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{random_key} + - update-document: PUT <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{random_key} Accept: "application/json" X-Cassandra-Request-Id: "{request_id}" X-Cassandra-Token: "<>" @@ -166,7 +166,7 @@ blocks: phase: main type: delete statements: - - write-document: DELETE <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{seq_key} + - delete-document: DELETE <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{seq_key} Accept: "application/json" X-Cassandra-Request-Id: "{request_id}" X-Cassandra-Token: "<>" diff --git a/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-dataset.yaml b/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-dataset.yaml index 09d19c6d0..e7a89f5b3 100644 --- a/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-dataset.yaml +++ b/driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-dataset.yaml @@ -7,11 +7,11 @@ description: | scenarios: default: - schema: run driver=http tags==phase:schema threads==1 cycles==UNDEF - write: run driver=http tags==phase:main,type:write cycles===TEMPLATE(write-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn - read: run driver=http tags==phase:main,type:read cycles===TEMPLATE(read-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn - update: run driver=http tags==phase:main,type:update cycles===TEMPLATE(update-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn - delete: run driver=http tags==phase:main,type:delete cycles===TEMPLATE(delete-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + schema: run driver=http tags==phase:schema threads==1 cycles==UNDEF + write: run driver=http tags==phase:main,type:write cycles===TEMPLATE(write-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + read: run driver=http tags==phase:main,type:read cycles===TEMPLATE(read-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + update: run driver=http tags==phase:main,type:update cycles===TEMPLATE(update-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + delete: run driver=http tags==phase:main,type:delete cycles===TEMPLATE(delete-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn bindings: # To enable an optional weighted set of hosts in place of a load balancer @@ -97,7 +97,7 @@ blocks: phase: main type: update statements: - - write-document: PUT <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{random_key} + - update-document: PUT <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{random_key} Accept: "application/json" X-Cassandra-Request-Id: "{request_id}" X-Cassandra-Token: "<>" @@ -113,7 +113,7 @@ blocks: phase: main type: delete statements: - - write-document: DELETE <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{seq_key} + - update-document: DELETE <>://{weighted_hosts}:<><>/v2/namespaces/<>/collections/<>/{seq_key} Accept: "application/json" X-Cassandra-Request-Id: "{request_id}" X-Cassandra-Token: "<>" diff --git a/driver-mongodb/src/main/resources/activities/mongodb-crud-basic.md b/driver-mongodb/src/main/resources/activities/mongodb-crud-basic.md new file mode 100644 index 000000000..744062b7e --- /dev/null +++ b/driver-mongodb/src/main/resources/activities/mongodb-crud-basic.md @@ -0,0 +1,14 @@ +--- +title: mongoDB CRUD Basic +weight: 1 +--- + +## Description + +The mongoDB CRUD Basic workflow emulates CRUD operations for the mongoDB using generated JSON documents. +It's a counterpart of the Stargate's Documents API CRUD Basic workflow. +Please refer to [http-docsapi-crud-basic.md](../../../../../driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-basic.md) for the general workflow design details. + +## Indexing + +To simulate a realistic situation as much as possible, this workflow creates 3 additional indexes (apart from `_id`) for the collection where documents are stored. diff --git a/driver-mongodb/src/main/resources/activities/mongodb-crud-basic.yaml b/driver-mongodb/src/main/resources/activities/mongodb-crud-basic.yaml new file mode 100644 index 000000000..de7196042 --- /dev/null +++ b/driver-mongodb/src/main/resources/activities/mongodb-crud-basic.yaml @@ -0,0 +1,183 @@ +# nb -v run driver=mongodb yaml=mongodb-crud-basic tags=phase:schema connection=mongodb://127.0.0.1 database=testdb + +description: | + This workload emulates CRUD operations for the mongoDB. + It generates a simple JSON document to be used for writes and updates. + It's a counterpart of the Stargate's Documents API CRUD Basic workflow. + +scenarios: + default: + schema: run driver=mongodb tags==phase:schema threads==1 cycles==UNDEF + write: run driver=mongodb tags==phase:main,type:write cycles===TEMPLATE(write-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + read: run driver=mongodb tags==phase:main,type:read cycles===TEMPLATE(read-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + update: run driver=mongodb tags==phase:main,type:update cycles===TEMPLATE(update-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + delete: run driver=mongodb tags==phase:main,type:delete cycles===TEMPLATE(delete-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + +bindings: + seq_key: Mod(<>); ToString() -> String + random_key: Uniform(0,<>); ToString() -> String + + user_id: ToHashedUUID(); ToString() -> String + created_on: Uniform(1262304000,1577836800) -> long + gender: WeightedStrings('M:10;F:10;O:1') + full_name: FullNames() + married: ModuloToBoolean() + city: Cities() + country_code: CountryCodes() + lat: Uniform(-180d, 180d) + lng: Hash() -> long; Uniform(-180d, 180d) + friend_id: Add(-1); ToHashedUUID(); ToString() -> String + +blocks: + - tags: + phase: schema + statements: + - dummy-insert: | + { + insert: "<>", + documents: [ { _id: "dummyyyy" } ] + } + + - drop-collection: | + { + drop: "<>" + } + tags: + name: drop-collection + + - create-collection: | + { + create: "<>" + } + tags: + name: create-collection + + - create-indexes: | + { + createIndexes: "<>", + indexes: [ + { + key: { user_id: 1 }, + name: "user_id_idx", + unique: true + }, + { + key: { created_on: 1 }, + name: "created_on_idx" + }, + { + key: { gender: 1 }, + name: "gender_idx" + } + ] + } + tags: + name: create-indexes + + - name: main-write + tags: + phase: main + type: write + statements: + - write-document: | + { + insert: "<>", + documents: [ + { + "_id": "{seq_key}", + "user_id": "{user_id}", + "created_on": {created_on}, + "gender": "{gender}", + "full_name": "{full_name}", + "married": {married}, + "address": { + "primary": { + "city": "{city}", + "cc": "{country_code}" + }, + "secondary": {} + }, + "coordinates": [ + {lat}, + {lng} + ], + "children": [], + "friends": [ + "{friend_id}" + ], + "debt": null + } + ] + } + tags: + name: write-document + + - name: main-read + tags: + phase: main + type: read + statements: + - read-document: | + { + find: "<>", + filter: { _id: "{random_key}" } + } + tags: + name: read-document + + - name: main-update + tags: + phase: main + type: update + statements: + - update-document: | + { + update: "<>", + updates: [ + { + q: { _id: "{random_key}" }, + u: { + "_id": "{seq_key}", + "user_id": "{user_id}", + "created_on": {created_on}, + "gender": "{gender}", + "full_name": "{full_name}", + "married": {married}, + "address": { + "primary": { + "city": "{city}", + "cc": "{country_code}" + }, + "secondary": {} + }, + "coordinates": [ + {lat}, + {lng} + ], + "children": [], + "friends": [ + "{friend_id}" + ], + "debt": null + } + } + ] + } + tags: + name: update-document + + - name: main-delete + tags: + phase: main + type: delete + statements: + - delete-document: | + { + delete: "<>", + deletes: [ + { + q: { _id: "{seq_key}" }, + limit: 1 + } + ] + } diff --git a/driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.md b/driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.md new file mode 100644 index 000000000..2ab9ae289 --- /dev/null +++ b/driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.md @@ -0,0 +1,18 @@ +--- +title: mongoDB CRUD Dataset +weight: 2 +--- + +## Description + +The mongoDB CRUD Dataset workflow emulates CRUD operations for the mongoDB using JSON documents from an external dataset. +It's a counterpart of the Stargate's Documents API CRUD Dataset workflow. +Please refer to [http-docsapi-crud-dataset.md](../../../../../driver-http/src/main/resources/activities/documents-api/http-docsapi-crud-dataset.md) for the general workflow design details. + +## Indexing + +To simulate a realistic situation as much as possible, this workflow allows creation of the indexes using the parameter: + +* `indexes` - Specifies the indexes to create. Each document in the array specifies a separate index. Corresponds to the `indexes` field in the [mongoDB *createIndexes* command](https://docs.mongodb.com/manual/reference/command/createIndexes/#mongodb-dbcommand-dbcmd.createIndexes). + +If parameter `indexes` is not specify, a dummy sparse index will be created. diff --git a/driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.yaml b/driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.yaml new file mode 100644 index 000000000..5bef53850 --- /dev/null +++ b/driver-mongodb/src/main/resources/activities/mongodb-crud-dataset.yaml @@ -0,0 +1,114 @@ +# nb -v run driver=mongodb yaml=mongodb-crud-dataset tags=phase:schema connection=mongodb://127.0.0.1 database=testdb dataset_file=path/to/data.json + +description: | + This workload emulates CRUD operations for the mongoDB. + It requires a data set file, where each line is a single JSON document to be used for writes and updates. + It's a counterpart of the Stargate's Documents API CRUD Dataset workflow. + +scenarios: + default: + schema: run driver=mongodb tags==phase:schema threads==1 cycles==UNDEF + write: run driver=mongodb tags==phase:main,type:write cycles===TEMPLATE(write-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + read: run driver=mongodb tags==phase:main,type:read cycles===TEMPLATE(read-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + update: run driver=mongodb tags==phase:main,type:update cycles===TEMPLATE(update-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + delete: run driver=mongodb tags==phase:main,type:delete cycles===TEMPLATE(delete-cycles,TEMPLATE(docscount,10000000)) threads=auto errors=timer,warn + +bindings: + seq_key: Mod(<>); ToString() -> String + random_key: Uniform(0,<>); ToString() -> String + +blocks: + - tags: + phase: schema + statements: + - dummy-insert: | + { + insert: "<>", + documents: [ { _id: "dummyyyy" } ] + } + + - drop-collection: | + { + drop: "<>" + } + tags: + name: drop-collection + + - create-collection: | + { + create: "<>" + } + tags: + name: create-collection + + - create-indexes: | + { + createIndexes: "<>", + indexes: <> + } + tags: + name: create-indexes + + - name: main-write + tags: + phase: main + type: write + statements: + - write-document: | + { + insert: "<>", + documents: [ { "_id": "{seq_key}", {document_json_without_id} ] + } + tags: + name: write-document + bindings: + document_json_without_id: ModuloLineToString('<>'); ReplaceRegex('^\{', '') + + - name: main-read + tags: + phase: main + type: read + statements: + - read-document: | + { + find: "<>", + filter: { _id: "{random_key}" } + } + tags: + name: read-document + + - name: main-update + tags: + phase: main + type: update + statements: + - update-document: | + { + update: "<>", + updates: [ + { + q: { _id: "{random_key}" }, + u: { "_id": "{random_key}", {document_json_without_id} + } + ] + } + tags: + name: update-document + bindings: + document_json_without_id: ModuloLineToString('<>'); ReplaceRegex('^\{', '') + + - name: main-delete + tags: + phase: main + type: delete + statements: + - delete-document: | + { + delete: "<>", + deletes: [ + { + q: { _id: "{seq_key}" }, + limit: 1 + } + ] + }