Skip to content

Commit

Permalink
Replace old benchmark with SimpliestMapPipeliningBenchmark
Browse files Browse the repository at this point in the history
Also added a readme for the benchmark
  • Loading branch information
puzpuzpuz committed Mar 7, 2019
1 parent 324b43c commit de88269
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 259 deletions.
40 changes: 40 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Simple benchmark for Hazelcast IMDG Node.js Client

This simple benchmark runs `map.put('foo', 'bar')` operations in parallel, measures execution time and calculates throughput.

## Running the benchmark

First, install dependencies and build the client:
```bash
npm install
```

Then, build the client (compile TypeScript):
```bash
npm run compile
```

Next, run at least one instance of IMDG. The most simple way to do it would be to use the [official Docker image](https://hub.docker.com/r/hazelcast/hazelcast/):
```bash
docker run -p 5701:5701 hazelcast/hazelcast:3.11.2
```

Finally, run the benchmark:
```bash
node benchmark/SimpleMapBenchmark.js
```

The benchmark will run and produce its results into the console:
```bash
[DefaultLogger] INFO at ConnectionAuthenticator: Connection to 172.17.0.2:5701 authenticated
[DefaultLogger] INFO at ClusterService: Members received.
[ Member {
address: Address { host: '172.17.0.2', port: 5701, type: 4 },
uuid: '1c07e7a7-5301-452c-b098-3e662126e4fe',
isLiteMember: false,
attributes: {} } ]
[DefaultLogger] INFO at HazelcastClient: Client started
Took 0.855 seconds for 50000 requests
Ops/s: 58479.53216374269
Benchmark finished
```
94 changes: 42 additions & 52 deletions benchmark/SimpleMapBenchmark.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,46 @@
var REQ_COUNT = 50000;
var ENTRY_COUNT = 10 * 1000;
var VALUE_SIZE = 10000;
var GET_PERCENTAGE = 40;
var PUT_PERCENTAGE = 40;
var value_string = '';
for (var i = 0; i < VALUE_SIZE; i++) {
value_string = value_string + 'x';
}
var Test = {
map: undefined,
finishCallback: undefined,
ops: 0,
increment: function () {
this.ops = this.ops + 1;
if (this.ops === REQ_COUNT) {
var date = new Date();
this.run = function () {
};
this.finishCallback(date);
}
},
run: function () {
var key = Math.random() * ENTRY_COUNT;
var opType = Math.floor(Math.random() * 100);
if (opType < GET_PERCENTAGE) {
this.map.get(key).then(this.increment.bind(this));
} else if (opType < GET_PERCENTAGE + PUT_PERCENTAGE) {
this.map.put(key, value_string).then(this.increment.bind(this));
} else {
this.map.remove(key)
.then(this.increment.bind(this));
}
setImmediate(this.run.bind(this));
const REQ_COUNT = 50000;
const BATCH_SIZE = 100;

class Benchmark {
constructor(map) {
this.map = map;
this.ops = 0;
}
// increments ops counter, creates a new op and returns it
_nextOp() {
this.ops++;
return this.map.put('foo', 'bar');
}
// chains next op once one of ops finishes to keep constant concurrency of ops
_chainNext(p) {
return p.then(() => {
if (this.ops < REQ_COUNT) {
return this._chainNext(this._nextOp());
}
});
}
run() {
// initial batch of ops (no-op promises)
const batch = new Array(BATCH_SIZE).fill(Promise.resolve());
const start = new Date();
return Promise.all(batch.map(this._chainNext.bind(this)))
.then(() => {
const finish = new Date();
const tookSec = (finish - start) / 1000;
console.log(`Took ${tookSec} seconds for ${this.ops} requests`);
console.log(`Ops/s: ${this.ops / tookSec}`);
});
}
};
var Client = require('../.').Client;
var hazelcastClient;

Client.newHazelcastClient().then(function (client) {
hazelcastClient = client;
return hazelcastClient.getMap('default');
}).then(function (mp) {
Test.map = mp;
const Client = require('../.').Client;

var start;
Test.finishCallback = function (finish) {
console.log('Took ' + (finish - start) / 1000 + ' seconds for ' + REQ_COUNT + ' requests');
console.log('Ops/s: ' + REQ_COUNT / ((finish - start) / 1000));
Test.map.destroy().then(function () {
hazelcastClient.shutdown();
});
};
start = new Date();
Test.run();
});
Client.newHazelcastClient()
.then((client) => client.getMap('default'))
.then((map) => {
const benchmark = new Benchmark(map);
return benchmark.run()
.then(() => map.destroy())
.then(() => map.client.shutdown());
})
.then(() => console.log('Benchmark finished'));
58 changes: 0 additions & 58 deletions benchmark/SimpleMapParallelBenchmark.js

This file was deleted.

63 changes: 0 additions & 63 deletions benchmark/SimpleMapPipeliningBenchmark.js

This file was deleted.

40 changes: 0 additions & 40 deletions benchmark/SimpliestMapBenchmark.js

This file was deleted.

46 changes: 0 additions & 46 deletions benchmark/SimpliestMapPipeliningBenchmark.js

This file was deleted.

0 comments on commit de88269

Please sign in to comment.