■概要
hbaseインストールしたときのメモ
■インストール
brew install hbase
# Homebrewで楽しちゃいました
vi /usr/local/Cellar/hbase/0.92.0/libexec/conf/hbase-site.xml
hbase.rootdir
file:///usr/local/Cellar/hbase/databases/hbase-${user.name}/hbase
The directory shared by region servers and into
which HBase persists. The URL should be 'fully-qualified'
to include the filesystem scheme. For example, to specify the
HDFS directory '/hbase' where the HDFS instance's namenode is
running at namenode.example.org on port 9000, set this value to:
hdfs://namenode.example.org:9000/hbase. By default HBase writes
into /tmp. Change this configuration else all data will be lost
on machine restart.
# 起動
start-hbase.sh
# 停止
# stop-hbase.sh
# Rest I/F起動
hbase rest start
# ブラウザ確認
http://localhost:8080/
# → テーブルがないので白画面
# rubyでテーブル作成
gem install json
gem install hbase-stargate
require 'rubygems'
require 'stargate'
client = Stargate::Client.new("http://localhost:8080")
p client.list_tables
client.create_table('cats', 'profile', 'status')
p client.list_tables
# → create文なので、2回目からはコメントアウトすること
■パフォーマンスどれくらいか見てみよう
#!/usr/bin/ruby
# -*- encoding: utf-8 -*-
require 'rubygems'
require 'stargate'
require 'benchmark'
# 接続
client = Stargate::Client.new("http://localhost:8080")
# ---------------------------------------
# Insert / Select 性能
# ---------------------------------------
count = 100000
p 'count:' + count.to_s
# ---------------------------------------
# hbase
Benchmark.bm { |rep|
rep.report("hbase insert ") {
for num in 1..count
name = 'name' + num.to_s
# 登録
client.create_row('cats', num.to_s, Time.now.to_i,
[{:name => 'profile:name', :value => name}])
end
}
}
Benchmark.bm { |rep|
rep.report("hbase select") {
for num in 1..count
id = rand(count).to_i + 1
row = client.show_row('cats', id.to_s)
end
}
}
■結果
"count:100000"
user system total real
hbase insert 45.120000 5.880000 51.000000 (223.785493)
user system total real
hbase select 51.610000 6.440000 58.050000 (273.129300)
# 前提として、1台のmacで行っているため、スケールアウトのメリットを享受できていません。
# そのため、Cassandra やhbaseでは期待する効果が出ていません!!
■参考サイト
Getting Hbase and Thrift Running on a Mac
hbase-stargateを使ってHBaseのCRUD