Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme for using new/flexible interfaces #18

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
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
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -109,7 +118,25 @@ function makeId(length) {
}

```

### Exists test

```js
import xk6_couchbase from 'k6/x/couchbase';


const client = xk6_couchbase.newClient('localhost', '<username>', '<password>');
export default () => {
// syntax :: client.exists("<db>", "<scope>", "<keyspace>", "<docId>");
var res = client.exists("test", "_default", "_default", "002wPJwiJArcUpz");
console.log(res);
}

```


### FindOne test

```js
import xk6_couchbase from 'k6/x/couchbase';

Expand All @@ -124,6 +151,7 @@ export default () => {
```

### Document Deletion Test

```js
import xk6_couchbase from 'k6/x/couchbase';

Expand All @@ -137,6 +165,7 @@ export default () => {
```

### Query test

```js
import xk6_couchbase from 'k6/x/couchbase';

Expand All @@ -150,7 +179,8 @@ export default () => {
}
```

### Query using a prepared statement
### Query using a prepared statement

```js
import xk6_couchbase from 'k6/x/couchbase';

Expand All @@ -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
Expand Down Expand Up @@ -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';
Expand All @@ -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: '<username>', password: '<password>' };
const bucketsToPreWarm = ['test'];
const client = xk6_couchbase.newClientWithSharedConnection(dbConfig, bucketsToPreWarm, "5s");
export default () => {
// syntax :: client.findOne("<db>", "<scope>", "<keyspace>", "<docId>");
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: '<username>', password: '<password>' };
const bucketsToPreWarm = ['test'];
const client = xk6_couchbase.newClientPerVU(dbConfig, bucketsToPreWarm, "5s");
export default () => {
// syntax :: client.findOne("<db>", "<scope>", "<keyspace>", "<docId>");
var res = client.findOne("test", "_default", "_default", "002wPJwiJArcUpz");
console.log(res);
}

```
Loading