People at work query our Hadoop cluster with SQL from a lot of places: Superset and Looker, DataGrip, beeline on a shared host, and scripts. For Spark SQL, all of those went through the Spark Thrift Server. This summer we started replacing it with Apache Kyuubi. This post is about why, and what changed for the people using it.
The problem with one shared Spark application
The Spark Thrift Server is a single long-running Spark application that accepts JDBC connections and runs everyone’s queries inside it. That’s simple to run, and it works until several people use it at once:
- Everyone shares one set of resources. One expensive query slows down or starves every other user, and a query that takes down the driver takes down everyone’s session with it.
- Everyone is the same user. Queries run as the service account that started the server, not as the person who sent them. HDFS permissions can’t tell people apart, so we couldn’t let anyone write to the databases they own through it.
- It wasn’t stable. And when the one shared application had problems, everyone’s queries did.
What Kyuubi does differently
Kyuubi speaks the same protocol as the Thrift Server, so every client that worked before still connects. The difference is behind it. Kyuubi doesn’t run queries itself: it authenticates the connection, then routes it to a Spark application, which it calls an engine, launched for that user and running as that user. In our setup there’s one engine per user:
- Queries run as you. The engine runs under your own username, so HDFS and table permissions apply to you. You can write to the databases you have write access to, and nothing else.
- Your queries use your resources. A heavy query fills your own engine, not everyone’s.
- Your session follows you across tools. Connections from the same user share the same engine, so a temporary table or function you create from
beelineis there when you run a query in Superset. - Engines outlive connections. An engine stays up for 30 minutes after its last connection closes, so a dropped connection, a laptop going to sleep or a restart of Kyuubi itself doesn’t throw away the Spark application doing your work.
The cost is a cold start. The first connection after your engine has shut down waits a minute or two while Kyuubi starts a new Spark application on the cluster. After that, queries start immediately.
How people connect
- JDBC over HTTPS for anything outside the cluster, authenticated with the same company credentials people use everywhere else. Superset, DataGrip and
beelineconnect this way. - JDBC over the binary Thrift protocol from inside the cluster, which is what Python clients like PyHive expect.
- A REST API for submitting Spark batch jobs, similar to Apache Livy.
What’s next
Once Kyuubi has proven itself, the Spark Thrift Server goes away. After that it’s a candidate to replace two more services: HiveServer2, since most of our querying has already moved to Spark and Trino, and Livy, since Kyuubi’s REST API does the same job for batch submissions. Fewer ways into the cluster means fewer places to get authentication and resource limits right.
Addendum: HiveServer2 was retired at the end of 2023, keeping only the Hive metastore as the catalog for Spark and Trino. Running every user’s Spark jobs through one gateway also raised its own security questions, which I wrote about in Locking down local files in Apache Kyuubi.
Leave a Reply