Last active
October 15, 2017 08:31
-
-
Save wanming/b6c08cf9bc53bf7392b01f91d62a2273 to your computer and use it in GitHub Desktop.
Hbase benchmark
This file contains hidden or 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
const Bluebird = require('bluebird') | |
var hbase = require('hbase-rpc-client') | |
const zookeeperHosts = process.env.NODE_ENV === 'production' | |
? [ | |
'hb-2zep85a9uik6g1lg8-004.hbase.rds.aliyuncs.com:2181', | |
'hb-2zep85a9uik6g1lg8-003.hbase.rds.aliyuncs.com:2181', | |
'hb-2zep85a9uik6g1lg8-002.hbase.rds.aliyuncs.com:2181' | |
] : [ | |
'localhost:2181' | |
] | |
var client = hbase({ | |
zookeeperHosts | |
}) | |
Bluebird.promisifyAll(client) | |
client.on('error', function (err) { | |
console.log('hbase client error', err) | |
}) | |
function put (table, rowKey, columnFamily = 'default', data) { | |
const put = new hbase.Put(rowKey) | |
Object.keys(data).forEach(key => { | |
put.add(columnFamily, key, data[key]) | |
}) | |
return client.putAsync(table, put) | |
} | |
function get (table, rowKey) { | |
const get = new hbase.Get(rowKey) | |
return client.getAsync(table, get) | |
} | |
function destroy (table, rowKey) { | |
const del = new hbase.Delete(rowKey) | |
return client.deleteAsync(table, del) | |
} | |
suite('HBase', () => { | |
bench('get', async next => { | |
const r = await get('file', 'tomwan') | |
next() | |
}) | |
bench('put', async next => { | |
await put('file', 'tomwan', 'content', { | |
aaa: 'aaa' | |
}) | |
next() | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment