I’m running a spark application with YARN-client or YARN-cluster mode.
But it seems to take too long to startup.
It takes 10+ seconds to initialize the spark con
This is pretty typical. My system takes about 20 seconds from running spark-submit until getting a SparkContext.
As it says in the docs in a couple of places, the solution is to turn your driver into an RPC server. That way you initialize once, and then other applications can use the driver's context as a service.
I am in the middle of doing this with my application. I am using http4s and turning my driver into a web server.