【问题标题】:Using Spark (MLlib) with Spray: how to integrate both?将 Spark (MLlib) 与 Spray 一起使用:如何将两者集成?
【发布时间】:2014-10-11 20:31:49
【问题描述】:

我的意图是使用 Akka 创建一个应用程序。当我意识到我需要创建一些 Web 服务时,我决定使用 Spray。

这个 App 需要一个分类器,所以我在 Spark 上使用 MLlib 构建了一个原型。现在我需要了解如何将 Spark 与 Spray 集成。具体来说,我需要得到
1. 这是创建 Spark 上下文的最佳方法
2. 如何让 Spark 上下文对 Actor 可见

我假设我必须在引导应用程序时创建 Spark 上下文,所以我根据 GitHub 上的示例修改了这段代码,该示例用于没有 Spark 集成的 Spray 应用程序。结果在实例化 Actor 时出现错误

14/10/11 22:12:32 ERROR actor.OneForOneStrategy: exception during creation
akka.actor.ActorInitializationException: exception during creation

我对原始代码的更改是标记为//$$$ $$$的那些

trait Core {

  protected implicit def system: ActorSystem
  // $$$ SparkContext in the trait $$$
  protected implicit def sc: SparkContext

}

/**
 * This trait implements ``Core`` by starting the required 
 * ``ActorSystem`` and registering the
 * termination handler to stop the system when the JVM exits.
 */
trait BootedCore extends Core with Api {
  def system: ActorSystem = ActorSystem("activator-akka-spray")
  def actorRefFactory: ActorRefFactory = system
  // $$$ Initializing SparkContext $$$
  def sc = new SparkContext("local[2]", "naivebayes")  

  val rootService = system.actorOf(Props(new RoutedHttpService(routes)))

  IO(Http)(system) ! Http.Bind(rootService, "0.0.0.0", port = 9010)

  /**
   * Construct the ActorSystem we will use in our application
   */
  //protected implicit  val system : ActorSystem

  /**
   * Ensure that the constructed ActorSystem is shut 
   * down when the JVM shuts down
   */
  sys.addShutdownHook(system.shutdown())

}

/**
 * This trait contains the actors that make up our application;
 * it can be mixed in with
 * ``BootedCore`` for running code or ``TestKit`` 
 * for unit and integration tests.
 */
trait CoreActors {
  this: Core =>
                           //$$$ passing the context to the actor $$$
  val classifier = system.actorOf(Props(classOf[ClassifierActor], sc)) 

}

【问题讨论】:

    标签: apache-spark spray


    【解决方案1】:

    我刚刚发现错误是由于 Spark 和 Spray 使用的 Akka 版本不同造成的。

    == 更新 ==
    如果我没记错的话,问题是通过从 build.sbt 中的项目依赖项中删除 Akka 来解决的,这样我就可以使用 Spark 所依赖的特定 Akka 版本。 我只是让 Spark 为我选择要使用的 Akka 版本。 然后我搜索了一个喷雾版本,它依赖于 Spark 所依赖的同一个 Akka 版本。

    Spark 1.1.0
    喷雾1.2.2

    我从未更新到较早的版本,因此如果您想保持最新状态,我不能说两者的哪个版本可以组合在一起。

    【讨论】:

    • 能否请您展示您是如何解决这个问题的(git repo 会很棒,但即使是版本也会有所帮助)——我遇到了同样的问题。我正在尝试使用 val akkaVersion = "2.3.9" val sprayVersion = "1.2-20130727" val sparkVersion = "1.2.1" 但在包含火花罐后,我遇到了 java.lang.NoSuchMethodError: akka.actor.Props 之类的错误$.apply(Lscala/Function0;)Lakka/actor/Props;
    • 你有上面的 git repo 吗?我正在做类似的事情 - 将喷雾与 Spark 集成,我不知道该怎么做。谢谢
    猜你喜欢
    • 2015-12-18
    • 2016-12-13
    • 1970-01-01
    • 2015-06-05
    • 2017-11-18
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    相关资源
    最近更新 更多