Apache Hbase提取随机行非常慢

时间:2019-06-28 16:26:22

标签: database performance hbase query-performance

我正在AWS EMR上运行Apache Hbase。我有一个具有32个核心和244 GB内存的主实例,以及3个具有16个核心和122 GB内存的从属实例。我存储的是15,000行和50,000列的大型整数矩阵。行数将很快达到200万。

我的用例是能够在1秒内随机选择500行和30列。由于Hbase在“数以百万计的列”中被广告宣传为绩效 “数十亿行”,我认为这将是一个很好的用例。

我的行和列没有访问模式,可以随时访问任何500行和任何30列,每个查询都需要在不到一秒钟的时间内返回。现在,我的查询将在5秒钟左右返回,这太慢了。

我启用了BLOOM_FILTER = ROWCOL,并且还将块大小减小到8KB,这使我的性能有了些微提升,但幅度却很小。

我创建表的代码在这里:

import happybase
import pandas as pd

print('reading csv...')
df = pd.read_csv('exon.csv')
print('connecting to hbase...')
connection = happybase.Connection(host='localhost', port=9090)

familes = {
    's': dict(in_memory=True)
}

print('deleting table...')
connection.delete_table('exon', disable=True)
print('creating table...')
connection.create_table('exon', familes)

table = connection.table('exon')

col = list(df)
col = col[1:]

with table.batch(batch_size=100) as b:
    for index, row in df.iterrows():
        to_put = {}
        for col_name in col:
            to_put[('s:'+ col_name).encode('utf-8')] = str(row[col_name]).encode('utf-8')
        print('putting: ' + str(row[0]))
        b.put(row[0].encode('utf-8'), to_put)

我的代码是在这里获取具有500个随机行和30个随机列的数据的:

import happybase
import time
import random
import pandas as pd

print('reading csv...')
col_df = pd.read_csv('exon.csv', nrows=1)
row_df = pd.read_csv('exon.csv', nrows=1500, usecols=[0])
print('connecting to hbase...')
connection = happybase.Connection(host='localhost', port=9090)

rows = row_df.iloc[:,0].tolist()
rows_to_get = [i.encode('utf-8') for i in random.sample(rows, 500)]

table = connection.table('exon')

col = list(col_df)
col = col[1:]

cols_to_get = ['s:{0}'.format(i).encode('utf-8') for i in random.sample(col, 30)]

start = time.time()
row = table.rows(rows_to_get, columns=cols_to_get)
elapsed = time.time() - start
print(row)
print('Elapsed: ' + str(elapsed))

我想知道这是否可能是AWS设置卷方式的磁盘空间问题:

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        121G   88K  121G   1% /dev
tmpfs           121G     0  121G   0% /dev/shm
/dev/xvda1      9.8G  7.3G  2.4G  76% /
/dev/xvdb1      5.0G   68M  5.0G   2% /emr
/dev/xvdb2      123G  1.2G  122G   1% /mnt
/dev/xvdc       128G  168M  128G   1% /mnt1
/dev/xvdd       128G  168M  128G   1% /mnt2
/dev/xvde       128G  168M  128G   1% /mnt3

我的行键是长字符串,看起来像这样:'F1S4_160721_097_D01'。 我的列名称是不超过9位的整数。

我所有的列都在一个列族下。

缩短行键名称可能会加速数据访问吗?

0 个答案:

没有答案