Skip to content

How it works

How an interactive Spark session stays warm

A batch job starts a driver and executors every time it runs. A service starts them once, and every request after that goes to the driver that is already up.

For Ilum 6.7.3. To follow along you need a cluster with Ilum installed, kubectl and curl.

38.3 s cold.
2.9 s warm.

the same Spark query, median of five runs each

A new job: 38.3 s, 38.4 s, 39.9 s, 37.9 s, 38.2 s. A running service: 3.2 s, 2.9 s, 3.0 s, 2.8 s, 2.8 s.

The same question, asked two ways.

Card spend of one state over 30 days, computed by Spark on a two-node cluster with 8 vCPU. Once as a new job, once as a call to a service that is already running.

A new jobPOST /api/v1/job/submitspark-submit, a driver pod, two executor pods, the query, shutdown
38.3 s
A running servicePOST /api/v1/group/{id}/job/executeone call to a driver that is already up
3.2 s
Five runs of each
RunA new jobA running service
138.3 s3.2 s
238.4 s2.9 s
339.9 s3.0 s
437.9 s2.8 s
538.2 s2.8 s
Median38.3 s2.9 s

13×faster on the running service

The service pays for its pods once. Its first call, which starts them, took 51.0 s. Every call after that is the short lane.

Step by step

Step 1 of 5. your terminal → ilum-core · ilum-core → Kubernetes API

Create the service

A service is a Spark application that stays up. One request with the code creates it. ilum-core answers with the group id.

The file you upload holds a class with one method, run. It receives the SparkSession of the service and the configuration of the request, and returns a string. That method is all a request will execute later.

shelldocs ↗
curl -X POST 'http://localhost:9888/api/v1/group' \
  --form 'name="MyJobService"' \
  --form 'pyFiles=@"Ilum_interactive_spark_pi.py"' \
  --form 'clusterName="default"' \
  --form 'language="PYTHON"' \
  --form 'scale="1"' \
  --form 'pyRequirements="ilum-job-api"'
{
  "groupId": "20251222-1208-e0z6b"
}

Spark pods after this step

  • service-<groupId>-<hash>-driverPending
  • your terminal ilum-core · HTTP · POST /api/v1/group
  • ilum-core Kubernetes API · create the driver pod
Python
class IlumJob: def run(self, spark: SparkSession, config: dict) -> str
Scala
trait Job: def run(sparkSession: SparkSession, config: Map[String, Any]): Option[String]
pyRequirements
The class imports ilum.api, which comes from the ilum-job-api package. On the default Spark image of this release the import fails without it, so the request asks for the package. ilum-core installs it when the driver starts.
scale
The number of Spark applications the service keeps. Each replica is a driver of its own with its executors.
States of a service
ACTIVE, PAUSED or ARCHIVED. A service is ACTIVE from the moment it is created, before any driver is up.

Step 2 of 5. driver → ilum-core

Spark starts once

Driver and executors come up as they would for any job, and the driver reports READY. It is the only start the service pays.

The launch is the one a batch job gets: ilum-core runs spark-submit and Kubernetes starts the pods. The difference is in the driver. Instead of running a class and exiting, it reports READY, opens a stream to ilum-core and waits.

Spark pods after this step

  • service-<groupId>-<hash>-driverRunning
  • service-<groupId>-<hash>-exec-1Running
  • service-<groupId>-<hash>-exec-2Running
  • driver ilum-core · gRPC · ready
When it can be called
When the service is ACTIVE and its job is READY.
State
READY is reported by the driver itself once its SparkSession is up.

Step 3 of 5. your terminal → ilum-core · ilum-core → driver · …

Execute against the warm driver

The request is pushed over gRPC to the driver that is already running. No JVM starts and no pod is scheduled. The result comes back in the same HTTP response.

ilum-core turns the request into an event and pushes it down the stream the driver opened when it started. The driver creates an instance of your class and calls run with the SparkSession that already exists. The string it returns travels back in a second call and becomes the body of the HTTP response.

A driver runs one request at a time. With a scale above one, a request goes to one of the replicas at random.

shelldocs ↗
curl -X POST \
  "http://localhost:9888/api/v1/group/{groupId}/job/execute" \
  -H "Content-Type: application/json" \
  -d '{
  "type": "interactive_job_execute",
  "jobClass": "Ilum_interactive_spark_pi.SparkPiInteractiveExample",
  "jobConfig": { "partitions": "5" }
}'

