Clojure错误 - 超出GC开销限制

时间:2013-10-01 15:53:58

标签: clojure garbage-collection large-files fasta

我正在尝试随机抽样大型FASTQ文件并将其写入标准输出。我不断收到“超出GC开销限制”的错误,我不确定我做错了什么。我试过在leiningen增加Xmx,但这没有用。这是我的代码:

(ns fastq-sample.core
  (:gen-class)
  (:use clojure.java.io))

(def n-read-pair-lines 8)

(defn sample? [sample-rate]
  (> sample-rate (rand)))

;
; Agent for writing the reads asynchronously
;

(def wtr (agent (writer *out*)))

(defn write-out [r]
  (letfn [(write [out msg] (.write out msg) out)]
    (send wtr write r)))

(defn write-close []
  (send wtr #(.close %))
  (await wtr))

;
; Main
;

(defn reads [file]
  (->>
    (input-stream file)
    (java.util.zip.GZIPInputStream.)
    (reader)
    (line-seq)))

(defn -main [fastq-file sample-rate-str]
  (let [sample-rate (Float. sample-rate-str)
        in-reads    (partition n-read-pair-lines (reads fastq-file))]
    (doseq [x (filter (fn [_] (sample? sample-rate)) in-reads)]
      (write-out (clojure.string/join "\n" x)))
    (write-close)
    (shutdown-agents)))

1 个答案:

答案 0 :(得分:1)

当我尝试将无限序列合并到像地图或矢量这样的simgle数据结构时,这是我经常遇到的相同症状。它通常意味着内存紧张,垃圾收集器无法跟上对新对象的需求。 很可能wtr代理对于内存来说太大了。也许您可能不希望通过更改

将打印结果存储在原子中
(write [out msg] (.write out msg) out)

(write [out msg] (.write out msg))