Spark as a Service之JobServer初测

来源:互联网 发布:linux识别不到hba卡 编辑:程序博客网 时间:2024/05/22 10:40

spark-jobserver提供了一个用于提交和管理Apache Spark作业(job)、jar文件和作业上下文(SparkContext)的RESTful接口。该项目位于git(https://github.com/ooyala/spark-jobserver),当前为0.4版本。

特性

“Spark as a Service”: 简单的面向job和context管理的REST接口
通过长期运行的job context支持亚秒级低延时作业(job)
可以通过结束context来停止运行的作业(job)
分割jar上传步骤以提高job的启动
异步和同步的job API,其中同步API对低延时作业非常有效
支持Standalone Spark和Mesos
Job和jar信息通过一个可插拔的DAO接口来持久化
命名RDD以缓存,并可以通过该名称获取RDD。这样可以提高作业间RDD的共享和重用

安装并启动jobServer

jobServer依赖sbt,所以必须先装好sbt。

rpm -ivh https://dl.bintray.com/sbt/rpm/sbt-0.13.6.rpmyum install git# 下面clone这个项目SHELL$ git clone https://github.com/ooyala/spark-jobserver.git# 在项目根目录下,进入sbt  SHELL$ sbt......[info] Set current project to spark-jobserver-master (in build file:/D:/Projects/spark-jobserver-master/)>#在本地启动jobServer(开发者模式)>re-start --- -Xmx4g......#此时会下载spark-core,jetty和liftweb等相关模块。job-server Starting spark.jobserver.JobServer.main()[success] Total time: 545 s, completed 2014-10-21 19:19:48

然后访问http://localhost:8090 可以看到Web UI
job


测试job执行

这里我们直接使用job-server的test包进行测试

SHELL$ sbt job-server-tests/package......[info] Compiling 5 Scala sources to /root/spark-jobserver/job-server-tests/target/classes...[info] Packaging /root/spark-jobserver/job-server-tests/target/job-server-tests-0.4.0.jar ...[info] Done packaging.

编译完成后,将打包的jar文件通过REST接口上传
REST接口的API如下:
GET /jobs 查询所有job
POST /jobs 提交一个新job
GET /jobs/ 查询某一任务的结果和状态
GET /jobs//config

SHELL$ curl --data-binary @job-server-tests/target/job-server-tests-0.4.0.jar localhost:8090/jars/testOK# 查看提交的jarSHELL$ curl localhost:8090/jars/{  "test": "2014-10-22T15:15:04.826+08:00"}# 提交job提交的appNametestclassspark.jobserver.WordCountExampleSHELL$  curl -d "input.string = hello job server" 'localhost:8090/jobs?appName=test&classPath=spark.jobserver.WordCountExample'{  "status": "STARTED",  "result": {    "jobId": "34ce0666-0148-46f7-8bcf-a7a19b5608b2",    "context": "eba36388-spark.jobserver.WordCountExample"  }}# 通过job-id查看结果和配置信息SHELL$ curl localhost:8090/jobs/34ce0666-0148-46f7-8bcf-a7a19b5608b2{  "status": "OK",  "result": {    "job": 1,    "hello": 1,    "server": 1  }SHELL$ curl localhost:8090/jobs/34ce0666-0148-46f7-8bcf-a7a19b5608b2/config{    "input" : {        "string" : "hello job server"}# 提交一个同步的job,当执行命令后,terminal会hang住直到任务执行完毕。SHELL$ curl -d "input.string = hello job server" 'localhost:8090/jobs?appName=test&classPath=spark.jobserver.WordCountExample'&sync=true{  "status": "OK",  "result": {    "job": 1,    "hello": 1,    "server": 1  }

在Web UI上也可以看到Completed Jobs相应的信息。

预先启动Context

和Context相关的API
GET /contexts ​查询所有预先建立好的context
POST /contexts ​建立新的context
DELETE ​/contexts/ ​删除此context,停止运行于此context上的所有job

SHELL$ curl -d "" 'localhost:8090/contexts/test-context?num-cpu-cores=4&mem-per-node=512m'OK# 查看现有的contextcurl localhost:8090/contexts["test-context", "feceedc3-spark.jobserver.WordCountExample"]接下来在这个context上执行jobcurl -d "input.string = a b c a b see" 'localhost:8090/jobs?appName=test&classPath=spark.jobserver.WordCountExample&context=test-context&sync=true'{  "status": "OK",  "result": {    "a": 2,    "b": 2,    "c": 1,    "see": 1  }

配置文件

打开配置文件,可以发现master设置为local[4],可以将其改为我们的集群地址。

vim spark-jobserver/config/local.conf.templatemaster = "local[4]"

此外,关于数据对象的存储方法和路径:

jobdao = spark.jobserver.io.JobFileDAO    filedao {      rootdir = /tmp/spark-job-server/filedao/data    }

默认context设置,该设置可以被
下面再次在sbt中启动REST接口的中的参数覆盖。

# universal context configuration.  These settings can be overridden, see README.md  context-settings {    num-cpu-cores = 2           # Number of cores to allocate.  Required.    memory-per-node = 512m         # Executor memory per node, -Xmx style eg 512m, #1G, etc.    # in case spark distribution should be accessed from HDFS (as opposed to being installed on every mesos slave)    # spark.executor.uri = "hdfs://namenode:8020/apps/spark/spark.tgz"    # uris of jars to be loaded into the classpath for this context    # dependent-jar-uris = ["file:///some/path/present/in/each/mesos/slave/somepackage.jar"]  }

基本的使用到此为止,jobServer的部署和项目使用将之后介绍。顺便期待下一个版本SQL Window的功能。

0 0
原创粉丝点击