1

hbase を使用して、Phoenix の一括挿入と複数の挿入を比較する小さなテストを行いました。そして、フェニックスはストレート プットよりもはるかに遅いです (10,000 レコードで 6.157 秒対 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);

フェニックスからのログは次のとおりです。

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

なぜフェニックスはストレートインサートよりもはるかに時間がかかったのですか? 私は何か悪いことをしていますか?

ありがとう、ショーン

4

2 に答える 2

0

純粋な HBase に比べて何でも遅くなります。Phoenix は、HBase の最上位にある一種のレイヤーであり、「低レイテンシ アプリケーション向けの HBase 上の高性能リレーショナル データベース レイヤー」です。

于 2015-12-23T16:00:50.877 に答える