diff --git a/README.md b/README.md index e70c19d..09b8388 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,25 @@ K6 extension to perform tests on couchbase. ## Build Instructions - Install xk6 using (go install go.k6.io/xk6/cmd/xk6@latest) + ### For Development + ```shell git clone git@github.com:thotasrinath/xk6-couchbase.git cd xk6-couchbase xk6 build --output xk6-couchbase --with github.com/thotasrinath/xk6-couchbase=. ``` + ### For Use + ```shell xk6 build --with github.com/thotasrinath/xk6-couchbase@latest ``` ## Examples + ### Document Insertion Test + ```js import xk6_couchbase from 'k6/x/couchbase'; @@ -58,13 +64,16 @@ function makeId(length) { } ``` + ##### Below is the example commands to test the script + ```bash # Update examples/test-insert.js with cluster credentials and bucket name ./xk6-couchbase run --vus 10 --duration 30s examples/test-insert.js ``` ### Batch Insert Documents + ```js import xk6_couchbase from 'k6/x/couchbase'; @@ -109,7 +118,25 @@ function makeId(length) { } ``` + +### Exists test + +```js +import xk6_couchbase from 'k6/x/couchbase'; + + +const client = xk6_couchbase.newClient('localhost', '', ''); +export default () => { + // syntax :: client.exists("", "", "", ""); + var res = client.exists("test", "_default", "_default", "002wPJwiJArcUpz"); + console.log(res); +} + +``` + + ### FindOne test + ```js import xk6_couchbase from 'k6/x/couchbase'; @@ -124,6 +151,7 @@ export default () => { ``` ### Document Deletion Test + ```js import xk6_couchbase from 'k6/x/couchbase'; @@ -137,6 +165,7 @@ export default () => { ``` ### Query test + ```js import xk6_couchbase from 'k6/x/couchbase'; @@ -150,7 +179,8 @@ export default () => { } ``` -### Query using a prepared statement +### Query using a prepared statement + ```js import xk6_couchbase from 'k6/x/couchbase'; @@ -165,6 +195,7 @@ export default () => { ``` ### Upsert test + #### Initial data load is expected. Data with sequential Id's could be generated with below script. File - examples/load-sequential-data.js ```js @@ -196,7 +227,9 @@ export default function () { client.insert("test", "_default", "_default", String(docId), doc); } ``` + #### Upsert test script to generate random id in range and excute Upsert. File - examples/test-upsert.js + ```js import xk6_couchbase from 'k6/x/couchbase'; import {randomIntBetween} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; @@ -215,3 +248,51 @@ export default () => { client.upsert("test", "_default", "_default", String(randomIntBetween(0, 100000)), doc); } ``` + + +### Client with options + +Default NewClient is a good start to get familiar with the extension with little wiring and get going. For refined flexibility of connection management during the tests, following additional interfaces are provided: + +* NewClientWithSharedConnection: Shares a single connection across all the VUs and maximizes the QPS without affecting client resources. +* NewClientPerVU: Creates new client connection for each VU. Useful for testing max number of connections that the cluster can handle. + +In addition to controlling number of connections, both the functions provide: + +* Ability to pre-warm the buckets as part of initialization. +* Ability to set timeout duration for bucket readiness (WaitUntilReady timeout). +* Ability to control the connection buffer size. By default couchbase client uses 20MB buffer size which limits the number of concurrent connections that can be created by a single client instance. + +#### Example for wiring client with shared connection across VUs + +```js +import xk6_couchbase from 'k6/x/couchbase'; + + +const dbConfig = { hostname: 'localhost', username: '', password: '' }; +const bucketsToPreWarm = ['test']; +const client = xk6_couchbase.newClientWithSharedConnection(dbConfig, bucketsToPreWarm, "5s"); +export default () => { + // syntax :: client.findOne("", "", "", ""); + var res = client.findOne("test", "_default", "_default", "002wPJwiJArcUpz"); + console.log(res); +} + +``` + +#### Example for wiring client with unique connections per VUs + +```javascript +import xk6_couchbase from 'k6/x/couchbase'; + + +const dbConfig = { hostname: 'localhost', username: '', password: '' }; +const bucketsToPreWarm = ['test']; +const client = xk6_couchbase.newClientPerVU(dbConfig, bucketsToPreWarm, "5s"); +export default () => { + // syntax :: client.findOne("", "", "", ""); + var res = client.findOne("test", "_default", "_default", "002wPJwiJArcUpz"); + console.log(res); +} + +```