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

Enhancement/performance optimizations #473

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [4.3. Custom Serialization](#43-custom-serialization)
* [4.4. Global Serialization](#44-global-serialization)
* [4.5. JSON Serialization](#45-json-serialization)
* [4.6. String Serialization](#46-string-serialization)
* [5. Setting Up Client Network](#5-setting-up-client-network)
* [5.1. Providing Member Addresses](#51-providing-member-addresses)
* [5.2. Setting Smart Routing](#52-setting-smart-routing)
Expand Down Expand Up @@ -1084,6 +1085,30 @@ config.serializationConfig.jsonStringDeserializationPolicy = JsonStringDeseriali
}
```

## 4.6. String Serialization

Starting from version v3.12 Hazelcast Node.js client follows UTF-8 standard (RFC 3629) for string data type serialization of 4 byte UTF characters, like less common CJK characters and emoji. This may lead to compatibility issues with Hazelcast IMDG 3.x and other client libraries for string and JSON values. Such issues are represented by `Malformed byte sequence` (error code 64) errors on members and other clients.

In case if you encounter these error messages, you can switch to the legacy mode of string serialization that provides full compatibility with Hazelcast IMDG 3.x members and other client libraries.

Below is the configuration required to use the legacy string serialization.

**Programmatic Configuration:**

```javascript
config.serializationConfig.stringSerializationPolicy = StringSerializationPolicy.LEGACY;
```

**Declarative Configuration:**

```json
{
"serialization": {
"stringSerializationPolicy": "legacy"
}
}
```

# 5. Setting Up Client Network

All network related configuration of Hazelcast Node.js client is performed via the `network` element in the declarative configuration file, or in the object `ClientNetworkConfig` when using programmatic configuration. Let's first give the examples for these two approaches. Then we will look at its sub-elements and attributes.
Expand Down
38 changes: 38 additions & 0 deletions benchmark/MapGetRunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const REQ_COUNT = 10000;
const BATCH_SIZE = 100;

const Benchmark = require('./SimpleBenchmark');
const Client = require('../.').Client;

function randomString(len) {
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let res = '';
for (let i = 0; i < len; i++) {
const pos = Math.floor(Math.random() * charSet.length);
res += charSet.substring(pos, pos + 1);
}
return res;
}

const KEY = '00000000-0000-0000-0000-000000000000';
const VAL = randomString(100 * 1024);

Client.newHazelcastClient()
.then((client) => client.getMap('default'))
.then((map) => {
return map.set(KEY, VAL)
.then(() => map);
})
.then((map) => {
const benchmark = new Benchmark({
nextOp: () => map.get(KEY),
totalOpsCount: REQ_COUNT,
batchSize: BATCH_SIZE
});
return benchmark.run()
.then(() => map.destroy())
.then(() => map.client.shutdown());
})
.then(() => console.log('Benchmark finished'));
3 changes: 2 additions & 1 deletion benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

A collection of simple benchmarks that run operations on Map in parallel, measure execution time and calculate throughput:
* `MapPutRunner` - runs `map.put('foo', 'bar')` operations.
* `MapGetRunner` - runs `map.get` operations that read string value with >100 KB size.
* `MapRandomOpRunner` - runs randomly selected operations (`get`, `put`, `remove`).

## Running the benchmark
Expand All @@ -21,7 +22,7 @@ Next, run at least one instance of IMDG. The most simple way to do it would be t
docker run -p 5701:5701 hazelcast/hazelcast:3.11.2
```

Finally, run the benchmark:
Finally, run one of the benchmarks, e.g.:
```bash
node benchmark/MapPutRunner.js
```
Expand Down
7 changes: 7 additions & 0 deletions config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@
],
"default": "double"
},
"stringSerialization": {
"enum": [
"standard",
"legacy"
],
"default": "standard"
},
"isBigEndian": {
"type": "boolean",
"default": false
Expand Down
1 change: 1 addition & 0 deletions hazelcast-client-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"defaultNumberType": "double",
"isBigEndian": true,
"jsonStringDeserializationPolicy": "eager",
"stringSerialization": "standard",
"dataSerializableFactories": [
{
"path": "path/to/file",
Expand Down
Loading