search
HomeDatabaseMysql TutorialSpark as a Service之JobServer初测

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

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.rpm
yum 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/<jobid></jobid> 查询某一任务的结果和状态
GET /jobs/<jobid>/config</jobid>

SHELL$ curl --data-binary @job-server-tests/target/job-server-tests-0.4.0.jar localhost:8090/jars/test
OK
# 查看提交的jar
SHELL$ curl localhost:8090/jars/
{
  "test": "2014-10-22T15:15:04.826+08:00"
}
# 提交job
提交的appName为test,class为spark.jobserver.WordCountExample
SHELL$  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/<name></name> ?删除此context,停止运行于此context上的所有job

SHELL$ curl -d "" 'localhost:8090/contexts/test-context?num-cpu-cores=4&mem-per-node=512m'
OK
# 查看现有的context
curl localhost:8090/contexts
["test-context", "feceedc3-spark.jobserver.WordCountExample"]
接下来在这个context上执行job
curl -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.template
master = "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的功能。

^^

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),