Spark pods after this step

  • service-<groupId>-<hash>-driverRunning
  • service-<groupId>-<hash>-exec-1Running
  • service-<groupId>-<hash>-exec-2Running
  • your terminal ilum-core · HTTP · POST …/job/execute
  • ilum-core driver · gRPC · execute
  • exec-2 ilum-minio · S3 · s3a:// read
Waits for the result
POST /api/v1/group/{groupId}/job/execute answers when the run is complete.
Does not wait
POST /api/v1/group/{groupId}/job/submit returns at once. Ask for the result later.
One at a time
Requests to one driver are executed on a single thread.
Which replica
One of the subscribed drivers of the service, picked at random.

Step 4 of 5. your terminal → ilum-core · ilum-core → driver

Call it again

Same endpoint, same pods. Every further request skips the start entirely, which is why a notebook cell or an API call answers at once.

Notebooks ride on the same mechanism. ilum-core serves the Livy API itself, Jupyter’s sparkmagic is pointed at http://ilum-core:9888, and a Livy session shows up in the console as a service.

shelldocs ↗
curl -X POST \
  "http://localhost:9888/api/v1/group/{groupId}/job/execute" \
  -H "Content-Type: application/json" \
  -d '{
  "type": "interactive_job_execute",
  "jobClass": "Ilum_interactive_spark_pi.SparkPiInteractiveExample",
  "jobConfig": { "partitions": "5" }
}'

Spark pods after this step

  • service-<groupId>-<hash>-driverRunning
  • service-<groupId>-<hash>-exec-1Running
  • service-<groupId>-<hash>-exec-2Running
  • your terminal ilum-core · HTTP · POST …/job/execute
  • ilum-core driver · gRPC · execute
Livy
Served by ilum-core. There is no separate Livy server to run.
In the console
A Livy session created in Jupyter appears as a code service among your workloads.

Step 5 of 5. on the cluster

Idle services scale to zero

A service created with auto-pause is paused after 3600 s without a request: its driver stops and the pods go away. The next request resumes it, and that one call pays the start again.

Pausing is a message, not a pod delete: every driver of the service is told to stop its SparkSession and exits. ilum-core checks for idle services every 180 seconds. An execute request to a paused service resumes it first.

Spark pods after this step

  • service-<groupId>-<hash>-driverremoved
  • service-<groupId>-<hash>-exec-1removed
  • service-<groupId>-<hash>-exec-2removed
Per service
Only services created with autoPause set are paused. The flag is off unless you set it.
Settings
job.autoPause.idleTime (3600 seconds) and job.autoPause.period (180 seconds) in the chart.
Resume
Any execute request resumes the service before it is sent on.
By hand
Change the number of replicas with /api/v1/group/{groupId}/rescale/{scale}.
your Kubernetes cluster · namespace default
Spark pods of this service
your terminalhelm, kubectl, curl
Kubernetes APICreates and watches pods
ilum-coreJobs, sessions, SQL, REST API9888 HTTP · 9999 gRPC
ilum-minioObject storage (S3 API)9000 S3
driverSpark driver of the servicePendingRunningCompleted
exec-1Spark executorPendingRunningCompleted
exec-2Spark executorPendingRunningCompleted
HTTPPOST /api/v1/groupK8s APIcreate the driver podgRPCreadyHTTPPOST …/job/executegRPCexecuteS3s3a:// readHTTPPOST …/job/executegRPCexecuteA warm session: a diagram of the cluster in 5 steps.

Watch it answer

On a two-node cluster with 8 vCPU the service was READY 34 s after it was created. The first call took 3.6 s and the next one 2.1 s.

shell2.1 s

$ curl -X POST 'http://localhost:9888/api/v1/group' --form 'name="MyJobService"' …

Why the second request is fast

Nothing is cached and nothing is skipped. The work that makes a Spark job slow to start has simply been done already.

No scheduling
The driver and executor pods exist. Kubernetes has nothing to place or pull.
No JVM start
Your class is instantiated inside the running driver and handed its SparkSession.
No polling
The request reaches the driver over a stream that is already open, and the result returns in the same HTTP call.

Run it on your own cluster

Every step runs on any Kubernetes cluster after two commands, on the free Community license.

shelldocs ↗
helm repo add ilum https://charts.ilum.cloud
helm install ilum ilum/ilum
NextHow a Spark job runs on Kubernetes with IlumThe same cluster running one batch job: from the request to a finished driver pod, with the logs and the lineage it leaves behind.