Skip to content

Commit c28f2fc

Browse files
[LIVY-1009] Add support for global TTL for sessions
## What changes were proposed in this pull request? Added two new Livy configuration parameters as below: ``` Enabled to check whether TTL Livy sessions should be stopped. livy.server.session.ttl-check = false Time in milliseconds on how long Livy will wait before TTL is an inactive session. Note that the inactive session could be busy running jobs. livy.server.session.ttl = 8h ``` ## How was this patch tested? Read LIVY-1009 for details.
1 parent adb1084 commit c28f2fc

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

conf/livy.conf.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@
6767
# How long a finished session state should be kept in LivyServer for query.
6868
# livy.server.session.state-retain.sec = 600s
6969

70+
# Enabled to check whether TTL Livy sessions should be stopped.
71+
# livy.server.session.ttl-check = false
72+
73+
# Time in milliseconds on how long Livy will wait before TTL is an inactive session.
74+
# Note that the inactive session could be busy running jobs.
75+
# livy.server.session.ttl = 8h
76+
7077
# If livy should impersonate the requesting users when creating a new session.
7178
# livy.impersonation.enabled = false
7279

server/src/main/scala/org/apache/livy/LivyConf.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ object LivyConf {
354354
// Max creating session in livyServer
355355
val SESSION_MAX_CREATION = Entry("livy.server.session.max-creation", 100)
356356

357+
// Enabled to check whether TTL Livy sessions should be stopped.
358+
val SESSION_TTL_CHECK = Entry("livy.server.session.ttl-check", false)
359+
360+
// Time in milliseconds on how long Livy will wait before TTL is an inactive session.
361+
// Note that the inactive session could be busy running jobs.
362+
val SESSION_TTL = Entry("livy.server.session.ttl", "8h")
363+
357364
val SESSION_ALLOW_CUSTOM_CLASSPATH = Entry("livy.server.session.allow-custom-classpath", false)
358365

359366
val SPARK_MASTER = "spark.master"

server/src/main/scala/org/apache/livy/sessions/SessionManager.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
8383

8484
private[this] final val sessionTimeout = livyConf.getTimeAsMs(LivyConf.SESSION_TIMEOUT)
8585

86+
private[this] final val sessionTtlCheck = livyConf.getBoolean(LivyConf.SESSION_TTL_CHECK)
87+
88+
private[this] final val sessionTtl = livyConf.getTimeAsMs(LivyConf.SESSION_TTL)
89+
8690
private[this] final val sessionStateRetainedInSec =
8791
TimeUnit.MILLISECONDS.toNanos(livyConf.getTimeAsMs(LivyConf.SESSION_STATE_RETAIN_TIME))
8892

@@ -178,9 +182,13 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
178182
if (currentTime - session.lastActivity > calculatedTimeout) {
179183
return true
180184
}
181-
if (session.ttl.isDefined && session.startedOn.isDefined) {
182-
calculatedTimeout = TimeUnit.MILLISECONDS.toNanos(
183-
ClientConf.getTimeAsMs(session.ttl.get))
185+
if (sessionTtlCheck && session.startedOn.isDefined) {
186+
if (session.ttl.isDefined) {
187+
calculatedTimeout = TimeUnit.MILLISECONDS.toNanos(
188+
ClientConf.getTimeAsMs(session.ttl.get))
189+
} else {
190+
calculatedTimeout = TimeUnit.MILLISECONDS.toNanos(sessionTtl)
191+
}
184192
if (currentTime - session.startedOn.get > calculatedTimeout) {
185193
return true
186194
}

0 commit comments

Comments
 (0)