hbase phoenix批量插入非常慢

e0bqpujr  于 2021-06-09  发布在  Hbase
关注(0)|答案(2)|浏览(717)

我做了一个小测试,比较了phoenix批插入和使用hbase的多个put。Phoenix城的速度比直投慢得多(6.157秒,而10000个记录的速度是0.083秒)。
这是我的密码:

SingleConnectionDataSource dataSource = new SingleConnectionDataSource();
    final JdbcTemplate template = new JdbcTemplate();
    template.setDataSource(dataSource);
    dataSource.setUrl(PhoenixZK);
    dataSource.setDriverClassName("org.apache.phoenix.jdbc.PhoenixDriver");

    final PlatformTransactionManager txnManager = new DataSourceTransactionManager(dataSource);
    TransactionTemplate txnTemplate = new TransactionTemplate(txnManager);
    txnTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            template.execute("DROP TABLE IF EXISTS stats.prod_metrics");
            template.execute("CREATE TABLE stats.prod_metrics ( host char(50) not null, created_date TIMESTAMP not null,\n" +
                    "    txn_count bigint CONSTRAINT pk PRIMARY KEY (host, created_date) ) SALT_BUCKETS=36, COMPRESSION='SNAPPY', REPLICATION_SCOPE=1");
        }
    });

    long startTime = System.currentTimeMillis();
    final Random random = new Random();
    txnTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            template.batchUpdate("UPSERT INTO stats.prod_metrics VALUES (?,?,?)", new BatchPreparedStatementSetter(){

                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {

                    ps.setString(1, "localhost-" + random.nextInt());
                    ps.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
                    ps.setInt(3, random.nextInt());
                }

                @Override
                public int getBatchSize() {
                    return numRec;
                }
            });
        }
    });

    System.out.println("elapse = " + (double)(System.currentTimeMillis() - startTime)/1000.0);

以下是pheonix的日志:

16:03:42.544  DEBUG  MutationState                   Sending 10000 mutations for STATS.PROD_METRICS with 20000 key values of total size 1950000 bytes
16:03:47.784  DEBUG  MutationState                   Total time for batch call of  10000 mutations into STATS.PROD_METRICS: 5235 ms

为什么Phoenix花了比直接插入更长的时间?我做错什么了?
谢谢,肖恩

lvmkulzt

lvmkulzt1#

任何东西都比纯hbase慢。phoenix是hbase之上的一种层,“针对低延迟应用的hbase上的高性能关系数据库层”。

mxg2im7a

mxg2im7a2#

10000条记录0.083秒
你怎么知道这些数字的?这是每秒10万。只有在10-20个节点运行多个(多线程)客户机的集群上才能获得这种性能。
在我看来,每秒约2k次插入(事务性?)相当正常。这只是一个客户端向一个rs(区域服务器)发送数据。

相关问题