簡體   English   中英

使用Scala / Phantom-DSL異步讀取大型Cassandra表

[英]Async reading of large Cassandra table using Scala / Phantom-DSL

我在讀取包含> 800k行的表時遇到問題。 我需要從上至下讀取行以進行處理。

我將Scala和Phantom用於此目的。

這是我的桌子的樣子。

CREATE TABLE raw (
    id uuid PRIMARY KEY,
    b1 text,
    b2 timestamp,
    b3 text,
    b4 text,
    b5 text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';

到目前為止,我嘗試使用以下方法讀取表:

def getAllRecords : Future[Seq[row]] = select.fetch

或更花哨的Play枚舉器,並將其與Iteratee結合使用

def getAllRecords : Enumerator = select.fetchEnumrator

這項工作無濟於事,似乎cassandra / driver /我的程序總是嘗試讀取所有記錄,我在這里錯過了什么?

您是否嘗試過在較大的讀取測試中檢查代碼?

class IterateeBigReadPerformanceTest extends BigTest with ScalaFutures {

  it should "read the correct number of records found in the table" in {
    val counter: AtomicLong = new AtomicLong(0)
    val result = TestDatabase.primitivesJoda.select
      .fetchEnumerator run Iteratee.forEach {
      r => counter.incrementAndGet()
    }

    result.successful {
      query => {
        info(s"done, reading: ${counter.get}")
        counter.get() shouldEqual 2000000
      }
    }
  }
}

這不是會預先讀取您的記錄的東西。 實際上,我們已經進行了超過一小時的測試,以確保有足夠的GC暫停時間,沒有GC開銷,磁導/元空間壓力保持在范圍之內,等等。

如果確實發生了任何變化,那只是錯誤,但這應該仍然有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM