1

这可能是一个非常特殊的情况,但在我头疼了一段时间后,我想从 Stackoverflow 社区获得帮助。

我正在为大型数据集(来自大型系统的一天的数据)构建倒排索引。倒排索引的构建在 Hadoop 上作为 map reduce 作业执行。倒排索引是在 scala 的帮助下构建的。倒排索引的结构如下:{key:"New", ProductID:[1,2,3,4,5,...]}这些被写入 avro 文件。

在此过程中,我遇到了 Java 堆大小问题。我认为原因是我上面显示的“新”之类的术语包含大量产品 ID。我有一个粗略的想法,问题可能发生在我的 Scala 代码中:

  def toIndexedRecord(ids: List[Long], token: String): IndexRecord = {
    val javaList = ids.map(l => l: java.lang.Long).asJava //need to convert from scala long to java long
    new IndexRecord(token, javaList)
  }

这就是我使用这种方法的方式(它在许多地方使用,但使用相同的代码结构和登录名)

  val titles = textPipeDump.map(vf => (vf.itemId, normalizer.customNormalizer(vf.title + " " + vf.subTitle).trim))
    .flatMap {
    case (id, title) =>
      val ss = title.split("\\s+")
      ss.map(word => (word, List(id)))
  }
    .filter(f => f._2.nonEmpty)
    .group
    .sum
    .map {
    case (token, ids) =>
      toIndexedRecord(ids, token)
  } 

textPipeDump正在烫伤MultipleTextLine字段对象

case class MultipleTextLineFiles(p : String*) extends FixedPathSource(p:_*) with TextLineScheme

我有一个案例类来拆分并从该文本行中获取我想要的字段,这就是对象ss

这是我的堆栈跟踪:

Exception in thread "IPC Client (47) connection to /127.0.0.1:55977 from job_201306241658_232590" java.lang.OutOfMemoryError: Java heap space
    at org.apache.hadoop.io.IOUtils.closeStream(IOUtils.java:226)
    at org.apache.hadoop.ipc.Client$Connection.close(Client.java:903)
    at org.apache.hadoop.ipc.Client$Connection.run(Client.java:800)
28079664 [main] ERROR cascading.flow.stream.TrapHandler - caught Throwable, no trap available, rethrowing
cascading.pipe.OperatorException: [WritableSequenceFile(h...][com.twitter.scalding.GroupBuilder$$anonfun$1.apply(GroupBuilder.scala:189)] operator Every failed executing operation: MRMAggregator[decl:'value']
    at cascading.flow.stream.AggregatorEveryStage.receive(AggregatorEveryStage.java:136)
    at cascading.flow.stream.AggregatorEveryStage.receive(AggregatorEveryStage.java:39)
    at cascading.flow.stream.OpenReducingDuct.receive(OpenReducingDuct.java:49)
    at cascading.flow.stream.OpenReducingDuct.receive(OpenReducingDuct.java:28)
    at cascading.flow.hadoop.stream.HadoopGroupGate.run(HadoopGroupGate.java:90)
    at cascading.flow.hadoop.FlowReducer.reduce(FlowReducer.java:133)
    at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:520)
    at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:421)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1178)
    at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.OutOfMemoryError: Java heap space
    at scala.collection.mutable.ListBuffer.$plus$eq(ListBuffer.scala:168)
    at scala.collection.mutable.ListBuffer.$plus$eq(ListBuffer.scala:45)
    at scala.collection.generic.Growable$$anonfun$$plus$plus$eq$1.apply(Growable.scala:48)
    at scala.collection.generic.Growable$$anonfun$$plus$plus$eq$1.apply(Growable.scala:48)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
    at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:176)
    at scala.collection.immutable.List.$colon$colon$colon(List.scala:127)
    at scala.collection.immutable.List.$plus$plus(List.scala:193)
    at com.twitter.algebird.ListMonoid.plus(Monoid.scala:86)
    at com.twitter.algebird.ListMonoid.plus(Monoid.scala:84)
    at com.twitter.scalding.KeyedList$$anonfun$sum$1.apply(TypedPipe.scala:264)
    at com.twitter.scalding.MRMAggregator.aggregate(Operations.scala:279)
    at cascading.flow.stream.AggregatorEveryStage.receive(AggregatorEveryStage.java:128)
    ... 12 more

当我为小数据集执行 map reduce 作业时,我没有收到错误。这意味着随着数据的增加,我为 New 或 old 等词索引的项目/product_id 的数量会变大,这会导致堆大小溢出。

所以,问题是如何避免java堆大小溢出并完成这项任务。

4

0 回答 0