Skip to content

Commit 08f9933

Browse files
ecandreevnoorul
authored andcommitted
feat(jobserver): Enable/disable jar caching on upload (spark-jobserver#950)
* feat(jobserver): Enable/disable jar caching on upload Currently as soon as the jar is upload using /binaries endpoint, it is cached on filesystem. On a high usage SJS, disk is important and a trend has been seen where users upload jars but don't start jobs. This change gives the option to admin to cache jars on job start only. The property "spark.jobserver.cache-on-upload" is configurable and can have the value true/false. * Add "cache-on-upload" parameter to application.conf * Remove ";" from application.conf * Add cache-on-upload to test configurations * Add test case Check if jar can be saved and loaded without creating a cache
1 parent 8f81bde commit 08f9933

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

job-server/src/main/resources/application.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ spark {
2828
# test = /path/to/my/test.jar
2929
# }
3030

31+
# Cache binary on upload.
32+
# If set to false, the binary will be cached on job start only.
33+
cache-on-upload = true
34+
3135
filedao {
3236
rootdir = /tmp/spark-jobserver/filedao/data
3337
}

job-server/src/main/scala/spark/jobserver/io/JobSqlDAO.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ class JobSqlDAO(config: Config) extends JobDAO with FileCacher {
137137
binaryType: BinaryType,
138138
uploadTime: DateTime,
139139
binBytes: Array[Byte]) {
140-
// The order is important. Save the jar file first and then log it into database.
141-
cacheBinary(appName, binaryType, uploadTime, binBytes)
140+
val cacheOnUploadEnabled = config.getBoolean("spark.jobserver.cache-on-upload")
141+
if (cacheOnUploadEnabled) {
142+
// The order is important. Save the jar file first and then log it into database.
143+
cacheBinary(appName, binaryType, uploadTime, binBytes)
144+
}
142145

143146
// log it into database
144147
if (Await.result(insertBinaryInfo(

job-server/src/test/resources/local.test.jobsqldao.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
spark.jobserver {
44
jobdao = spark.jobserver.io.JobSqlDAO
55

6+
cache-on-upload = true
7+
68
cassandra {
79
hosts = ["localhost:9142"]
810
chunk-size-in-kb = 8

job-server/src/test/resources/local.test.jobsqldao_dbcp.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
spark.jobserver {
44
jobdao = spark.jobserver.io.JobSqlDAO
55

6+
cache-on-upload = true
7+
68
sqldao {
79
rootdir = /tmp/spark-job-server-test/sqldao/data
810
# https://coderwall.com/p/a2vnxg

job-server/src/test/scala/spark/jobserver/io/JobSqlDAOSpec.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ class JobSqlDAOSpec extends JobSqlDAOSpecBase with TestJarFinder with FunSpecLik
122122
apps(jarInfo.appName) should equal ((BinaryType.Jar, jarInfo.uploadTime))
123123
}
124124

125+
it("should be able to save one jar and get it back without creating a cache") {
126+
val configNoCache = config.withValue("spark.jobserver.cache-on-upload", ConfigValueFactory.fromAnyRef(false))
127+
val daoNoCache = new JobSqlDAO(configNoCache)
128+
// check the pre-condition
129+
jarFile.exists() should equal (false)
130+
131+
// save
132+
daoNoCache.saveBinary(jarInfo.appName, BinaryType.Jar, jarInfo.uploadTime, jarBytes)
133+
134+
// read it back
135+
val apps: Map[String, (BinaryType, DateTime)] =
136+
Await.result(daoNoCache.getApps, timeout).filter(_._2._1 == BinaryType.Jar)
137+
138+
// test
139+
jarFile.exists() should equal (false)
140+
apps.keySet should equal (Set(jarInfo.appName))
141+
apps(jarInfo.appName) should equal ((BinaryType.Jar, jarInfo.uploadTime))
142+
}
143+
125144
it("should be able to retrieve the jar file") {
126145
// check the pre-condition
127146
jarFile.exists() should equal (false)
@@ -376,6 +395,7 @@ class JobSqlDAOSpec extends JobSqlDAOSpecBase with TestJarFinder with FunSpecLik
376395
apps.keys should not contain (jarInfo.appName)
377396
}
378397
}
398+
379399
}
380400

381401
class JobSqlDAODBCPSpec extends JobSqlDAOSpec {

0 commit comments

Comments
 (0)