-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also added a readme for the benchmark
- Loading branch information
Showing
2 changed files
with
82 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |